python_code
stringlengths
0
1.8M
repo_name
stringclasses
7 values
file_path
stringlengths
5
99
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2022 MediaTek Inc. * Author: Garmin Chang <[email protected]> */ #include <dt-bindings/clock/mediatek,mt8188-clk.h> #include <linux/clk-provider.h> #include <linux/platform_device.h> #include "clk-gate.h" #include "clk-mtk.h" static const struct mtk_gate_regs vpp0_0_cg_regs = { .set_ofs = 0x24, .clr_ofs = 0x28, .sta_ofs = 0x20, }; static const struct mtk_gate_regs vpp0_1_cg_regs = { .set_ofs = 0x30, .clr_ofs = 0x34, .sta_ofs = 0x2c, }; static const struct mtk_gate_regs vpp0_2_cg_regs = { .set_ofs = 0x3c, .clr_ofs = 0x40, .sta_ofs = 0x38, }; #define GATE_VPP0_0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &vpp0_0_cg_regs, _shift, &mtk_clk_gate_ops_setclr) #define GATE_VPP0_1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &vpp0_1_cg_regs, _shift, &mtk_clk_gate_ops_setclr) #define GATE_VPP0_2(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &vpp0_2_cg_regs, _shift, &mtk_clk_gate_ops_setclr) static const struct mtk_gate vpp0_clks[] = { /* VPP0_0 */ GATE_VPP0_0(CLK_VPP0_MDP_FG, "vpp0_mdp_fg", "top_vpp", 1), GATE_VPP0_0(CLK_VPP0_STITCH, "vpp0_stitch", "top_vpp", 2), GATE_VPP0_0(CLK_VPP0_PADDING, "vpp0_padding", "top_vpp", 7), GATE_VPP0_0(CLK_VPP0_MDP_TCC, "vpp0_mdp_tcc", "top_vpp", 8), GATE_VPP0_0(CLK_VPP0_WARP0_ASYNC_TX, "vpp0_warp0_async_tx", "top_vpp", 10), GATE_VPP0_0(CLK_VPP0_WARP1_ASYNC_TX, "vpp0_warp1_async_tx", "top_vpp", 11), GATE_VPP0_0(CLK_VPP0_MUTEX, "vpp0_mutex", "top_vpp", 13), GATE_VPP0_0(CLK_VPP02VPP1_RELAY, "vpp02vpp1_relay", "top_vpp", 14), GATE_VPP0_0(CLK_VPP0_VPP12VPP0_ASYNC, "vpp0_vpp12vpp0_async", "top_vpp", 15), GATE_VPP0_0(CLK_VPP0_MMSYSRAM_TOP, "vpp0_mmsysram_top", "top_vpp", 16), GATE_VPP0_0(CLK_VPP0_MDP_AAL, "vpp0_mdp_aal", "top_vpp", 17), GATE_VPP0_0(CLK_VPP0_MDP_RSZ, "vpp0_mdp_rsz", "top_vpp", 18), /* VPP0_1 */ GATE_VPP0_1(CLK_VPP0_SMI_COMMON_MMSRAM, "vpp0_smi_common_mmsram", "top_vpp", 0), GATE_VPP0_1(CLK_VPP0_GALS_VDO0_LARB0_MMSRAM, "vpp0_gals_vdo0_larb0_mmsram", "top_vpp", 1), GATE_VPP0_1(CLK_VPP0_GALS_VDO0_LARB1_MMSRAM, "vpp0_gals_vdo0_larb1_mmsram", "top_vpp", 2), GATE_VPP0_1(CLK_VPP0_GALS_VENCSYS_MMSRAM, "vpp0_gals_vencsys_mmsram", "top_vpp", 3), GATE_VPP0_1(CLK_VPP0_GALS_VENCSYS_CORE1_MMSRAM, "vpp0_gals_vencsys_core1_mmsram", "top_vpp", 4), GATE_VPP0_1(CLK_VPP0_GALS_INFRA_MMSRAM, "vpp0_gals_infra_mmsram", "top_vpp", 5), GATE_VPP0_1(CLK_VPP0_GALS_CAMSYS_MMSRAM, "vpp0_gals_camsys_mmsram", "top_vpp", 6), GATE_VPP0_1(CLK_VPP0_GALS_VPP1_LARB5_MMSRAM, "vpp0_gals_vpp1_larb5_mmsram", "top_vpp", 7), GATE_VPP0_1(CLK_VPP0_GALS_VPP1_LARB6_MMSRAM, "vpp0_gals_vpp1_larb6_mmsram", "top_vpp", 8), GATE_VPP0_1(CLK_VPP0_SMI_REORDER_MMSRAM, "vpp0_smi_reorder_mmsram", "top_vpp", 9), GATE_VPP0_1(CLK_VPP0_SMI_IOMMU, "vpp0_smi_iommu", "top_vpp", 10), GATE_VPP0_1(CLK_VPP0_GALS_IMGSYS_CAMSYS, "vpp0_gals_imgsys_camsys", "top_vpp", 11), GATE_VPP0_1(CLK_VPP0_MDP_RDMA, "vpp0_mdp_rdma", "top_vpp", 12), GATE_VPP0_1(CLK_VPP0_MDP_WROT, "vpp0_mdp_wrot", "top_vpp", 13), GATE_VPP0_1(CLK_VPP0_GALS_EMI0_EMI1, "vpp0_gals_emi0_emi1", "top_vpp", 16), GATE_VPP0_1(CLK_VPP0_SMI_SUB_COMMON_REORDER, "vpp0_smi_sub_common_reorder", "top_vpp", 17), GATE_VPP0_1(CLK_VPP0_SMI_RSI, "vpp0_smi_rsi", "top_vpp", 18), GATE_VPP0_1(CLK_VPP0_SMI_COMMON_LARB4, "vpp0_smi_common_larb4", "top_vpp", 19), GATE_VPP0_1(CLK_VPP0_GALS_VDEC_VDEC_CORE1, "vpp0_gals_vdec_vdec_core1", "top_vpp", 20), GATE_VPP0_1(CLK_VPP0_GALS_VPP1_WPESYS, "vpp0_gals_vpp1_wpesys", "top_vpp", 21), GATE_VPP0_1(CLK_VPP0_GALS_VDO0_VDO1_VENCSYS_CORE1, "vpp0_gals_vdo0_vdo1_vencsys_core1", "top_vpp", 22), GATE_VPP0_1(CLK_VPP0_FAKE_ENG, "vpp0_fake_eng", "top_vpp", 23), GATE_VPP0_1(CLK_VPP0_MDP_HDR, "vpp0_mdp_hdr", "top_vpp", 24), GATE_VPP0_1(CLK_VPP0_MDP_TDSHP, "vpp0_mdp_tdshp", "top_vpp", 25), GATE_VPP0_1(CLK_VPP0_MDP_COLOR, "vpp0_mdp_color", "top_vpp", 26), GATE_VPP0_1(CLK_VPP0_MDP_OVL, "vpp0_mdp_ovl", "top_vpp", 27), GATE_VPP0_1(CLK_VPP0_DSIP_RDMA, "vpp0_dsip_rdma", "top_vpp", 28), GATE_VPP0_1(CLK_VPP0_DISP_WDMA, "vpp0_disp_wdma", "top_vpp", 29), GATE_VPP0_1(CLK_VPP0_MDP_HMS, "vpp0_mdp_hms", "top_vpp", 30), /* VPP0_2 */ GATE_VPP0_2(CLK_VPP0_WARP0_RELAY, "vpp0_warp0_relay", "top_wpe_vpp", 0), GATE_VPP0_2(CLK_VPP0_WARP0_ASYNC, "vpp0_warp0_async", "top_wpe_vpp", 1), GATE_VPP0_2(CLK_VPP0_WARP1_RELAY, "vpp0_warp1_relay", "top_wpe_vpp", 2), GATE_VPP0_2(CLK_VPP0_WARP1_ASYNC, "vpp0_warp1_async", "top_wpe_vpp", 3), }; static const struct mtk_clk_desc vpp0_desc = { .clks = vpp0_clks, .num_clks = ARRAY_SIZE(vpp0_clks), }; static const struct platform_device_id clk_mt8188_vpp0_id_table[] = { { .name = "clk-mt8188-vpp0", .driver_data = (kernel_ulong_t)&vpp0_desc }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, clk_mt8188_vpp0_id_table); static struct platform_driver clk_mt8188_vpp0_drv = { .probe = mtk_clk_pdev_probe, .remove_new = mtk_clk_pdev_remove, .driver = { .name = "clk-mt8188-vpp0", }, .id_table = clk_mt8188_vpp0_id_table, }; module_platform_driver(clk_mt8188_vpp0_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8188-vpp0.c
// SPDX-License-Identifier: GPL-2.0-only // // Copyright (c) 2022 MediaTek Inc. // Author: Chun-Jie Chen <[email protected]> #include <linux/clk-provider.h> #include <linux/platform_device.h> #include <dt-bindings/clock/mt8186-clk.h> #include "clk-gate.h" #include "clk-mtk.h" static const struct mtk_gate_regs mfg_cg_regs = { .set_ofs = 0x4, .clr_ofs = 0x8, .sta_ofs = 0x0, }; #define GATE_MFG(_id, _name, _parent, _shift) \ GATE_MTK_FLAGS(_id, _name, _parent, &mfg_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr, CLK_SET_RATE_PARENT) static const struct mtk_gate mfg_clks[] = { GATE_MFG(CLK_MFG_BG3D, "mfg_bg3d", "top_mfg", 0), }; static const struct mtk_clk_desc mfg_desc = { .clks = mfg_clks, .num_clks = ARRAY_SIZE(mfg_clks), }; static const struct of_device_id of_match_clk_mt8186_mfg[] = { { .compatible = "mediatek,mt8186-mfgsys", .data = &mfg_desc, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8186_mfg); static struct platform_driver clk_mt8186_mfg_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt8186-mfg", .of_match_table = of_match_clk_mt8186_mfg, }, }; module_platform_driver(clk_mt8186_mfg_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8186-mfg.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2021 MediaTek Inc. * Chun-Jie Chen <[email protected]> * Copyright (c) 2023 Collabora Ltd. * AngeloGioacchino Del Regno <[email protected]> */ #include <dt-bindings/clock/mt8192-clk.h> #include <linux/module.h> #include <linux/platform_device.h> #include "clk-fhctl.h" #include "clk-gate.h" #include "clk-mtk.h" #include "clk-pll.h" #include "clk-pllfh.h" static const struct mtk_gate_regs apmixed_cg_regs = { .set_ofs = 0x14, .clr_ofs = 0x14, .sta_ofs = 0x14, }; #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_MIPID26M, "mipid26m", "clk26m", 16), }; #define MT8192_PLL_FMAX (3800UL * MHZ) #define MT8192_PLL_FMIN (1500UL * MHZ) #define MT8192_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 = MT8192_PLL_FMAX, \ .fmin = MT8192_PLL_FMIN, \ .pcwbits = _pcwbits, \ .pcwibits = MT8192_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, \ } #define PLL_B(_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) \ 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, 0, 0, 0) static const struct mtk_pll_data plls[] = { PLL_B(CLK_APMIXED_MAINPLL, "mainpll", 0x0340, 0x034c, 0xff000000, HAVE_RST_BAR, BIT(23), 22, 0x0344, 24, 0, 0, 0, 0x0344, 0), PLL_B(CLK_APMIXED_UNIVPLL, "univpll", 0x0308, 0x0314, 0xff000000, HAVE_RST_BAR, BIT(23), 22, 0x030c, 24, 0, 0, 0, 0x030c, 0), PLL(CLK_APMIXED_USBPLL, "usbpll", 0x03c4, 0x03cc, 0x00000000, 0, 0, 22, 0x03c4, 24, 0, 0, 0, 0x03c4, 0, 0x03c4, 0x03cc, 2), PLL_B(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0350, 0x035c, 0x00000000, 0, 0, 22, 0x0354, 24, 0, 0, 0, 0x0354, 0), PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0360, 0x036c, 0xff000000, HAVE_RST_BAR, BIT(23), 22, 0x0364, 24, 0, 0, 0, 0x0364, 0), PLL_B(CLK_APMIXED_ADSPPLL, "adsppll", 0x0370, 0x037c, 0xff000000, HAVE_RST_BAR, BIT(23), 22, 0x0374, 24, 0, 0, 0, 0x0374, 0), PLL_B(CLK_APMIXED_MFGPLL, "mfgpll", 0x0268, 0x0274, 0x00000000, 0, 0, 22, 0x026c, 24, 0, 0, 0, 0x026c, 0), PLL_B(CLK_APMIXED_TVDPLL, "tvdpll", 0x0380, 0x038c, 0x00000000, 0, 0, 22, 0x0384, 24, 0, 0, 0, 0x0384, 0), PLL_B(CLK_APMIXED_APLL1, "apll1", 0x0318, 0x0328, 0x00000000, 0, 0, 32, 0x031c, 24, 0x0040, 0x000c, 0, 0x0320, 0), PLL_B(CLK_APMIXED_APLL2, "apll2", 0x032c, 0x033c, 0x00000000, 0, 0, 32, 0x0330, 24, 0, 0, 0, 0x0334, 0), }; enum fh_pll_id { FH_ARMPLL_LL, FH_ARMPLL_BL0, FH_ARMPLL_BL1, FH_ARMPLL_BL2, FH_ARMPLL_BL3, FH_CCIPLL, FH_MFGPLL, FH_MEMPLL, FH_MPLL, FH_MMPLL, FH_MAINPLL, FH_MSDCPLL, FH_ADSPPLL, FH_APUPLL, FH_TVDPLL, FH_NR_FH, }; #define FH(_pllid, _fhid, _offset) { \ .data = { \ .pll_id = _pllid, \ .fh_id = _fhid, \ .fh_ver = FHCTL_PLLFH_V2, \ .fhx_offset = _offset, \ .dds_mask = GENMASK(21, 0), \ .slope0_value = 0x6003c97, \ .slope1_value = 0x6003c97, \ .sfstrx_en = BIT(2), \ .frddsx_en = BIT(1), \ .fhctlx_en = BIT(0), \ .tgl_org = BIT(31), \ .dvfs_tri = BIT(31), \ .pcwchg = BIT(31), \ .dt_val = 0x0, \ .df_val = 0x9, \ .updnlmt_shft = 16, \ .msk_frddsx_dys = GENMASK(23, 20), \ .msk_frddsx_dts = GENMASK(19, 16), \ }, \ } static struct mtk_pllfh_data pllfhs[] = { FH(CLK_APMIXED_MFGPLL, FH_MFGPLL, 0xb4), FH(CLK_APMIXED_MMPLL, FH_MMPLL, 0xf0), FH(CLK_APMIXED_MAINPLL, FH_MAINPLL, 0x104), FH(CLK_APMIXED_MSDCPLL, FH_MSDCPLL, 0x118), FH(CLK_APMIXED_ADSPPLL, FH_ADSPPLL, 0x12c), FH(CLK_APMIXED_TVDPLL, FH_TVDPLL, 0x154), }; static const struct of_device_id of_match_clk_mt8192_apmixed[] = { { .compatible = "mediatek,mt8192-apmixedsys" }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8192_apmixed); static int clk_mt8192_apmixed_probe(struct platform_device *pdev) { struct clk_hw_onecell_data *clk_data; struct device_node *node = pdev->dev.of_node; const u8 *fhctl_node = "mediatek,mt8192-fhctl"; int r; clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK); if (!clk_data) return -ENOMEM; fhctl_parse_dt(fhctl_node, pllfhs, ARRAY_SIZE(pllfhs)); r = mtk_clk_register_pllfhs(node, plls, ARRAY_SIZE(plls), pllfhs, ARRAY_SIZE(pllfhs), clk_data); if (r) goto free_clk_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; return r; unregister_gates: mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data); unregister_plls: mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs, ARRAY_SIZE(pllfhs), clk_data); free_clk_data: mtk_free_clk_data(clk_data); return r; } static void clk_mt8192_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_pllfhs(plls, ARRAY_SIZE(plls), pllfhs, ARRAY_SIZE(pllfhs), clk_data); mtk_free_clk_data(clk_data); } static struct platform_driver clk_mt8192_apmixed_drv = { .driver = { .name = "clk-mt8192-apmixed", .of_match_table = of_match_clk_mt8192_apmixed, }, .probe = clk_mt8192_apmixed_probe, .remove_new = clk_mt8192_apmixed_remove, }; module_platform_driver(clk_mt8192_apmixed_drv); MODULE_DESCRIPTION("MediaTek MT8192 apmixed clocks driver"); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8192-apmixedsys.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2022 MediaTek Inc. */ #include <dt-bindings/clock/mediatek,mt8365-clk.h> #include <linux/clk-provider.h> #include <linux/platform_device.h> #include "clk-gate.h" #include "clk-mtk.h" static const struct mtk_gate_regs mfg0_cg_regs = { .set_ofs = 0x4, .clr_ofs = 0x8, .sta_ofs = 0x0, }; static const struct mtk_gate_regs mfg1_cg_regs = { .set_ofs = 0x280, .clr_ofs = 0x280, .sta_ofs = 0x280, }; #define GATE_MFG0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &mfg0_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr) #define GATE_MFG1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &mfg1_cg_regs, _shift, \ &mtk_clk_gate_ops_no_setclr) static const struct mtk_gate mfg_clks[] = { /* MFG0 */ GATE_MFG0(CLK_MFG_BG3D, "mfg_bg3d", "mfg_sel", 0), /* MFG1 */ GATE_MFG1(CLK_MFG_MBIST_DIAG, "mfg_mbist_diag", "mbist_diag_sel", 24), }; static const struct mtk_clk_desc mfg_desc = { .clks = mfg_clks, .num_clks = ARRAY_SIZE(mfg_clks), }; static const struct of_device_id of_match_clk_mt8365_mfg[] = { { .compatible = "mediatek,mt8365-mfgcfg", .data = &mfg_desc, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8365_mfg); static struct platform_driver clk_mt8365_mfg_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt8365-mfg", .of_match_table = of_match_clk_mt8365_mfg, }, }; module_platform_driver(clk_mt8365_mfg_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8365-mfg.c
// SPDX-License-Identifier: GPL-2.0 // // Copyright (c) 2018 MediaTek Inc. // Author: Weiyi Lu <[email protected]> #include <linux/clk-provider.h> #include <linux/platform_device.h> #include "clk-mtk.h" #include "clk-gate.h" #include <dt-bindings/clock/mt8183-clk.h> static const struct mtk_gate_regs vdec0_cg_regs = { .set_ofs = 0x0, .clr_ofs = 0x4, .sta_ofs = 0x0, }; static const struct mtk_gate_regs vdec1_cg_regs = { .set_ofs = 0x8, .clr_ofs = 0xc, .sta_ofs = 0x8, }; #define GATE_VDEC0_I(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &vdec0_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr_inv) #define GATE_VDEC1_I(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &vdec1_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr_inv) static const struct mtk_gate vdec_clks[] = { /* VDEC0 */ GATE_VDEC0_I(CLK_VDEC_VDEC, "vdec_vdec", "mm_sel", 0), /* VDEC1 */ GATE_VDEC1_I(CLK_VDEC_LARB1, "vdec_larb1", "mm_sel", 0), }; static const struct mtk_clk_desc vdec_desc = { .clks = vdec_clks, .num_clks = ARRAY_SIZE(vdec_clks), }; static const struct of_device_id of_match_clk_mt8183_vdec[] = { { .compatible = "mediatek,mt8183-vdecsys", .data = &vdec_desc, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8183_vdec); static struct platform_driver clk_mt8183_vdec_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt8183-vdec", .of_match_table = of_match_clk_mt8183_vdec, }, }; module_platform_driver(clk_mt8183_vdec_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8183-vdec.c
// SPDX-License-Identifier: GPL-2.0-only // // Copyright (c) 2021 MediaTek Inc. // Author: Chun-Jie Chen <[email protected]> #include "clk-fhctl.h" #include "clk-gate.h" #include "clk-mtk.h" #include "clk-pll.h" #include "clk-pllfh.h" #include <dt-bindings/clock/mt8195-clk.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> static const struct mtk_gate_regs apmixed_cg_regs = { .set_ofs = 0x8, .clr_ofs = 0x8, .sta_ofs = 0x8, }; #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, "pll_ssusb26m", "clk26m", 1), }; #define MT8195_PLL_FMAX (3800UL * MHZ) #define MT8195_PLL_FMIN (1500UL * MHZ) #define MT8195_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 = MT8195_PLL_FMAX, \ .fmin = MT8195_PLL_FMIN, \ .pcwbits = _pcwbits, \ .pcwibits = MT8195_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_NNAPLL, "nnapll", 0x0390, 0x03a0, 0, 0, 0, 22, 0x0398, 24, 0, 0, 0, 0x0398, 0, 0x0398, 0, 9), PLL(CLK_APMIXED_RESPLL, "respll", 0x0190, 0x0320, 0, 0, 0, 22, 0x0198, 24, 0, 0, 0, 0x0198, 0, 0x0198, 0, 9), PLL(CLK_APMIXED_ETHPLL, "ethpll", 0x0360, 0x0370, 0, 0, 0, 22, 0x0368, 24, 0, 0, 0, 0x0368, 0, 0x0368, 0, 9), PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0710, 0x0720, 0, 0, 0, 22, 0x0718, 24, 0, 0, 0, 0x0718, 0, 0x0718, 0, 9), PLL(CLK_APMIXED_TVDPLL1, "tvdpll1", 0x00a0, 0x00b0, 0, 0, 0, 22, 0x00a8, 24, 0, 0, 0, 0x00a8, 0, 0x00a8, 0, 9), PLL(CLK_APMIXED_TVDPLL2, "tvdpll2", 0x00c0, 0x00d0, 0, 0, 0, 22, 0x00c8, 24, 0, 0, 0, 0x00c8, 0, 0x00c8, 0, 9), PLL(CLK_APMIXED_MMPLL, "mmpll", 0x00e0, 0x00f0, 0xff000000, HAVE_RST_BAR, BIT(23), 22, 0x00e8, 24, 0, 0, 0, 0x00e8, 0, 0x00e8, 0, 9), PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x01d0, 0x01e0, 0xff000000, HAVE_RST_BAR, BIT(23), 22, 0x01d8, 24, 0, 0, 0, 0x01d8, 0, 0x01d8, 0, 9), PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x0890, 0x08a0, 0, 0, 0, 22, 0x0898, 24, 0, 0, 0, 0x0898, 0, 0x0898, 0, 9), PLL(CLK_APMIXED_IMGPLL, "imgpll", 0x0100, 0x0110, 0, 0, 0, 22, 0x0108, 24, 0, 0, 0, 0x0108, 0, 0x0108, 0, 9), PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x01f0, 0x0700, 0xff000000, HAVE_RST_BAR, BIT(23), 22, 0x01f8, 24, 0, 0, 0, 0x01f8, 0, 0x01f8, 0, 9), PLL(CLK_APMIXED_HDMIPLL1, "hdmipll1", 0x08c0, 0x08d0, 0, 0, 0, 22, 0x08c8, 24, 0, 0, 0, 0x08c8, 0, 0x08c8, 0, 9), PLL(CLK_APMIXED_HDMIPLL2, "hdmipll2", 0x0870, 0x0880, 0, 0, 0, 22, 0x0878, 24, 0, 0, 0, 0x0878, 0, 0x0878, 0, 9), PLL(CLK_APMIXED_HDMIRX_APLL, "hdmirx_apll", 0x08e0, 0x0dd4, 0, 0, 0, 32, 0x08e8, 24, 0, 0, 0, 0x08ec, 0, 0x08e8, 0, 9), PLL(CLK_APMIXED_USB1PLL, "usb1pll", 0x01a0, 0x01b0, 0, 0, 0, 22, 0x01a8, 24, 0, 0, 0, 0x01a8, 0, 0x01a8, 0, 9), PLL(CLK_APMIXED_ADSPPLL, "adsppll", 0x07e0, 0x07f0, 0, 0, 0, 22, 0x07e8, 24, 0, 0, 0, 0x07e8, 0, 0x07e8, 0, 9), PLL(CLK_APMIXED_APLL1, "apll1", 0x07c0, 0x0dc0, 0, 0, 0, 32, 0x07c8, 24, 0x0470, 0x0000, 12, 0x07cc, 0, 0x07c8, 0, 9), PLL(CLK_APMIXED_APLL2, "apll2", 0x0780, 0x0dc4, 0, 0, 0, 32, 0x0788, 24, 0x0474, 0x0000, 13, 0x078c, 0, 0x0788, 0, 9), PLL(CLK_APMIXED_APLL3, "apll3", 0x0760, 0x0dc8, 0, 0, 0, 32, 0x0768, 24, 0x0478, 0x0000, 14, 0x076c, 0, 0x0768, 0, 9), PLL(CLK_APMIXED_APLL4, "apll4", 0x0740, 0x0dcc, 0, 0, 0, 32, 0x0748, 24, 0x047C, 0x0000, 15, 0x074c, 0, 0x0748, 0, 9), PLL(CLK_APMIXED_APLL5, "apll5", 0x07a0, 0x0dd0, 0x100000, 0, 0, 32, 0x07a8, 24, 0x0480, 0x0000, 16, 0x07ac, 0, 0x07a8, 0, 9), PLL(CLK_APMIXED_MFGPLL, "mfgpll", 0x0340, 0x0350, 0, 0, 0, 22, 0x0348, 24, 0, 0, 0, 0x0348, 0, 0x0348, 0, 9), PLL(CLK_APMIXED_DGIPLL, "dgipll", 0x0150, 0x0160, 0, 0, 0, 22, 0x0158, 24, 0, 0, 0, 0x0158, 0, 0x0158, 0, 9), }; enum fh_pll_id { FH_ARMPLL_LL, FH_ARMPLL_BL, FH_MEMPLL, FH_ADSPPLL, FH_NNAPLL, FH_CCIPLL, FH_MFGPLL, FH_TVDPLL2, FH_MPLL, FH_MMPLL, FH_MAINPLL, FH_MSDCPLL, FH_IMGPLL, FH_VDECPLL, FH_TVDPLL1, FH_NR_FH, }; #define FH(_pllid, _fhid, _offset) { \ .data = { \ .pll_id = _pllid, \ .fh_id = _fhid, \ .fh_ver = FHCTL_PLLFH_V2, \ .fhx_offset = _offset, \ .dds_mask = GENMASK(21, 0), \ .slope0_value = 0x6003c97, \ .slope1_value = 0x6003c97, \ .sfstrx_en = BIT(2), \ .frddsx_en = BIT(1), \ .fhctlx_en = BIT(0), \ .tgl_org = BIT(31), \ .dvfs_tri = BIT(31), \ .pcwchg = BIT(31), \ .dt_val = 0x0, \ .df_val = 0x9, \ .updnlmt_shft = 16, \ .msk_frddsx_dys = GENMASK(23, 20), \ .msk_frddsx_dts = GENMASK(19, 16), \ }, \ } static struct mtk_pllfh_data pllfhs[] = { FH(CLK_APMIXED_ADSPPLL, FH_ADSPPLL, 0x78), FH(CLK_APMIXED_NNAPLL, FH_NNAPLL, 0x8c), FH(CLK_APMIXED_MFGPLL, FH_MFGPLL, 0xb4), FH(CLK_APMIXED_TVDPLL2, FH_TVDPLL2, 0xc8), FH(CLK_APMIXED_MMPLL, FH_MMPLL, 0xf0), FH(CLK_APMIXED_MAINPLL, FH_MAINPLL, 0x104), FH(CLK_APMIXED_MSDCPLL, FH_MSDCPLL, 0x118), FH(CLK_APMIXED_IMGPLL, FH_IMGPLL, 0x12c), FH(CLK_APMIXED_VDECPLL, FH_VDECPLL, 0x140), FH(CLK_APMIXED_TVDPLL2, FH_TVDPLL1, 0x154), }; static const struct of_device_id of_match_clk_mt8195_apmixed[] = { { .compatible = "mediatek,mt8195-apmixedsys", }, {} }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8195_apmixed); static int clk_mt8195_apmixed_probe(struct platform_device *pdev) { struct clk_hw_onecell_data *clk_data; struct device_node *node = pdev->dev.of_node; const u8 *fhctl_node = "mediatek,mt8195-fhctl"; int r; clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK); if (!clk_data) return -ENOMEM; fhctl_parse_dt(fhctl_node, pllfhs, ARRAY_SIZE(pllfhs)); r = mtk_clk_register_pllfhs(node, plls, ARRAY_SIZE(plls), pllfhs, ARRAY_SIZE(pllfhs), 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 r; unregister_gates: mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data); unregister_plls: mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs, ARRAY_SIZE(pllfhs), clk_data); free_apmixed_data: mtk_free_clk_data(clk_data); return r; } static void clk_mt8195_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_pllfhs(plls, ARRAY_SIZE(plls), pllfhs, ARRAY_SIZE(pllfhs), clk_data); mtk_free_clk_data(clk_data); } static struct platform_driver clk_mt8195_apmixed_drv = { .probe = clk_mt8195_apmixed_probe, .remove_new = clk_mt8195_apmixed_remove, .driver = { .name = "clk-mt8195-apmixed", .of_match_table = of_match_clk_mt8195_apmixed, }, }; module_platform_driver(clk_mt8195_apmixed_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8195-apmixedsys.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2019 MediaTek Inc. * Author: Wendell Lin <[email protected]> */ #include <linux/module.h> #include <linux/clk-provider.h> #include <linux/platform_device.h> #include <dt-bindings/clock/mt6779-clk.h> #include "clk-mtk.h" #include "clk-gate.h" static const struct mtk_gate_regs mm0_cg_regs = { .set_ofs = 0x0104, .clr_ofs = 0x0108, .sta_ofs = 0x0100, }; static const struct mtk_gate_regs mm1_cg_regs = { .set_ofs = 0x0114, .clr_ofs = 0x0118, .sta_ofs = 0x0110, }; #define GATE_MM0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &mm0_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr) #define GATE_MM1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &mm1_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr) static const struct mtk_gate mm_clks[] = { /* MM0 */ GATE_MM0(CLK_MM_SMI_COMMON, "mm_smi_common", "mm_sel", 0), GATE_MM0(CLK_MM_SMI_LARB0, "mm_smi_larb0", "mm_sel", 1), GATE_MM0(CLK_MM_SMI_LARB1, "mm_smi_larb1", "mm_sel", 2), GATE_MM0(CLK_MM_GALS_COMM0, "mm_gals_comm0", "mm_sel", 3), GATE_MM0(CLK_MM_GALS_COMM1, "mm_gals_comm1", "mm_sel", 4), GATE_MM0(CLK_MM_GALS_CCU2MM, "mm_gals_ccu2mm", "mm_sel", 5), GATE_MM0(CLK_MM_GALS_IPU12MM, "mm_gals_ipu12mm", "mm_sel", 6), GATE_MM0(CLK_MM_GALS_IMG2MM, "mm_gals_img2mm", "mm_sel", 7), GATE_MM0(CLK_MM_GALS_CAM2MM, "mm_gals_cam2mm", "mm_sel", 8), GATE_MM0(CLK_MM_GALS_IPU2MM, "mm_gals_ipu2mm", "mm_sel", 9), GATE_MM0(CLK_MM_MDP_DL_TXCK, "mm_mdp_dl_txck", "mm_sel", 10), GATE_MM0(CLK_MM_IPU_DL_TXCK, "mm_ipu_dl_txck", "mm_sel", 11), GATE_MM0(CLK_MM_MDP_RDMA0, "mm_mdp_rdma0", "mm_sel", 12), GATE_MM0(CLK_MM_MDP_RDMA1, "mm_mdp_rdma1", "mm_sel", 13), GATE_MM0(CLK_MM_MDP_RSZ0, "mm_mdp_rsz0", "mm_sel", 14), GATE_MM0(CLK_MM_MDP_RSZ1, "mm_mdp_rsz1", "mm_sel", 15), GATE_MM0(CLK_MM_MDP_TDSHP, "mm_mdp_tdshp", "mm_sel", 16), GATE_MM0(CLK_MM_MDP_WROT0, "mm_mdp_wrot0", "mm_sel", 17), GATE_MM0(CLK_MM_MDP_WROT1, "mm_mdp_wrot1", "mm_sel", 18), GATE_MM0(CLK_MM_FAKE_ENG, "mm_fake_eng", "mm_sel", 19), GATE_MM0(CLK_MM_DISP_OVL0, "mm_disp_ovl0", "mm_sel", 20), GATE_MM0(CLK_MM_DISP_OVL0_2L, "mm_disp_ovl0_2l", "mm_sel", 21), GATE_MM0(CLK_MM_DISP_OVL1_2L, "mm_disp_ovl1_2l", "mm_sel", 22), GATE_MM0(CLK_MM_DISP_RDMA0, "mm_disp_rdma0", "mm_sel", 23), GATE_MM0(CLK_MM_DISP_RDMA1, "mm_disp_rdma1", "mm_sel", 24), GATE_MM0(CLK_MM_DISP_WDMA0, "mm_disp_wdma0", "mm_sel", 25), GATE_MM0(CLK_MM_DISP_COLOR0, "mm_disp_color0", "mm_sel", 26), GATE_MM0(CLK_MM_DISP_CCORR0, "mm_disp_ccorr0", "mm_sel", 27), GATE_MM0(CLK_MM_DISP_AAL0, "mm_disp_aal0", "mm_sel", 28), GATE_MM0(CLK_MM_DISP_GAMMA0, "mm_disp_gamma0", "mm_sel", 29), GATE_MM0(CLK_MM_DISP_DITHER0, "mm_disp_dither0", "mm_sel", 30), GATE_MM0(CLK_MM_DISP_SPLIT, "mm_disp_split", "mm_sel", 31), /* MM1 */ GATE_MM1(CLK_MM_DSI0_MM_CK, "mm_dsi0_mmck", "mm_sel", 0), GATE_MM1(CLK_MM_DSI0_IF_CK, "mm_dsi0_ifck", "mm_sel", 1), GATE_MM1(CLK_MM_DPI_MM_CK, "mm_dpi_mmck", "mm_sel", 2), GATE_MM1(CLK_MM_DPI_IF_CK, "mm_dpi_ifck", "dpi0_sel", 3), GATE_MM1(CLK_MM_FAKE_ENG2, "mm_fake_eng2", "mm_sel", 4), GATE_MM1(CLK_MM_MDP_DL_RX_CK, "mm_mdp_dl_rxck", "mm_sel", 5), GATE_MM1(CLK_MM_IPU_DL_RX_CK, "mm_ipu_dl_rxck", "mm_sel", 6), GATE_MM1(CLK_MM_26M, "mm_26m", "f_f26m_ck", 7), GATE_MM1(CLK_MM_MM_R2Y, "mm_mmsys_r2y", "mm_sel", 8), GATE_MM1(CLK_MM_DISP_RSZ, "mm_disp_rsz", "mm_sel", 9), GATE_MM1(CLK_MM_MDP_AAL, "mm_mdp_aal", "mm_sel", 10), GATE_MM1(CLK_MM_MDP_HDR, "mm_mdp_hdr", "mm_sel", 11), GATE_MM1(CLK_MM_DBI_MM_CK, "mm_dbi_mmck", "mm_sel", 12), GATE_MM1(CLK_MM_DBI_IF_CK, "mm_dbi_ifck", "dpi0_sel", 13), GATE_MM1(CLK_MM_DISP_POSTMASK0, "mm_disp_pm0", "mm_sel", 14), GATE_MM1(CLK_MM_DISP_HRT_BW, "mm_disp_hrt_bw", "mm_sel", 15), GATE_MM1(CLK_MM_DISP_OVL_FBDC, "mm_disp_ovl_fbdc", "mm_sel", 16), }; static const struct mtk_clk_desc mm_desc = { .clks = mm_clks, .num_clks = ARRAY_SIZE(mm_clks), }; static const struct platform_device_id clk_mt6779_mm_id_table[] = { { .name = "clk-mt6779-mm", .driver_data = (kernel_ulong_t)&mm_desc }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, clk_mt6779_mm_id_table); static struct platform_driver clk_mt6779_mm_drv = { .probe = mtk_clk_pdev_probe, .remove_new = mtk_clk_pdev_remove, .driver = { .name = "clk-mt6779-mm", }, .id_table = clk_mt6779_mm_id_table, }; module_platform_driver(clk_mt6779_mm_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt6779-mm.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2022 MediaTek Inc. * Author: Garmin Chang <[email protected]> */ #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-mux.h" static DEFINE_SPINLOCK(mt8188_clk_lock); static const struct mtk_fixed_clk top_fixed_clks[] = { FIXED_CLK(CLK_TOP_ULPOSC1, "ulposc_ck1", NULL, 260000000), FIXED_CLK(CLK_TOP_MPHONE_SLAVE_BCK, "mphone_slave_bck", NULL, 49152000), FIXED_CLK(CLK_TOP_PAD_FPC, "pad_fpc_ck", NULL, 50000000), FIXED_CLK(CLK_TOP_466M_FMEM, "hd_466m_fmem_ck", NULL, 533000000), FIXED_CLK(CLK_TOP_PEXTP_PIPE, "pextp_pipe", NULL, 250000000), FIXED_CLK(CLK_TOP_DSI_PHY, "dsi_phy", NULL, 500000000), }; static const struct mtk_fixed_factor top_divs[] = { FACTOR(CLK_TOP_MAINPLL_D3, "mainpll_d3", "mainpll", 1, 3), FACTOR(CLK_TOP_MAINPLL_D4, "mainpll_d4", "mainpll", 1, 4), FACTOR(CLK_TOP_MAINPLL_D4_D2, "mainpll_d4_d2", "mainpll_d4", 1, 2), FACTOR(CLK_TOP_MAINPLL_D4_D4, "mainpll_d4_d4", "mainpll_d4", 1, 4), FACTOR(CLK_TOP_MAINPLL_D4_D8, "mainpll_d4_d8", "mainpll_d4", 1, 8), FACTOR(CLK_TOP_MAINPLL_D5, "mainpll_d5", "mainpll", 1, 5), FACTOR(CLK_TOP_MAINPLL_D5_D2, "mainpll_d5_d2", "mainpll_d5", 1, 2), FACTOR(CLK_TOP_MAINPLL_D5_D4, "mainpll_d5_d4", "mainpll_d5", 1, 4), FACTOR(CLK_TOP_MAINPLL_D5_D8, "mainpll_d5_d8", "mainpll_d5", 1, 8), FACTOR(CLK_TOP_MAINPLL_D6, "mainpll_d6", "mainpll", 1, 6), FACTOR(CLK_TOP_MAINPLL_D6_D2, "mainpll_d6_d2", "mainpll_d6", 1, 2), FACTOR(CLK_TOP_MAINPLL_D6_D4, "mainpll_d6_d4", "mainpll_d6", 1, 4), FACTOR(CLK_TOP_MAINPLL_D6_D8, "mainpll_d6_d8", "mainpll_d6", 1, 8), FACTOR(CLK_TOP_MAINPLL_D7, "mainpll_d7", "mainpll", 1, 7), FACTOR(CLK_TOP_MAINPLL_D7_D2, "mainpll_d7_d2", "mainpll_d7", 1, 2), FACTOR(CLK_TOP_MAINPLL_D7_D4, "mainpll_d7_d4", "mainpll_d7", 1, 4), FACTOR(CLK_TOP_MAINPLL_D7_D8, "mainpll_d7_d8", "mainpll_d7", 1, 8), FACTOR(CLK_TOP_MAINPLL_D9, "mainpll_d9", "mainpll", 1, 9), FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2), FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3), FACTOR(CLK_TOP_UNIVPLL_D4, "univpll_d4", "univpll", 1, 4), FACTOR(CLK_TOP_UNIVPLL_D4_D2, "univpll_d4_d2", "univpll_d4", 1, 2), FACTOR(CLK_TOP_UNIVPLL_D4_D4, "univpll_d4_d4", "univpll_d4", 1, 4), FACTOR(CLK_TOP_UNIVPLL_D4_D8, "univpll_d4_d8", "univpll_d4", 1, 8), FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5), FACTOR(CLK_TOP_UNIVPLL_D5_D2, "univpll_d5_d2", "univpll_d5", 1, 2), FACTOR(CLK_TOP_UNIVPLL_D5_D4, "univpll_d5_d4", "univpll_d5", 1, 4), FACTOR(CLK_TOP_UNIVPLL_D5_D8, "univpll_d5_d8", "univpll_d5", 1, 8), FACTOR(CLK_TOP_UNIVPLL_D6, "univpll_d6", "univpll", 1, 6), FACTOR(CLK_TOP_UNIVPLL_D6_D2, "univpll_d6_d2", "univpll_d6", 1, 2), FACTOR(CLK_TOP_UNIVPLL_D6_D4, "univpll_d6_d4", "univpll_d6", 1, 4), FACTOR(CLK_TOP_UNIVPLL_D6_D8, "univpll_d6_d8", "univpll_d6", 1, 8), FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7), FACTOR(CLK_TOP_UNIVPLL_192M, "univpll_192m", "univpll", 1, 13), FACTOR(CLK_TOP_UNIVPLL_192M_D4, "univpll_192m_d4", "univpll_192m", 1, 4), FACTOR(CLK_TOP_UNIVPLL_192M_D8, "univpll_192m_d8", "univpll_192m", 1, 8), FACTOR(CLK_TOP_UNIVPLL_192M_D10, "univpll_192m_d10", "univpll_192m", 1, 10), FACTOR(CLK_TOP_UNIVPLL_192M_D16, "univpll_192m_d16", "univpll_192m", 1, 16), FACTOR(CLK_TOP_UNIVPLL_192M_D32, "univpll_192m_d32", "univpll_192m", 1, 32), FACTOR(CLK_TOP_APLL1_D3, "apll1_d3", "apll1", 1, 3), FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1", 1, 4), FACTOR(CLK_TOP_APLL2_D3, "apll2_d3", "apll2", 1, 3), FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2", 1, 4), FACTOR(CLK_TOP_APLL3_D4, "apll3_d4", "apll3", 1, 4), FACTOR(CLK_TOP_APLL4_D4, "apll4_d4", "apll4", 1, 4), FACTOR(CLK_TOP_APLL5_D4, "apll5_d4", "apll5", 1, 4), FACTOR(CLK_TOP_MMPLL_D4, "mmpll_d4", "mmpll", 1, 4), FACTOR(CLK_TOP_MMPLL_D4_D2, "mmpll_d4_d2", "mmpll_d4", 1, 2), FACTOR(CLK_TOP_MMPLL_D5, "mmpll_d5", "mmpll", 1, 5), FACTOR(CLK_TOP_MMPLL_D5_D2, "mmpll_d5_d2", "mmpll_d5", 1, 2), FACTOR(CLK_TOP_MMPLL_D5_D4, "mmpll_d5_d4", "mmpll_d5", 1, 4), FACTOR(CLK_TOP_MMPLL_D6, "mmpll_d6", "mmpll", 1, 6), FACTOR(CLK_TOP_MMPLL_D6_D2, "mmpll_d6_d2", "mmpll_d6", 1, 2), FACTOR(CLK_TOP_MMPLL_D7, "mmpll_d7", "mmpll", 1, 7), FACTOR(CLK_TOP_MMPLL_D9, "mmpll_d9", "mmpll", 1, 9), FACTOR(CLK_TOP_TVDPLL1_D2, "tvdpll1_d2", "tvdpll1", 1, 2), FACTOR(CLK_TOP_TVDPLL1_D4, "tvdpll1_d4", "tvdpll1", 1, 4), FACTOR(CLK_TOP_TVDPLL1_D8, "tvdpll1_d8", "tvdpll1", 1, 8), FACTOR(CLK_TOP_TVDPLL1_D16, "tvdpll1_d16", "tvdpll1", 1, 16), FACTOR(CLK_TOP_TVDPLL2_D2, "tvdpll2_d2", "tvdpll2", 1, 2), FACTOR(CLK_TOP_TVDPLL2_D4, "tvdpll2_d4", "tvdpll2", 1, 4), FACTOR(CLK_TOP_TVDPLL2_D8, "tvdpll2_d8", "tvdpll2", 1, 8), FACTOR(CLK_TOP_TVDPLL2_D16, "tvdpll2_d16", "tvdpll2", 1, 16), FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1, 2), FACTOR(CLK_TOP_MSDCPLL_D16, "msdcpll_d16", "msdcpll", 1, 16), FACTOR(CLK_TOP_ETHPLL_D2, "ethpll_d2", "ethpll", 1, 2), FACTOR(CLK_TOP_ETHPLL_D4, "ethpll_d4", "ethpll", 1, 4), FACTOR(CLK_TOP_ETHPLL_D8, "ethpll_d8", "ethpll", 1, 8), FACTOR(CLK_TOP_ETHPLL_D10, "ethpll_d10", "ethpll", 1, 10), FACTOR(CLK_TOP_ADSPPLL_D2, "adsppll_d2", "adsppll", 1, 2), FACTOR(CLK_TOP_ADSPPLL_D4, "adsppll_d4", "adsppll", 1, 4), FACTOR(CLK_TOP_ADSPPLL_D8, "adsppll_d8", "adsppll", 1, 8), FACTOR(CLK_TOP_ULPOSC1_D2, "ulposc1_d2", "ulposc_ck1", 1, 2), FACTOR(CLK_TOP_ULPOSC1_D4, "ulposc1_d4", "ulposc_ck1", 1, 4), FACTOR(CLK_TOP_ULPOSC1_D8, "ulposc1_d8", "ulposc_ck1", 1, 8), FACTOR(CLK_TOP_ULPOSC1_D7, "ulposc1_d7", "ulposc_ck1", 1, 7), FACTOR(CLK_TOP_ULPOSC1_D10, "ulposc1_d10", "ulposc_ck1", 1, 10), FACTOR(CLK_TOP_ULPOSC1_D16, "ulposc1_d16", "ulposc_ck1", 1, 16), }; static const char * const axi_parents[] = { "clk26m", "mainpll_d4_d4", "mainpll_d7_d2", "mainpll_d4_d2", "mainpll_d5_d2", "mainpll_d6_d2", "ulposc1_d4" }; static const char * const spm_parents[] = { "clk26m", "ulposc1_d10", "mainpll_d7_d4", "clk32k" }; static const char * const scp_parents[] = { "clk26m", "univpll_d4", "mainpll_d6", "univpll_d6", "univpll_d4_d2", "mainpll_d4_d2", "univpll_d3", "mainpll_d3" }; static const char * const bus_aximem_parents[] = { "clk26m", "mainpll_d7_d2", "mainpll_d4_d2", "mainpll_d5_d2", "mainpll_d6" }; static const char * const vpp_parents[] = { "clk26m", "univpll_d6_d2", "mainpll_d5_d2", "mmpll_d6_d2", "univpll_d5_d2", "univpll_d4_d2", "mmpll_d4_d2", "mmpll_d7", "univpll_d6", "mainpll_d4", "mmpll_d5", "tvdpll1", "tvdpll2", "univpll_d4", "mmpll_d4" }; static const char * const ethdr_parents[] = { "clk26m", "univpll_d6_d2", "mainpll_d5_d2", "mmpll_d6_d2", "univpll_d5_d2", "univpll_d4_d2", "mmpll_d4_d2", "mmpll_d7", "univpll_d6", "mainpll_d4", "mmpll_d5_d4", "tvdpll1", "tvdpll2", "univpll_d4", "mmpll_d4" }; static const char * const ipe_parents[] = { "clk26m", "imgpll", "mainpll_d4", "mmpll_d6", "univpll_d6", "mainpll_d6", "mmpll_d4_d2", "univpll_d4_d2", "mainpll_d4_d2", "mmpll_d6_d2", "univpll_d5_d2", "mainpll_d7" }; static const char * const cam_parents[] = { "clk26m", "tvdpll1", "mainpll_d4", "mmpll_d4", "univpll_d4", "univpll_d5", "univpll_d6", "mmpll_d7", "univpll_d4_d2", "mainpll_d4_d2", "imgpll" }; static const char * const ccu_parents[] = { "clk26m", "univpll_d6", "mainpll_d4_d2", "mainpll_d4", "univpll_d5", "mainpll_d6", "mmpll_d6", "mmpll_d7", "univpll_d4_d2", "univpll_d7" }; static const char * const ccu_ahb_parents[] = { "clk26m", "univpll_d6", "mainpll_d4_d2", "mainpll_d4", "univpll_d5", "mainpll_d6", "mmpll_d6", "mmpll_d7", "univpll_d4_d2", "univpll_d7" }; static const char * const img_parents[] = { "clk26m", "imgpll", "univpll_d4", "mainpll_d4", "univpll_d5", "mmpll_d6", "mmpll_d7", "univpll_d6", "mainpll_d6", "mmpll_d4_d2", "univpll_d4_d2", "mainpll_d4_d2", "univpll_d5_d2" }; static const char * const camtm_parents[] = { "clk26m", "univpll_d4_d4", "univpll_d6_d2", "univpll_d6_d4" }; static const char * const dsp_parents[] = { "clk26m", "univpll_d6_d2", "univpll_d4_d2", "univpll_d5", "univpll_d4", "mmpll_d4", "mainpll_d3", "univpll_d3" }; static const char * const dsp1_parents[] = { "clk26m", "univpll_d6_d2", "mainpll_d4_d2", "univpll_d5", "mmpll_d5", "univpll_d4", "mainpll_d3", "univpll_d3" }; static const char * const dsp2_parents[] = { "clk26m", "univpll_d6_d2", "mainpll_d4_d2", "univpll_d5", "mmpll_d5", "univpll_d4", "mainpll_d3", "univpll_d3" }; static const char * const dsp3_parents[] = { "clk26m", "univpll_d6_d2", "mainpll_d4_d2", "univpll_d5", "mmpll_d5", "univpll_d4", "mainpll_d3", "univpll_d3" }; static const char * const dsp4_parents[] = { "clk26m", "univpll_d6_d2", "univpll_d4_d2", "mainpll_d4", "univpll_d4", "mmpll_d4", "mainpll_d3", "univpll_d3" }; static const char * const dsp5_parents[] = { "clk26m", "univpll_d6_d2", "univpll_d4_d2", "mainpll_d4", "univpll_d4", "mmpll_d4", "mainpll_d3", "univpll_d3" }; static const char * const dsp6_parents[] = { "clk26m", "univpll_d6_d2", "univpll_d4_d2", "mainpll_d4", "univpll_d4", "mmpll_d4", "mainpll_d3", "univpll_d3" }; static const char * const dsp7_parents[] = { "clk26m", "univpll_d6_d2", "univpll_d4_d2", "univpll_d5", "univpll_d4", "mmpll_d4", "mainpll_d3", "univpll_d3" }; static const char * const mfg_core_tmp_parents[] = { "clk26m", "mainpll_d5_d2", "univpll_d6", "univpll_d7" }; static const char * const camtg_parents[] = { "clk26m", "univpll_192m_d8", "univpll_d6_d8", "univpll_192m_d4", "univpll_192m_d10", "clk13m", "univpll_192m_d16", "univpll_192m_d32" }; static const char * const camtg2_parents[] = { "clk26m", "univpll_192m_d8", "univpll_d6_d8", "univpll_192m_d4", "univpll_192m_d10", "clk13m", "univpll_192m_d16", "univpll_192m_d32" }; static const char * const camtg3_parents[] = { "clk26m", "univpll_192m_d8", "univpll_d6_d8", "univpll_192m_d4", "univpll_192m_d10", "clk13m", "univpll_192m_d16", "univpll_192m_d32" }; static const char * const uart_parents[] = { "clk26m", "univpll_d6_d8" }; static const char * const spi_parents[] = { "clk26m", "mainpll_d5_d4", "mainpll_d6_d4", "univpll_d6_d4", "univpll_d6_d2", "mainpll_d6_d2", "mainpll_d4_d4", "univpll_d5_d4" }; static const char * const msdc5hclk_parents[] = { "clk26m", "mainpll_d4_d2", "mainpll_d6_d2" }; static const char * const msdc50_0_parents[] = { "clk26m", "msdcpll", "msdcpll_d2", "univpll_d4_d4", "mainpll_d6_d2", "univpll_d4_d2" }; static const char * const msdc30_1_parents[] = { "clk26m", "univpll_d6_d2", "mainpll_d6_d2", "mainpll_d7_d2", "msdcpll_d2" }; static const char * const msdc30_2_parents[] = { "clk26m", "univpll_d6_d2", "mainpll_d6_d2", "mainpll_d7_d2", "msdcpll_d2" }; static const char * const intdir_parents[] = { "clk26m", "univpll_d6", "mainpll_d4", "univpll_d4" }; static const char * const aud_intbus_parents[] = { "clk26m", "mainpll_d4_d4", "mainpll_d7_d4" }; static const char * const audio_h_parents[] = { "clk26m", "univpll_d7", "apll1", "apll2" }; static const char * const pwrap_ulposc_parents[] = { "clk26m", "ulposc1_d10", "ulposc1_d7", "ulposc1_d8", "ulposc1_d16", "mainpll_d4_d8", "univpll_d5_d8", "tvdpll1_d16" }; static const char * const atb_parents[] = { "clk26m", "mainpll_d4_d2", "mainpll_d5_d2" }; static const char * const sspm_parents[] = { "clk26m", "mainpll_d7_d2", "mainpll_d6_d2", "mainpll_d5_d2", "mainpll_d9", "mainpll_d4_d2" }; static const char * const dp_parents[] = { "clk26m", "tvdpll1_d2", "tvdpll2_d2", "tvdpll1_d4", "tvdpll2_d4", "tvdpll1_d8", "tvdpll2_d8", "tvdpll1_d16", "tvdpll2_d16" }; static const char * const edp_parents[] = { "clk26m", "tvdpll1_d2", "tvdpll2_d2", "tvdpll1_d4", "tvdpll2_d4", "tvdpll1_d8", "tvdpll2_d8", "tvdpll1_d16", "tvdpll2_d16" }; static const char * const dpi_parents[] = { "clk26m", "tvdpll1_d2", "tvdpll2_d2", "tvdpll1_d4", "tvdpll2_d4", "tvdpll1_d8", "tvdpll2_d8", "tvdpll1_d16", "tvdpll2_d16" }; static const char * const disp_pwm0_parents[] = { "clk26m", "univpll_d6_d4", "ulposc1_d2", "ulposc1_d4", "ulposc1_d16", "ethpll_d4" }; static const char * const disp_pwm1_parents[] = { "clk26m", "univpll_d6_d4", "ulposc1_d2", "ulposc1_d4", "ulposc1_d16" }; static const char * const usb_parents[] = { "clk26m", "univpll_d5_d4", "univpll_d6_d4", "univpll_d5_d2" }; static const char * const ssusb_xhci_parents[] = { "clk26m", "univpll_d5_d4", "univpll_d6_d4", "univpll_d5_d2" }; static const char * const usb_2p_parents[] = { "clk26m", "univpll_d5_d4", "univpll_d6_d4", "univpll_d5_d2" }; static const char * const ssusb_xhci_2p_parents[] = { "clk26m", "univpll_d5_d4", "univpll_d6_d4", "univpll_d5_d2" }; static const char * const usb_3p_parents[] = { "clk26m", "univpll_d5_d4", "univpll_d6_d4", "univpll_d5_d2" }; static const char * const ssusb_xhci_3p_parents[] = { "clk26m", "univpll_d5_d4", "univpll_d6_d4", "univpll_d5_d2" }; static const char * const i2c_parents[] = { "clk26m", "mainpll_d4_d8", "univpll_d5_d4" }; static const char * const seninf_parents[] = { "clk26m", "univpll_d4_d4", "univpll_d6_d2", "mainpll_d4_d2", "univpll_d7", "univpll_d6", "mmpll_d6", "univpll_d5" }; static const char * const seninf1_parents[] = { "clk26m", "univpll_d4_d4", "univpll_d6_d2", "mainpll_d4_d2", "univpll_d7", "univpll_d6", "mmpll_d6", "univpll_d5" }; static const char * const gcpu_parents[] = { "clk26m", "mainpll_d6", "univpll_d4_d2", "mmpll_d5_d2", "univpll_d5_d2" }; static const char * const venc_parents[] = { "clk26m", "mmpll_d4_d2", "mainpll_d6", "univpll_d4_d2", "mainpll_d4_d2", "univpll_d6", "mmpll_d6", "mainpll_d5_d2", "mainpll_d6_d2", "mmpll_d9", "univpll_d4_d4", "mainpll_d4", "univpll_d4", "univpll_d5", "univpll_d5_d2", "mainpll_d5" }; static const char * const vdec_parents[] = { "clk26m", "mainpll_d5_d2", "mmpll_d6_d2", "univpll_d5_d2", "univpll_d4_d2", "mmpll_d4_d2", "univpll_d6", "mainpll_d5", "univpll_d5", "mmpll_d6", "mainpll_d4", "tvdpll2", "univpll_d4", "imgpll", "univpll_d6_d2", "mmpll_d9" }; static const char * const pwm_parents[] = { "clk32k", "clk26m", "univpll_d4_d8", "univpll_d6_d4" }; static const char * const mcupm_parents[] = { "clk26m", "mainpll_d6_d2", "mainpll_d7_d4" }; static const char * const spmi_p_mst_parents[] = { "clk26m", "clk13m", "ulposc1_d8", "ulposc1_d10", "ulposc1_d16", "ulposc1_d7", "clk32k", "mainpll_d7_d8", "mainpll_d6_d8", "mainpll_d5_d8" }; static const char * const spmi_m_mst_parents[] = { "clk26m", "clk13m", "ulposc1_d8", "ulposc1_d10", "ulposc1_d16", "ulposc1_d7", "clk32k", "mainpll_d7_d8", "mainpll_d6_d8", "mainpll_d5_d8" }; static const char * const dvfsrc_parents[] = { "clk26m", "ulposc1_d10", "univpll_d6_d8", "msdcpll_d16" }; static const char * const tl_parents[] = { "clk26m", "univpll_d5_d4", "mainpll_d4_d4" }; static const char * const aes_msdcfde_parents[] = { "clk26m", "mainpll_d4_d2", "mainpll_d6", "mainpll_d4_d4", "univpll_d4_d2", "univpll_d6" }; static const char * const dsi_occ_parents[] = { "clk26m", "univpll_d6_d2", "univpll_d5_d2", "univpll_d4_d2" }; static const char * const wpe_vpp_parents[] = { "clk26m", "mainpll_d5_d2", "mmpll_d6_d2", "univpll_d5_d2", "mainpll_d4_d2", "univpll_d4_d2", "mmpll_d4_d2", "mainpll_d6", "mmpll_d7", "univpll_d6", "mainpll_d5", "univpll_d5", "mainpll_d4", "tvdpll1", "univpll_d4" }; static const char * const hdcp_parents[] = { "clk26m", "univpll_d4_d8", "mainpll_d5_d8", "univpll_d6_d4" }; static const char * const hdcp_24m_parents[] = { "clk26m", "univpll_192m_d4", "univpll_192m_d8", "univpll_d6_d8" }; static const char * const hdmi_apb_parents[] = { "clk26m", "univpll_d6_d4", "msdcpll_d2" }; static const char * const snps_eth_250m_parents[] = { "clk26m", "ethpll_d2" }; static const char * const snps_eth_62p4m_ptp_parents[] = { "apll2_d3", "apll1_d3", "clk26m", "ethpll_d8" }; static const char * const snps_eth_50m_rmii_parents[] = { "clk26m", "ethpll_d10" }; static const char * const adsp_parents[] = { "clk26m", "clk13m", "mainpll_d6", "mainpll_d5_d2", "univpll_d4_d4", "univpll_d4", "ulposc1_d2", "ulposc1_ck1", "adsppll", "adsppll_d2", "adsppll_d4", "adsppll_d8" }; static const char * const audio_local_bus_parents[] = { "clk26m", "clk13m", "mainpll_d4_d4", "mainpll_d7_d2", "mainpll_d5_d2", "mainpll_d4_d2", "mainpll_d7", "mainpll_d4", "univpll_d6", "ulposc1_ck1", "ulposc1_d4", "ulposc1_d2" }; static const char * const asm_h_parents[] = { "clk26m", "univpll_d6_d4", "univpll_d6_d2", "mainpll_d5_d2" }; static const char * const asm_l_parents[] = { "clk26m", "univpll_d6_d4", "univpll_d6_d2", "mainpll_d5_d2" }; static const char * const apll1_parents[] = { "clk26m", "apll1_d4" }; static const char * const apll2_parents[] = { "clk26m", "apll2_d4" }; static const char * const apll3_parents[] = { "clk26m", "apll3_d4" }; static const char * const apll4_parents[] = { "clk26m", "apll4_d4" }; static const char * const apll5_parents[] = { "clk26m", "apll5_d4" }; static const char * const i2so1_parents[] = { "clk26m", "apll1", "apll2", "apll3", "apll4", "apll5" }; static const char * const i2so2_parents[] = { "clk26m", "apll1", "apll2", "apll3", "apll4", "apll5" }; static const char * const i2si1_parents[] = { "clk26m", "apll1", "apll2", "apll3", "apll4", "apll5" }; static const char * const i2si2_parents[] = { "clk26m", "apll1", "apll2", "apll3", "apll4", "apll5" }; static const char * const dptx_parents[] = { "clk26m", "apll1", "apll2", "apll3", "apll4", "apll5" }; static const char * const aud_iec_parents[] = { "clk26m", "apll1", "apll2", "apll3", "apll4", "apll5" }; static const char * const a1sys_hp_parents[] = { "clk26m", "apll1_d4" }; static const char * const a2sys_parents[] = { "clk26m", "apll2_d4" }; static const char * const a3sys_parents[] = { "clk26m", "apll3_d4", "apll4_d4", "apll5_d4" }; static const char * const a4sys_parents[] = { "clk26m", "apll3_d4", "apll4_d4", "apll5_d4" }; static const char * const ecc_parents[] = { "clk26m", "mainpll_d4_d4", "mainpll_d5_d2", "mainpll_d4_d2", "mainpll_d6", "univpll_d6" }; static const char * const spinor_parents[] = { "clk26m", "clk13m", "mainpll_d7_d8", "univpll_d6_d8" }; static const char * const ulposc_parents[] = { "ulposc_ck1", "ethpll_d2", "mainpll_d4_d2", "ethpll_d10" }; static const char * const srck_parents[] = { "ulposc1_d10", "clk26m" }; static const char * const mfg_fast_ref_parents[] = { "top_mfg_core_tmp", "mfgpll" }; static const struct mtk_mux top_mtk_muxes[] = { /* * CLK_CFG_0 * axi_sel and bus_aximem_sel are bus clocks, should not be closed by Linux. * spm_sel and scp_sel are main clocks in always-on co-processor. */ MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_AXI, "top_axi", axi_parents, 0x020, 0x024, 0x028, 0, 4, 7, 0x04, 0, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_SPM, "top_spm", spm_parents, 0x020, 0x024, 0x028, 8, 4, 15, 0x04, 1, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_SCP, "top_scp", scp_parents, 0x020, 0x024, 0x028, 16, 4, 23, 0x04, 2, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_BUS_AXIMEM, "top_bus_aximem", bus_aximem_parents, 0x020, 0x024, 0x028, 24, 4, 31, 0x04, 3, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), /* CLK_CFG_1 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_VPP, "top_vpp", vpp_parents, 0x02C, 0x030, 0x034, 0, 4, 7, 0x04, 4), MUX_GATE_CLR_SET_UPD(CLK_TOP_ETHDR, "top_ethdr", ethdr_parents, 0x02C, 0x030, 0x034, 8, 4, 15, 0x04, 5), MUX_GATE_CLR_SET_UPD(CLK_TOP_IPE, "top_ipe", ipe_parents, 0x02C, 0x030, 0x034, 16, 4, 23, 0x04, 6), MUX_GATE_CLR_SET_UPD(CLK_TOP_CAM, "top_cam", cam_parents, 0x02C, 0x030, 0x034, 24, 4, 31, 0x04, 7), /* CLK_CFG_2 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_CCU, "top_ccu", ccu_parents, 0x038, 0x03C, 0x040, 0, 4, 7, 0x04, 8), MUX_GATE_CLR_SET_UPD(CLK_TOP_CCU_AHB, "top_ccu_ahb", ccu_ahb_parents, 0x038, 0x03C, 0x040, 8, 4, 15, 0x04, 9), MUX_GATE_CLR_SET_UPD(CLK_TOP_IMG, "top_img", img_parents, 0x038, 0x03C, 0x040, 16, 4, 23, 0x04, 10), MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTM, "top_camtm", camtm_parents, 0x038, 0x03C, 0x040, 24, 4, 31, 0x04, 11), /* CLK_CFG_3 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP, "top_dsp", dsp_parents, 0x044, 0x048, 0x04C, 0, 4, 7, 0x04, 12), MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP1, "top_dsp1", dsp1_parents, 0x044, 0x048, 0x04C, 8, 4, 15, 0x04, 13), MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP2, "top_dsp2", dsp2_parents, 0x044, 0x048, 0x04C, 16, 4, 23, 0x04, 14), MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP3, "top_dsp3", dsp3_parents, 0x044, 0x048, 0x04C, 24, 4, 31, 0x04, 15), /* CLK_CFG_4 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP4, "top_dsp4", dsp4_parents, 0x050, 0x054, 0x058, 0, 4, 7, 0x04, 16), MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP5, "top_dsp5", dsp5_parents, 0x050, 0x054, 0x058, 8, 4, 15, 0x04, 17), MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP6, "top_dsp6", dsp6_parents, 0x050, 0x054, 0x058, 16, 4, 23, 0x04, 18), MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP7, "top_dsp7", dsp7_parents, 0x050, 0x054, 0x058, 24, 4, 31, 0x04, 19), /* CLK_CFG_5 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MFG_CORE_TMP, "top_mfg_core_tmp", mfg_core_tmp_parents, 0x05C, 0x060, 0x064, 0, 4, 7, 0x04, 20), MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG, "top_camtg", camtg_parents, 0x05C, 0x060, 0x064, 8, 4, 15, 0x04, 21), MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG2, "top_camtg2", camtg2_parents, 0x05C, 0x060, 0x064, 16, 4, 23, 0x04, 22), MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG3, "top_camtg3", camtg3_parents, 0x05C, 0x060, 0x064, 24, 4, 31, 0x04, 23), /* CLK_CFG_6 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_UART, "top_uart", uart_parents, 0x068, 0x06C, 0x070, 0, 4, 7, 0x04, 24), MUX_GATE_CLR_SET_UPD(CLK_TOP_SPI, "top_spi", spi_parents, 0x068, 0x06C, 0x070, 8, 4, 15, 0x04, 25), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MSDC50_0_HCLK, "top_msdc5hclk", msdc5hclk_parents, 0x068, 0x06C, 0x070, 16, 4, 23, 0x04, 26, 0), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MSDC50_0, "top_msdc50_0", msdc50_0_parents, 0x068, 0x06C, 0x070, 24, 4, 31, 0x04, 27, 0), /* CLK_CFG_7 */ MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MSDC30_1, "top_msdc30_1", msdc30_1_parents, 0x074, 0x078, 0x07C, 0, 4, 7, 0x04, 28, 0), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MSDC30_2, "top_msdc30_2", msdc30_2_parents, 0x074, 0x078, 0x07C, 8, 4, 15, 0x04, 29, 0), MUX_GATE_CLR_SET_UPD(CLK_TOP_INTDIR, "top_intdir", intdir_parents, 0x074, 0x078, 0x07C, 16, 4, 23, 0x04, 30), MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_INTBUS, "top_aud_intbus", aud_intbus_parents, 0x074, 0x078, 0x07C, 24, 4, 31, 0x04, 31), /* CLK_CFG_8 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_AUDIO_H, "top_audio_h", audio_h_parents, 0x080, 0x084, 0x088, 0, 4, 7, 0x08, 0), MUX_GATE_CLR_SET_UPD(CLK_TOP_PWRAP_ULPOSC, "top_pwrap_ulposc", pwrap_ulposc_parents, 0x080, 0x084, 0x088, 8, 4, 15, 0x08, 1), MUX_GATE_CLR_SET_UPD(CLK_TOP_ATB, "top_atb", atb_parents, 0x080, 0x084, 0x088, 16, 4, 23, 0x08, 2), MUX_GATE_CLR_SET_UPD(CLK_TOP_SSPM, "top_sspm", sspm_parents, 0x080, 0x084, 0x088, 24, 4, 31, 0x08, 3), /* CLK_CFG_9 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_DP, "top_dp", dp_parents, 0x08C, 0x090, 0x094, 0, 4, 7, 0x08, 4), MUX_GATE_CLR_SET_UPD(CLK_TOP_EDP, "top_edp", edp_parents, 0x08C, 0x090, 0x094, 8, 4, 15, 0x08, 5), MUX_GATE_CLR_SET_UPD(CLK_TOP_DPI, "top_dpi", dpi_parents, 0x08C, 0x090, 0x094, 16, 4, 23, 0x08, 6), MUX_GATE_CLR_SET_UPD(CLK_TOP_DISP_PWM0, "top_disp_pwm0", disp_pwm0_parents, 0x08C, 0x090, 0x094, 24, 4, 31, 0x08, 7), /* CLK_CFG_10 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_DISP_PWM1, "top_disp_pwm1", disp_pwm1_parents, 0x098, 0x09C, 0x0A0, 0, 4, 7, 0x08, 8), MUX_GATE_CLR_SET_UPD(CLK_TOP_USB_TOP, "top_usb_top", usb_parents, 0x098, 0x09C, 0x0A0, 8, 4, 15, 0x08, 9), MUX_GATE_CLR_SET_UPD(CLK_TOP_SSUSB_XHCI, "top_ssusb_xhci", ssusb_xhci_parents, 0x098, 0x09C, 0x0A0, 16, 4, 23, 0x08, 10), MUX_GATE_CLR_SET_UPD(CLK_TOP_USB_TOP_2P, "top_usb_top_2p", usb_2p_parents, 0x098, 0x09C, 0x0A0, 24, 4, 31, 0x08, 11), /* CLK_CFG_11 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_SSUSB_XHCI_2P, "top_ssusb_xhci_2p", ssusb_xhci_2p_parents, 0x0A4, 0x0A8, 0x0AC, 0, 4, 7, 0x08, 12), MUX_GATE_CLR_SET_UPD(CLK_TOP_USB_TOP_3P, "top_usb_top_3p", usb_3p_parents, 0x0A4, 0x0A8, 0x0AC, 8, 4, 15, 0x08, 13), MUX_GATE_CLR_SET_UPD(CLK_TOP_SSUSB_XHCI_3P, "top_ssusb_xhci_3p", ssusb_xhci_3p_parents, 0x0A4, 0x0A8, 0x0AC, 16, 4, 23, 0x08, 14), MUX_GATE_CLR_SET_UPD(CLK_TOP_I2C, "top_i2c", i2c_parents, 0x0A4, 0x0A8, 0x0AC, 24, 4, 31, 0x08, 15), /* CLK_CFG_12 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_SENINF, "top_seninf", seninf_parents, 0x0B0, 0x0B4, 0x0B8, 0, 4, 7, 0x08, 16), MUX_GATE_CLR_SET_UPD(CLK_TOP_SENINF1, "top_seninf1", seninf1_parents, 0x0B0, 0x0B4, 0x0B8, 8, 4, 15, 0x08, 17), MUX_GATE_CLR_SET_UPD(CLK_TOP_GCPU, "top_gcpu", gcpu_parents, 0x0B0, 0x0B4, 0x0B8, 16, 4, 23, 0x08, 18), MUX_GATE_CLR_SET_UPD(CLK_TOP_VENC, "top_venc", venc_parents, 0x0B0, 0x0B4, 0x0B8, 24, 4, 31, 0x08, 19), /* * CLK_CFG_13 * top_mcupm is main clock in co-processor, should not be handled by Linux. */ MUX_GATE_CLR_SET_UPD(CLK_TOP_VDEC, "top_vdec", vdec_parents, 0x0BC, 0x0C0, 0x0C4, 0, 4, 7, 0x08, 20), MUX_GATE_CLR_SET_UPD(CLK_TOP_PWM, "top_pwm", pwm_parents, 0x0BC, 0x0C0, 0x0C4, 8, 4, 15, 0x08, 21), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MCUPM, "top_mcupm", mcupm_parents, 0x0BC, 0x0C0, 0x0C4, 16, 4, 23, 0x08, 22, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), MUX_GATE_CLR_SET_UPD(CLK_TOP_SPMI_P_MST, "top_spmi_p_mst", spmi_p_mst_parents, 0x0BC, 0x0C0, 0x0C4, 24, 4, 31, 0x08, 23), /* * CLK_CFG_14 * dvfsrc_sel is for internal DVFS usage, should not be handled by Linux. */ MUX_GATE_CLR_SET_UPD(CLK_TOP_SPMI_M_MST, "top_spmi_m_mst", spmi_m_mst_parents, 0x0C8, 0x0CC, 0x0D0, 0, 4, 7, 0x08, 24), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_DVFSRC, "top_dvfsrc", dvfsrc_parents, 0x0C8, 0x0CC, 0x0D0, 8, 4, 15, 0x08, 25, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), MUX_GATE_CLR_SET_UPD(CLK_TOP_TL, "top_tl", tl_parents, 0x0C8, 0x0CC, 0x0D0, 16, 4, 23, 0x08, 26), MUX_GATE_CLR_SET_UPD(CLK_TOP_AES_MSDCFDE, "top_aes_msdcfde", aes_msdcfde_parents, 0x0C8, 0x0CC, 0x0D0, 24, 4, 31, 0x08, 27), /* CLK_CFG_15 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_DSI_OCC, "top_dsi_occ", dsi_occ_parents, 0x0D4, 0x0D8, 0x0DC, 0, 4, 7, 0x08, 28), MUX_GATE_CLR_SET_UPD(CLK_TOP_WPE_VPP, "top_wpe_vpp", wpe_vpp_parents, 0x0D4, 0x0D8, 0x0DC, 8, 4, 15, 0x08, 29), MUX_GATE_CLR_SET_UPD(CLK_TOP_HDCP, "top_hdcp", hdcp_parents, 0x0D4, 0x0D8, 0x0DC, 16, 4, 23, 0x08, 30), MUX_GATE_CLR_SET_UPD(CLK_TOP_HDCP_24M, "top_hdcp_24m", hdcp_24m_parents, 0x0D4, 0x0D8, 0x0DC, 24, 4, 31, 0x08, 31), /* CLK_CFG_16 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_HDMI_APB, "top_hdmi_apb", hdmi_apb_parents, 0x0E0, 0x0E4, 0x0E8, 0, 4, 7, 0x0C, 0), MUX_GATE_CLR_SET_UPD(CLK_TOP_SNPS_ETH_250M, "top_snps_eth_250m", snps_eth_250m_parents, 0x0E0, 0x0E4, 0x0E8, 8, 4, 15, 0x0C, 1), MUX_GATE_CLR_SET_UPD(CLK_TOP_SNPS_ETH_62P4M_PTP, "top_snps_eth_62p4m_ptp", snps_eth_62p4m_ptp_parents, 0x0E0, 0x0E4, 0x0E8, 16, 4, 23, 0x0C, 2), MUX_GATE_CLR_SET_UPD(CLK_TOP_SNPS_ETH_50M_RMII, "snps_eth_50m_rmii", snps_eth_50m_rmii_parents, 0x0E0, 0x0E4, 0x0E8, 24, 4, 31, 0x0C, 3), /* CLK_CFG_17 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_ADSP, "top_adsp", adsp_parents, 0x0EC, 0x0F0, 0x0F4, 0, 4, 7, 0x0C, 4), MUX_GATE_CLR_SET_UPD(CLK_TOP_AUDIO_LOCAL_BUS, "top_audio_local_bus", audio_local_bus_parents, 0x0EC, 0x0F0, 0x0F4, 8, 4, 15, 0x0C, 5), MUX_GATE_CLR_SET_UPD(CLK_TOP_ASM_H, "top_asm_h", asm_h_parents, 0x0EC, 0x0F0, 0x0F4, 16, 4, 23, 0x0C, 6), MUX_GATE_CLR_SET_UPD(CLK_TOP_ASM_L, "top_asm_l", asm_l_parents, 0x0EC, 0x0F0, 0x0F4, 24, 4, 31, 0x0C, 7), /* CLK_CFG_18 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_APLL1, "top_apll1", apll1_parents, 0x0F8, 0x0FC, 0x100, 0, 4, 7, 0x0C, 8), MUX_GATE_CLR_SET_UPD(CLK_TOP_APLL2, "top_apll2", apll2_parents, 0x0F8, 0x0FC, 0x100, 8, 4, 15, 0x0C, 9), MUX_GATE_CLR_SET_UPD(CLK_TOP_APLL3, "top_apll3", apll3_parents, 0x0F8, 0x0FC, 0x100, 16, 4, 23, 0x0C, 10), MUX_GATE_CLR_SET_UPD(CLK_TOP_APLL4, "top_apll4", apll4_parents, 0x0F8, 0x0FC, 0x100, 24, 4, 31, 0x0C, 11), /* CLK_CFG_19 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_APLL5, "top_apll5", apll5_parents, 0x0104, 0x0108, 0x010C, 0, 4, 7, 0x0C, 12), MUX_GATE_CLR_SET_UPD(CLK_TOP_I2SO1, "top_i2so1", i2so1_parents, 0x0104, 0x0108, 0x010C, 8, 4, 15, 0x0C, 13), MUX_GATE_CLR_SET_UPD(CLK_TOP_I2SO2, "top_i2so2", i2so2_parents, 0x0104, 0x0108, 0x010C, 16, 4, 23, 0x0C, 14), MUX_GATE_CLR_SET_UPD(CLK_TOP_I2SI1, "top_i2si1", i2si1_parents, 0x0104, 0x0108, 0x010C, 24, 4, 31, 0x0C, 15), /* CLK_CFG_20 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_I2SI2, "top_i2si2", i2si2_parents, 0x0110, 0x0114, 0x0118, 0, 4, 7, 0x0C, 16), MUX_GATE_CLR_SET_UPD(CLK_TOP_DPTX, "top_dptx", dptx_parents, 0x0110, 0x0114, 0x0118, 8, 4, 15, 0x0C, 17), MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_IEC, "top_aud_iec", aud_iec_parents, 0x0110, 0x0114, 0x0118, 16, 4, 23, 0x0C, 18), MUX_GATE_CLR_SET_UPD(CLK_TOP_A1SYS_HP, "top_a1sys_hp", a1sys_hp_parents, 0x0110, 0x0114, 0x0118, 24, 4, 31, 0x0C, 19), /* CLK_CFG_21 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_A2SYS, "top_a2sys", a2sys_parents, 0x011C, 0x0120, 0x0124, 0, 4, 7, 0x0C, 20), MUX_GATE_CLR_SET_UPD(CLK_TOP_A3SYS, "top_a3sys", a3sys_parents, 0x011C, 0x0120, 0x0124, 8, 4, 15, 0x0C, 21), MUX_GATE_CLR_SET_UPD(CLK_TOP_A4SYS, "top_a4sys", a4sys_parents, 0x011C, 0x0120, 0x0124, 16, 4, 23, 0x0C, 22), MUX_GATE_CLR_SET_UPD(CLK_TOP_ECC, "top_ecc", ecc_parents, 0x011C, 0x0120, 0x0124, 24, 4, 31, 0x0C, 23), /* * CLK_CFG_22 * top_ulposc/top_srck are clock source of always on co-processor, * should not be closed by Linux. */ MUX_GATE_CLR_SET_UPD(CLK_TOP_SPINOR, "top_spinor", spinor_parents, 0x0128, 0x012C, 0x0130, 0, 4, 7, 0x0C, 24), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_ULPOSC, "top_ulposc", ulposc_parents, 0x0128, 0x012C, 0x0130, 8, 4, 15, 0x0C, 25, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_SRCK, "top_srck", srck_parents, 0x0128, 0x012C, 0x0130, 16, 4, 23, 0x0C, 26, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), }; static const struct mtk_composite top_adj_divs[] = { DIV_GATE(CLK_TOP_APLL12_CK_DIV0, "apll12_div0", "top_i2si1", 0x0320, 0, 0x0328, 8, 0), DIV_GATE(CLK_TOP_APLL12_CK_DIV1, "apll12_div1", "top_i2si2", 0x0320, 1, 0x0328, 8, 8), DIV_GATE(CLK_TOP_APLL12_CK_DIV2, "apll12_div2", "top_i2so1", 0x0320, 2, 0x0328, 8, 16), DIV_GATE(CLK_TOP_APLL12_CK_DIV3, "apll12_div3", "top_i2so2", 0x0320, 3, 0x0328, 8, 24), DIV_GATE(CLK_TOP_APLL12_CK_DIV4, "apll12_div4", "top_aud_iec", 0x0320, 4, 0x0334, 8, 0), DIV_GATE(CLK_TOP_APLL12_CK_DIV9, "apll12_div9", "top_dptx", 0x0320, 9, 0x0338, 8, 8), }; static const struct mtk_gate_regs top0_cg_regs = { .set_ofs = 0x238, .clr_ofs = 0x238, .sta_ofs = 0x238, }; static const struct mtk_gate_regs top1_cg_regs = { .set_ofs = 0x250, .clr_ofs = 0x250, .sta_ofs = 0x250, }; #define GATE_TOP0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &top0_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv) #define GATE_TOP1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &top1_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv) static const struct mtk_gate top_clks[] = { /* TOP0 */ GATE_TOP0(CLK_TOP_CFGREG_CLOCK_EN_VPP0, "cfgreg_clock_vpp0", "top_vpp", 0), GATE_TOP0(CLK_TOP_CFGREG_CLOCK_EN_VPP1, "cfgreg_clock_vpp1", "top_vpp", 1), GATE_TOP0(CLK_TOP_CFGREG_CLOCK_EN_VDO0, "cfgreg_clock_vdo0", "top_vpp", 2), GATE_TOP0(CLK_TOP_CFGREG_CLOCK_EN_VDO1, "cfgreg_clock_vdo1", "top_vpp", 3), GATE_TOP0(CLK_TOP_CFGREG_CLOCK_ISP_AXI_GALS, "cfgreg_clock_isp_axi_gals", "top_vpp", 4), GATE_TOP0(CLK_TOP_CFGREG_F26M_VPP0, "cfgreg_f26m_vpp0", "clk26m", 5), GATE_TOP0(CLK_TOP_CFGREG_F26M_VPP1, "cfgreg_f26m_vpp1", "clk26m", 6), GATE_TOP0(CLK_TOP_CFGREG_F26M_VDO0, "cfgreg_f26m_vdo0", "clk26m", 7), GATE_TOP0(CLK_TOP_CFGREG_F26M_VDO1, "cfgreg_f26m_vdo1", "clk26m", 8), GATE_TOP0(CLK_TOP_CFGREG_AUD_F26M_AUD, "cfgreg_aud_f26m_aud", "clk26m", 9), GATE_TOP0(CLK_TOP_CFGREG_UNIPLL_SES, "cfgreg_unipll_ses", "univpll_d2", 15), GATE_TOP0(CLK_TOP_CFGREG_F_PCIE_PHY_REF, "cfgreg_f_pcie_phy_ref", "clk26m", 18), /* TOP1 */ GATE_TOP1(CLK_TOP_SSUSB_TOP_REF, "ssusb_ref", "clk26m", 0), GATE_TOP1(CLK_TOP_SSUSB_PHY_REF, "ssusb_phy_ref", "clk26m", 1), GATE_TOP1(CLK_TOP_SSUSB_TOP_P1_REF, "ssusb_p1_ref", "clk26m", 2), GATE_TOP1(CLK_TOP_SSUSB_PHY_P1_REF, "ssusb_phy_p1_ref", "clk26m", 3), GATE_TOP1(CLK_TOP_SSUSB_TOP_P2_REF, "ssusb_p2_ref", "clk26m", 4), GATE_TOP1(CLK_TOP_SSUSB_PHY_P2_REF, "ssusb_phy_p2_ref", "clk26m", 5), GATE_TOP1(CLK_TOP_SSUSB_TOP_P3_REF, "ssusb_p3_ref", "clk26m", 6), GATE_TOP1(CLK_TOP_SSUSB_PHY_P3_REF, "ssusb_phy_p3_ref", "clk26m", 7), }; static const struct of_device_id of_match_clk_mt8188_topck[] = { { .compatible = "mediatek,mt8188-topckgen" }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8188_topck); /* Register mux notifier for MFG mux */ static int clk_mt8188_reg_mfg_mux_notifier(struct device *dev, struct clk *clk) { struct mtk_mux_nb *mfg_mux_nb; mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL); if (!mfg_mux_nb) return -ENOMEM; mfg_mux_nb->ops = &clk_mux_ops; mfg_mux_nb->bypass_index = 0; /* Bypass to TOP_MFG_CORE_TMP */ return devm_mtk_clk_mux_notifier_register(dev, clk, mfg_mux_nb); } static int clk_mt8188_topck_probe(struct platform_device *pdev) { struct clk_hw_onecell_data *top_clk_data; struct device_node *node = pdev->dev.of_node; struct clk_hw *hw; int r; void __iomem *base; top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK); if (!top_clk_data) return -ENOMEM; base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) { r = PTR_ERR(base); goto free_top_data; } r = mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks), top_clk_data); if (r) goto free_top_data; r = mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data); if (r) goto unregister_fixed_clks; r = mtk_clk_register_muxes(&pdev->dev, top_mtk_muxes, ARRAY_SIZE(top_mtk_muxes), node, &mt8188_clk_lock, top_clk_data); if (r) goto unregister_factors; hw = devm_clk_hw_register_mux(&pdev->dev, "mfg_ck_fast_ref", mfg_fast_ref_parents, ARRAY_SIZE(mfg_fast_ref_parents), CLK_SET_RATE_PARENT, (base + 0x250), 8, 1, 0, &mt8188_clk_lock); if (IS_ERR(hw)) { r = PTR_ERR(hw); goto unregister_muxes; } top_clk_data->hws[CLK_TOP_MFG_CK_FAST_REF] = hw; r = clk_mt8188_reg_mfg_mux_notifier(&pdev->dev, top_clk_data->hws[CLK_TOP_MFG_CK_FAST_REF]->clk); if (r) goto unregister_muxes; r = mtk_clk_register_composites(&pdev->dev, top_adj_divs, ARRAY_SIZE(top_adj_divs), base, &mt8188_clk_lock, top_clk_data); if (r) goto unregister_muxes; r = mtk_clk_register_gates(&pdev->dev, node, top_clks, ARRAY_SIZE(top_clks), top_clk_data); if (r) goto unregister_composite_divs; r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, top_clk_data); if (r) goto unregister_gates; platform_set_drvdata(pdev, top_clk_data); return r; unregister_gates: mtk_clk_unregister_gates(top_clks, ARRAY_SIZE(top_clks), top_clk_data); unregister_composite_divs: mtk_clk_unregister_composites(top_adj_divs, ARRAY_SIZE(top_adj_divs), top_clk_data); unregister_muxes: mtk_clk_unregister_muxes(top_mtk_muxes, ARRAY_SIZE(top_mtk_muxes), top_clk_data); unregister_factors: mtk_clk_unregister_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data); unregister_fixed_clks: mtk_clk_unregister_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks), top_clk_data); free_top_data: mtk_free_clk_data(top_clk_data); return r; } static void clk_mt8188_topck_remove(struct platform_device *pdev) { struct clk_hw_onecell_data *top_clk_data = platform_get_drvdata(pdev); struct device_node *node = pdev->dev.of_node; of_clk_del_provider(node); mtk_clk_unregister_gates(top_clks, ARRAY_SIZE(top_clks), top_clk_data); mtk_clk_unregister_composites(top_adj_divs, ARRAY_SIZE(top_adj_divs), top_clk_data); mtk_clk_unregister_muxes(top_mtk_muxes, ARRAY_SIZE(top_mtk_muxes), top_clk_data); mtk_clk_unregister_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data); mtk_clk_unregister_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks), top_clk_data); mtk_free_clk_data(top_clk_data); } static struct platform_driver clk_mt8188_topck_drv = { .probe = clk_mt8188_topck_probe, .remove_new = clk_mt8188_topck_remove, .driver = { .name = "clk-mt8188-topck", .of_match_table = of_match_clk_mt8188_topck, }, }; module_platform_driver(clk_mt8188_topck_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8188-topckgen.c
// SPDX-License-Identifier: GPL-2.0-only // // Copyright (c) 2022 MediaTek Inc. // Author: Chun-Jie Chen <[email protected]> #include <linux/clk-provider.h> #include <linux/platform_device.h> #include <dt-bindings/clock/mt8186-clk.h> #include "clk-gate.h" #include "clk-mtk.h" static const struct mtk_gate_regs cam_cg_regs = { .set_ofs = 0x4, .clr_ofs = 0x8, .sta_ofs = 0x0, }; #define GATE_CAM(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &cam_cg_regs, _shift, &mtk_clk_gate_ops_setclr) static const struct mtk_gate cam_clks[] = { GATE_CAM(CLK_CAM_LARB13, "cam_larb13", "top_cam", 0), GATE_CAM(CLK_CAM_DFP_VAD, "cam_dfp_vad", "top_cam", 1), GATE_CAM(CLK_CAM_LARB14, "cam_larb14", "top_cam", 2), GATE_CAM(CLK_CAM, "cam", "top_cam", 6), GATE_CAM(CLK_CAMTG, "camtg", "top_cam", 7), GATE_CAM(CLK_CAM_SENINF, "cam_seninf", "top_cam", 8), GATE_CAM(CLK_CAMSV1, "camsv1", "top_cam", 10), GATE_CAM(CLK_CAMSV2, "camsv2", "top_cam", 11), GATE_CAM(CLK_CAMSV3, "camsv3", "top_cam", 12), GATE_CAM(CLK_CAM_CCU0, "cam_ccu0", "top_cam", 13), GATE_CAM(CLK_CAM_CCU1, "cam_ccu1", "top_cam", 14), GATE_CAM(CLK_CAM_MRAW0, "cam_mraw0", "top_cam", 15), GATE_CAM(CLK_CAM_FAKE_ENG, "cam_fake_eng", "top_cam", 17), GATE_CAM(CLK_CAM_CCU_GALS, "cam_ccu_gals", "top_cam", 18), GATE_CAM(CLK_CAM2MM_GALS, "cam2mm_gals", "top_cam", 19), }; static const struct mtk_gate cam_rawa_clks[] = { GATE_CAM(CLK_CAM_RAWA_LARBX_RAWA, "cam_rawa_larbx_rawa", "top_cam", 0), GATE_CAM(CLK_CAM_RAWA, "cam_rawa", "top_cam", 1), GATE_CAM(CLK_CAM_RAWA_CAMTG_RAWA, "cam_rawa_camtg_rawa", "top_cam", 2), }; static const struct mtk_gate cam_rawb_clks[] = { GATE_CAM(CLK_CAM_RAWB_LARBX_RAWB, "cam_rawb_larbx_rawb", "top_cam", 0), GATE_CAM(CLK_CAM_RAWB, "cam_rawb", "top_cam", 1), GATE_CAM(CLK_CAM_RAWB_CAMTG_RAWB, "cam_rawb_camtg_rawb", "top_cam", 2), }; static const struct mtk_clk_desc cam_desc = { .clks = cam_clks, .num_clks = ARRAY_SIZE(cam_clks), }; static const struct mtk_clk_desc cam_rawa_desc = { .clks = cam_rawa_clks, .num_clks = ARRAY_SIZE(cam_rawa_clks), }; static const struct mtk_clk_desc cam_rawb_desc = { .clks = cam_rawb_clks, .num_clks = ARRAY_SIZE(cam_rawb_clks), }; static const struct of_device_id of_match_clk_mt8186_cam[] = { { .compatible = "mediatek,mt8186-camsys", .data = &cam_desc, }, { .compatible = "mediatek,mt8186-camsys_rawa", .data = &cam_rawa_desc, }, { .compatible = "mediatek,mt8186-camsys_rawb", .data = &cam_rawb_desc, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8186_cam); static struct platform_driver clk_mt8186_cam_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt8186-cam", .of_match_table = of_match_clk_mt8186_cam, }, }; module_platform_driver(clk_mt8186_cam_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8186-cam.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2018 MediaTek Inc. * Author: Owen Chen <[email protected]> */ #include <linux/clk-provider.h> #include <linux/platform_device.h> #include "clk-mtk.h" #include "clk-gate.h" #include <dt-bindings/clock/mt6765-clk.h> static const struct mtk_gate_regs audio0_cg_regs = { .set_ofs = 0x0, .clr_ofs = 0x0, .sta_ofs = 0x0, }; static const struct mtk_gate_regs audio1_cg_regs = { .set_ofs = 0x4, .clr_ofs = 0x4, .sta_ofs = 0x4, }; #define GATE_AUDIO0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &audio0_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr) #define GATE_AUDIO1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &audio1_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr) static const struct mtk_gate audio_clks[] = { /* AUDIO0 */ GATE_AUDIO0(CLK_AUDIO_AFE, "aud_afe", "audio_ck", 2), GATE_AUDIO0(CLK_AUDIO_22M, "aud_22m", "aud_engen1_ck", 8), GATE_AUDIO0(CLK_AUDIO_APLL_TUNER, "aud_apll_tuner", "aud_engen1_ck", 19), GATE_AUDIO0(CLK_AUDIO_ADC, "aud_adc", "audio_ck", 24), GATE_AUDIO0(CLK_AUDIO_DAC, "aud_dac", "audio_ck", 25), GATE_AUDIO0(CLK_AUDIO_DAC_PREDIS, "aud_dac_predis", "audio_ck", 26), GATE_AUDIO0(CLK_AUDIO_TML, "aud_tml", "audio_ck", 27), /* AUDIO1 */ GATE_AUDIO1(CLK_AUDIO_I2S1_BCLK, "aud_i2s1_bclk", "audio_ck", 4), GATE_AUDIO1(CLK_AUDIO_I2S2_BCLK, "aud_i2s2_bclk", "audio_ck", 5), GATE_AUDIO1(CLK_AUDIO_I2S3_BCLK, "aud_i2s3_bclk", "audio_ck", 6), GATE_AUDIO1(CLK_AUDIO_I2S4_BCLK, "aud_i2s4_bclk", "audio_ck", 7), }; static const struct mtk_clk_desc audio_desc = { .clks = audio_clks, .num_clks = ARRAY_SIZE(audio_clks), }; static const struct of_device_id of_match_clk_mt6765_audio[] = { { .compatible = "mediatek,mt6765-audsys", .data = &audio_desc, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt6765_audio); static struct platform_driver clk_mt6765_audio_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt6765-audio", .of_match_table = of_match_clk_mt6765_audio, }, }; module_platform_driver(clk_mt6765_audio_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt6765-audio.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2017 MediaTek Inc. * Author: Weiyi Lu <[email protected]> */ #include <linux/clk.h> #include <linux/delay.h> #include <linux/mfd/syscon.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include <linux/slab.h> #include "clk-gate.h" #include "clk-mtk.h" #include <dt-bindings/clock/mt2712-clk.h> static DEFINE_SPINLOCK(mt2712_clk_lock); static const struct mtk_fixed_clk top_fixed_clks[] = { FIXED_CLK(CLK_TOP_VPLL3_DPIX, "vpll3_dpix", NULL, 200000000), FIXED_CLK(CLK_TOP_VPLL_DPIX, "vpll_dpix", NULL, 200000000), FIXED_CLK(CLK_TOP_LTEPLL_FS26M, "ltepll_fs26m", NULL, 26000000), FIXED_CLK(CLK_TOP_DMPLL, "dmpll_ck", NULL, 350000000), FIXED_CLK(CLK_TOP_DSI0_LNTC, "dsi0_lntc", NULL, 143000000), FIXED_CLK(CLK_TOP_DSI1_LNTC, "dsi1_lntc", NULL, 143000000), FIXED_CLK(CLK_TOP_LVDSTX3_CLKDIG_CTS, "lvdstx3", NULL, 140000000), FIXED_CLK(CLK_TOP_LVDSTX_CLKDIG_CTS, "lvdstx", NULL, 140000000), FIXED_CLK(CLK_TOP_CLKRTC_EXT, "clkrtc_ext", NULL, 32768), FIXED_CLK(CLK_TOP_CLKRTC_INT, "clkrtc_int", NULL, 32747), FIXED_CLK(CLK_TOP_CSI0, "csi0", NULL, 26000000), FIXED_CLK(CLK_TOP_CVBSPLL, "cvbspll", NULL, 108000000), }; static const struct mtk_fixed_factor top_divs[] = { FACTOR(CLK_TOP_SYS_26M, "sys_26m", "clk26m", 1, 1), FACTOR(CLK_TOP_CLK26M_D2, "clk26m_d2", "sys_26m", 1, 2), FACTOR(CLK_TOP_ARMCA35PLL, "armca35pll_ck", "armca35pll", 1, 1), FACTOR(CLK_TOP_ARMCA35PLL_600M, "armca35pll_600m", "armca35pll_ck", 1, 2), FACTOR(CLK_TOP_ARMCA35PLL_400M, "armca35pll_400m", "armca35pll_ck", 1, 3), FACTOR(CLK_TOP_ARMCA72PLL, "armca72pll_ck", "armca72pll", 1, 1), FACTOR(CLK_TOP_SYSPLL, "syspll_ck", "mainpll", 1, 1), FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "syspll_ck", 1, 2), FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1, 2), FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1, 4), FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1, 8), FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1, 16), FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "syspll_ck", 1, 3), FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1, 2), FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1, 4), FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "syspll_ck", 1, 5), FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1, 2), FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1, 4), FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "syspll_ck", 1, 7), FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1, 2), FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1, 4), FACTOR(CLK_TOP_UNIVPLL, "univpll_ck", "univpll", 1, 1), FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll_ck", 1, 7), FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll_ck", 1, 26), FACTOR(CLK_TOP_UNIVPLL_D52, "univpll_d52", "univpll_ck", 1, 52), FACTOR(CLK_TOP_UNIVPLL_D104, "univpll_d104", "univpll_ck", 1, 104), FACTOR(CLK_TOP_UNIVPLL_D208, "univpll_d208", "univpll_ck", 1, 208), FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll_ck", 1, 2), FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1, 2), FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1, 4), FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1, 8), FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll_ck", 1, 3), FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll_d3", 1, 2), FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll_d3", 1, 4), FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll_d3", 1, 8), FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll_ck", 1, 5), FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1, 2), FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1, 4), FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1, 8), FACTOR(CLK_TOP_F_MP0_PLL1, "f_mp0_pll1_ck", "univpll_d2", 1, 1), FACTOR(CLK_TOP_F_MP0_PLL2, "f_mp0_pll2_ck", "univpll1_d2", 1, 1), FACTOR(CLK_TOP_F_BIG_PLL1, "f_big_pll1_ck", "univpll_d2", 1, 1), FACTOR(CLK_TOP_F_BIG_PLL2, "f_big_pll2_ck", "univpll1_d2", 1, 1), FACTOR(CLK_TOP_F_BUS_PLL1, "f_bus_pll1_ck", "univpll_d2", 1, 1), FACTOR(CLK_TOP_F_BUS_PLL2, "f_bus_pll2_ck", "univpll1_d2", 1, 1), FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1, 1), FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1, 2), FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1_ck", 1, 4), FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1_ck", 1, 8), FACTOR(CLK_TOP_APLL1_D16, "apll1_d16", "apll1_ck", 1, 16), FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1, 1), FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2_ck", 1, 2), FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2_ck", 1, 4), FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2_ck", 1, 8), FACTOR(CLK_TOP_APLL2_D16, "apll2_d16", "apll2_ck", 1, 16), FACTOR(CLK_TOP_LVDSPLL, "lvdspll_ck", "lvdspll", 1, 1), FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll_ck", 1, 2), FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll_ck", 1, 4), FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll_ck", 1, 8), FACTOR(CLK_TOP_LVDSPLL2, "lvdspll2_ck", "lvdspll2", 1, 1), FACTOR(CLK_TOP_LVDSPLL2_D2, "lvdspll2_d2", "lvdspll2_ck", 1, 2), FACTOR(CLK_TOP_LVDSPLL2_D4, "lvdspll2_d4", "lvdspll2_ck", 1, 4), FACTOR(CLK_TOP_LVDSPLL2_D8, "lvdspll2_d8", "lvdspll2_ck", 1, 8), FACTOR(CLK_TOP_ETHERPLL_125M, "etherpll_125m", "etherpll", 1, 1), FACTOR(CLK_TOP_ETHERPLL_50M, "etherpll_50m", "etherpll", 1, 1), FACTOR(CLK_TOP_CVBS, "cvbs", "cvbspll", 1, 1), FACTOR(CLK_TOP_CVBS_D2, "cvbs_d2", "cvbs", 1, 2), FACTOR(CLK_TOP_MMPLL, "mmpll_ck", "mmpll", 1, 1), FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll_ck", 1, 2), FACTOR(CLK_TOP_VENCPLL, "vencpll_ck", "vencpll", 1, 1), FACTOR(CLK_TOP_VENCPLL_D2, "vencpll_d2", "vencpll_ck", 1, 2), FACTOR(CLK_TOP_VCODECPLL, "vcodecpll_ck", "vcodecpll", 1, 1), FACTOR(CLK_TOP_VCODECPLL_D2, "vcodecpll_d2", "vcodecpll_ck", 1, 2), FACTOR(CLK_TOP_TVDPLL, "tvdpll_ck", "tvdpll", 1, 1), FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1, 2), FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1, 4), FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1, 8), FACTOR(CLK_TOP_TVDPLL_429M, "tvdpll_429m", "tvdpll", 1, 1), FACTOR(CLK_TOP_TVDPLL_429M_D2, "tvdpll_429m_d2", "tvdpll_429m", 1, 2), FACTOR(CLK_TOP_TVDPLL_429M_D4, "tvdpll_429m_d4", "tvdpll_429m", 1, 4), FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1, 1), FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1, 2), FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll_ck", 1, 4), FACTOR(CLK_TOP_MSDCPLL2, "msdcpll2_ck", "msdcpll2", 1, 1), FACTOR(CLK_TOP_MSDCPLL2_D2, "msdcpll2_d2", "msdcpll2_ck", 1, 2), FACTOR(CLK_TOP_MSDCPLL2_D4, "msdcpll2_d4", "msdcpll2_ck", 1, 4), FACTOR(CLK_TOP_D2A_ULCLK_6P5M, "d2a_ulclk_6p5m", "clk26m", 1, 4), FACTOR(CLK_TOP_APLL1_D3, "apll1_d3", "apll1_ck", 1, 3), FACTOR(CLK_TOP_APLL2_D3, "apll2_d3", "apll2_ck", 1, 3), }; static const char * const axi_parents[] = { "clk26m", "syspll1_d2", "syspll_d5", "syspll1_d4", "univpll_d5", "univpll2_d2", "msdcpll2_ck" }; static const char * const mem_parents[] = { "clk26m", "dmpll_ck" }; static const char * const mm_parents[] = { "clk26m", "vencpll_ck", "syspll_d3", "syspll1_d2", "syspll_d5", "syspll1_d4", "univpll1_d2", "univpll2_d2" }; static const char * const pwm_parents[] = { "clk26m", "univpll2_d4", "univpll3_d2", "univpll1_d4" }; static const char * const vdec_parents[] = { "clk26m", "vcodecpll_ck", "tvdpll_429m", "univpll_d3", "vencpll_ck", "syspll_d3", "univpll1_d2", "mmpll_d2", "syspll3_d2", "tvdpll_ck" }; static const char * const venc_parents[] = { "clk26m", "univpll1_d2", "mmpll_d2", "tvdpll_d2", "syspll1_d2", "univpll_d5", "vcodecpll_d2", "univpll2_d2", "syspll3_d2" }; static const char * const mfg_parents[] = { "clk26m", "mmpll_ck", "univpll_d3", "clk26m", "clk26m", "clk26m", "clk26m", "clk26m", "clk26m", "syspll_d3", "syspll1_d2", "syspll_d5", "univpll_d3", "univpll1_d2", "univpll_d5", "univpll2_d2" }; static const char * const camtg_parents[] = { "clk26m", "univpll_d52", "univpll_d208", "univpll_d104", "clk26m_d2", "univpll_d26", "univpll2_d8", "syspll3_d4", "syspll3_d2", "univpll1_d4", "univpll2_d2" }; static const char * const uart_parents[] = { "clk26m", "univpll2_d8" }; static const char * const spi_parents[] = { "clk26m", "univpll2_d4", "univpll1_d4", "univpll2_d2", "univpll3_d2", "univpll1_d8" }; static const char * const usb20_parents[] = { "clk26m", "univpll1_d8", "univpll3_d4" }; static const char * const usb30_parents[] = { "clk26m", "univpll3_d2", "univpll3_d4", "univpll2_d4" }; static const char * const msdc50_0_h_parents[] = { "clk26m", "syspll1_d2", "syspll2_d2", "syspll4_d2", "univpll_d5", "univpll1_d4" }; static const char * const msdc50_0_parents[] = { "clk26m", "msdcpll_ck", "msdcpll_d2", "univpll1_d4", "syspll2_d2", "msdcpll_d4", "vencpll_d2", "univpll1_d2", "msdcpll2_ck", "msdcpll2_d2", "msdcpll2_d4" }; static const char * const msdc30_1_parents[] = { "clk26m", "univpll2_d2", "msdcpll_d2", "univpll1_d4", "syspll2_d2", "univpll_d7", "vencpll_d2" }; static const char * const msdc30_3_parents[] = { "clk26m", "msdcpll2_ck", "msdcpll2_d2", "univpll2_d2", "msdcpll2_d4", "univpll1_d4", "syspll2_d2", "syspll_d7", "univpll_d7", "vencpll_d2", "msdcpll_ck", "msdcpll_d2", "msdcpll_d4" }; static const char * const audio_parents[] = { "clk26m", "syspll3_d4", "syspll4_d4", "syspll1_d16" }; static const char * const aud_intbus_parents[] = { "clk26m", "syspll1_d4", "syspll4_d2", "univpll3_d2", "univpll2_d8", "syspll3_d2", "syspll3_d4" }; static const char * const pmicspi_parents[] = { "clk26m", "syspll1_d8", "syspll3_d4", "syspll1_d16", "univpll3_d4", "univpll_d26", "syspll3_d4" }; static const char * const dpilvds1_parents[] = { "clk26m", "lvdspll2_ck", "lvdspll2_d2", "lvdspll2_d4", "lvdspll2_d8", "clkfpc" }; static const char * const atb_parents[] = { "clk26m", "syspll1_d2", "univpll_d5", "syspll_d5" }; static const char * const nr_parents[] = { "clk26m", "univpll1_d4", "syspll2_d2", "syspll1_d4", "univpll1_d8", "univpll3_d2", "univpll2_d2", "syspll_d5" }; static const char * const nfi2x_parents[] = { "clk26m", "syspll4_d4", "univpll3_d4", "univpll1_d8", "syspll2_d4", "univpll3_d2", "syspll_d7", "syspll2_d2", "univpll2_d2", "syspll_d5", "syspll1_d2" }; static const char * const irda_parents[] = { "clk26m", "univpll2_d4", "syspll2_d4", "univpll2_d8" }; static const char * const cci400_parents[] = { "clk26m", "vencpll_ck", "armca35pll_600m", "armca35pll_400m", "univpll_d2", "syspll_d2", "msdcpll_ck", "univpll_d3" }; static const char * const aud_1_parents[] = { "clk26m", "apll1_ck", "univpll2_d4", "univpll2_d8" }; static const char * const aud_2_parents[] = { "clk26m", "apll2_ck", "univpll2_d4", "univpll2_d8" }; static const char * const mem_mfg_parents[] = { "clk26m", "mmpll_ck", "univpll_d3" }; static const char * const axi_mfg_parents[] = { "clk26m", "axi_sel", "univpll_d5" }; static const char * const scam_parents[] = { "clk26m", "syspll3_d2", "univpll2_d4", "syspll2_d4" }; static const char * const nfiecc_parents[] = { "clk26m", "nfi2x_sel", "syspll_d7", "syspll2_d2", "univpll2_d2", "univpll_d5", "syspll1_d2" }; static const char * const pe2_mac_p0_parents[] = { "clk26m", "syspll1_d8", "syspll4_d2", "syspll2_d4", "univpll2_d4", "syspll3_d2" }; static const char * const dpilvds_parents[] = { "clk26m", "lvdspll_ck", "lvdspll_d2", "lvdspll_d4", "lvdspll_d8", "clkfpc" }; static const char * const hdcp_parents[] = { "clk26m", "syspll4_d2", "syspll3_d4", "univpll2_d4" }; static const char * const hdcp_24m_parents[] = { "clk26m", "univpll_d26", "univpll_d52", "univpll2_d8" }; static const char * const rtc_parents[] = { "clkrtc_int", "clkrtc_ext", "clk26m", "univpll3_d8" }; static const char * const spinor_parents[] = { "clk26m", "clk26m_d2", "syspll4_d4", "univpll2_d8", "univpll3_d4", "syspll4_d2", "syspll2_d4", "univpll2_d4", "etherpll_125m", "syspll1_d4" }; static const char * const apll_parents[] = { "clk26m", "apll1_ck", "apll1_d2", "apll1_d4", "apll1_d8", "apll1_d16", "apll2_ck", "apll2_d2", "apll2_d4", "apll2_d8", "apll2_d16", "clk26m", "clk26m" }; static const char * const a1sys_hp_parents[] = { "clk26m", "apll1_ck", "apll1_d2", "apll1_d4", "apll1_d8", "apll1_d3" }; static const char * const a2sys_hp_parents[] = { "clk26m", "apll2_ck", "apll2_d2", "apll2_d4", "apll2_d8", "apll2_d3" }; static const char * const asm_l_parents[] = { "clk26m", "univpll2_d4", "univpll2_d2", "syspll_d5" }; static const char * const i2so1_parents[] = { "clk26m", "apll1_ck", "apll2_ck" }; static const char * const ether_125m_parents[] = { "clk26m", "etherpll_125m", "univpll3_d2" }; static const char * const ether_50m_parents[] = { "clk26m", "etherpll_50m", "apll1_d3", "univpll3_d4" }; static const char * const jpgdec_parents[] = { "clk26m", "univpll_d3", "tvdpll_429m", "vencpll_ck", "syspll_d3", "vcodecpll_ck", "univpll1_d2", "armca35pll_400m", "tvdpll_429m_d2", "tvdpll_429m_d4" }; static const char * const spislv_parents[] = { "clk26m", "univpll2_d4", "univpll1_d4", "univpll2_d2", "univpll3_d2", "univpll1_d8", "univpll1_d2", "univpll_d5" }; static const char * const ether_parents[] = { "clk26m", "etherpll_50m", "univpll_d26" }; static const char * const di_parents[] = { "clk26m", "tvdpll_d2", "tvdpll_d4", "tvdpll_d8", "vencpll_ck", "vencpll_d2", "cvbs", "cvbs_d2" }; static const char * const tvd_parents[] = { "clk26m", "cvbs_d2", "univpll2_d8" }; static const char * const i2c_parents[] = { "clk26m", "univpll_d26", "univpll2_d4", "univpll3_d2", "univpll1_d4" }; static const char * const msdc0p_aes_parents[] = { "clk26m", "syspll_d2", "univpll_d3", "vcodecpll_ck" }; static const char * const cmsys_parents[] = { "clk26m", "univpll_d3", "syspll_d3", "syspll1_d2", "syspll2_d2" }; static const char * const gcpu_parents[] = { "clk26m", "syspll_d3", "syspll1_d2", "univpll1_d2", "univpll_d5", "univpll3_d2", "univpll_d3" }; static const char * const aud_apll1_parents[] = { "apll1", "clkaud_ext_i_1" }; static const char * const aud_apll2_parents[] = { "apll2", "clkaud_ext_i_2" }; static const char * const apll1_ref_parents[] = { "clkaud_ext_i_2", "clkaud_ext_i_1", "clki2si0_mck_i", "clki2si1_mck_i", "clki2si2_mck_i", "clktdmin_mclk_i", "clki2si2_mck_i", "clktdmin_mclk_i" }; static const char * const audull_vtx_parents[] = { "d2a_ulclk_6p5m", "clkaud_ext_i_0" }; static struct mtk_composite top_muxes[] = { /* CLK_CFG_0 */ MUX_GATE_FLAGS(CLK_TOP_AXI_SEL, "axi_sel", axi_parents, 0x040, 0, 3, 7, CLK_IS_CRITICAL), MUX_GATE_FLAGS(CLK_TOP_MEM_SEL, "mem_sel", mem_parents, 0x040, 8, 1, 15, CLK_IS_CRITICAL), MUX_GATE(CLK_TOP_MM_SEL, "mm_sel", mm_parents, 0x040, 24, 3, 31), /* CLK_CFG_1 */ MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x050, 0, 2, 7), MUX_GATE(CLK_TOP_VDEC_SEL, "vdec_sel", vdec_parents, 0x050, 8, 4, 15), MUX_GATE(CLK_TOP_VENC_SEL, "venc_sel", venc_parents, 0x050, 16, 4, 23), MUX_GATE(CLK_TOP_MFG_SEL, "mfg_sel", mfg_parents, 0x050, 24, 4, 31), /* CLK_CFG_2 */ MUX_GATE(CLK_TOP_CAMTG_SEL, "camtg_sel", camtg_parents, 0x060, 0, 4, 7), MUX_GATE(CLK_TOP_UART_SEL, "uart_sel", uart_parents, 0x060, 8, 1, 15), MUX_GATE(CLK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x060, 16, 3, 23), MUX_GATE(CLK_TOP_USB20_SEL, "usb20_sel", usb20_parents, 0x060, 24, 2, 31), /* CLK_CFG_3 */ MUX_GATE(CLK_TOP_USB30_SEL, "usb30_sel", usb30_parents, 0x070, 0, 2, 7), MUX_GATE(CLK_TOP_MSDC50_0_HCLK_SEL, "msdc50_0_h_sel", msdc50_0_h_parents, 0x070, 8, 3, 15), MUX_GATE(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel", msdc50_0_parents, 0x070, 16, 4, 23), MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel", msdc30_1_parents, 0x070, 24, 3, 31), /* CLK_CFG_4 */ MUX_GATE(CLK_TOP_MSDC30_2_SEL, "msdc30_2_sel", msdc30_1_parents, 0x080, 0, 3, 7), MUX_GATE(CLK_TOP_MSDC30_3_SEL, "msdc30_3_sel", msdc30_3_parents, 0x080, 8, 4, 15), MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel", audio_parents, 0x080, 16, 2, 23), MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel", aud_intbus_parents, 0x080, 24, 3, 31), /* CLK_CFG_5 */ MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents, 0x090, 0, 3, 7), MUX_GATE(CLK_TOP_DPILVDS1_SEL, "dpilvds1_sel", dpilvds1_parents, 0x090, 8, 3, 15), MUX_GATE(CLK_TOP_ATB_SEL, "atb_sel", atb_parents, 0x090, 16, 2, 23), MUX_GATE(CLK_TOP_NR_SEL, "nr_sel", nr_parents, 0x090, 24, 3, 31), /* CLK_CFG_6 */ MUX_GATE(CLK_TOP_NFI2X_SEL, "nfi2x_sel", nfi2x_parents, 0x0a0, 0, 4, 7), MUX_GATE(CLK_TOP_IRDA_SEL, "irda_sel", irda_parents, 0x0a0, 8, 2, 15), MUX_GATE(CLK_TOP_CCI400_SEL, "cci400_sel", cci400_parents, 0x0a0, 16, 3, 23), MUX_GATE(CLK_TOP_AUD_1_SEL, "aud_1_sel", aud_1_parents, 0x0a0, 24, 2, 31), /* CLK_CFG_7 */ MUX_GATE(CLK_TOP_AUD_2_SEL, "aud_2_sel", aud_2_parents, 0x0b0, 0, 2, 7), MUX_GATE(CLK_TOP_MEM_MFG_IN_AS_SEL, "mem_mfg_sel", mem_mfg_parents, 0x0b0, 8, 2, 15), MUX_GATE(CLK_TOP_AXI_MFG_IN_AS_SEL, "axi_mfg_sel", axi_mfg_parents, 0x0b0, 16, 2, 23), MUX_GATE(CLK_TOP_SCAM_SEL, "scam_sel", scam_parents, 0x0b0, 24, 2, 31), /* CLK_CFG_8 */ MUX_GATE(CLK_TOP_NFIECC_SEL, "nfiecc_sel", nfiecc_parents, 0x0c0, 0, 3, 7), MUX_GATE(CLK_TOP_PE2_MAC_P0_SEL, "pe2_mac_p0_sel", pe2_mac_p0_parents, 0x0c0, 8, 3, 15), MUX_GATE(CLK_TOP_PE2_MAC_P1_SEL, "pe2_mac_p1_sel", pe2_mac_p0_parents, 0x0c0, 16, 3, 23), MUX_GATE(CLK_TOP_DPILVDS_SEL, "dpilvds_sel", dpilvds_parents, 0x0c0, 24, 3, 31), /* CLK_CFG_9 */ MUX_GATE(CLK_TOP_MSDC50_3_HCLK_SEL, "msdc50_3_h_sel", msdc50_0_h_parents, 0x0d0, 0, 3, 7), MUX_GATE(CLK_TOP_HDCP_SEL, "hdcp_sel", hdcp_parents, 0x0d0, 8, 2, 15), MUX_GATE(CLK_TOP_HDCP_24M_SEL, "hdcp_24m_sel", hdcp_24m_parents, 0x0d0, 16, 2, 23), MUX_GATE_FLAGS(CLK_TOP_RTC_SEL, "rtc_sel", rtc_parents, 0x0d0, 24, 2, 31, CLK_IS_CRITICAL), /* CLK_CFG_10 */ MUX_GATE(CLK_TOP_SPINOR_SEL, "spinor_sel", spinor_parents, 0x500, 0, 4, 7), MUX_GATE(CLK_TOP_APLL_SEL, "apll_sel", apll_parents, 0x500, 8, 4, 15), MUX_GATE(CLK_TOP_APLL2_SEL, "apll2_sel", apll_parents, 0x500, 16, 4, 23), MUX_GATE(CLK_TOP_A1SYS_HP_SEL, "a1sys_hp_sel", a1sys_hp_parents, 0x500, 24, 3, 31), /* CLK_CFG_11 */ MUX_GATE(CLK_TOP_A2SYS_HP_SEL, "a2sys_hp_sel", a2sys_hp_parents, 0x510, 0, 3, 7), MUX_GATE(CLK_TOP_ASM_L_SEL, "asm_l_sel", asm_l_parents, 0x510, 8, 2, 15), MUX_GATE(CLK_TOP_ASM_M_SEL, "asm_m_sel", asm_l_parents, 0x510, 16, 2, 23), MUX_GATE(CLK_TOP_ASM_H_SEL, "asm_h_sel", asm_l_parents, 0x510, 24, 2, 31), /* CLK_CFG_12 */ MUX_GATE(CLK_TOP_I2SO1_SEL, "i2so1_sel", i2so1_parents, 0x520, 0, 2, 7), MUX_GATE(CLK_TOP_I2SO2_SEL, "i2so2_sel", i2so1_parents, 0x520, 8, 2, 15), MUX_GATE(CLK_TOP_I2SO3_SEL, "i2so3_sel", i2so1_parents, 0x520, 16, 2, 23), MUX_GATE(CLK_TOP_TDMO0_SEL, "tdmo0_sel", i2so1_parents, 0x520, 24, 2, 31), /* CLK_CFG_13 */ MUX_GATE(CLK_TOP_TDMO1_SEL, "tdmo1_sel", i2so1_parents, 0x530, 0, 2, 7), MUX_GATE(CLK_TOP_I2SI1_SEL, "i2si1_sel", i2so1_parents, 0x530, 8, 2, 15), MUX_GATE(CLK_TOP_I2SI2_SEL, "i2si2_sel", i2so1_parents, 0x530, 16, 2, 23), MUX_GATE(CLK_TOP_I2SI3_SEL, "i2si3_sel", i2so1_parents, 0x530, 24, 2, 31), /* CLK_CFG_14 */ MUX_GATE(CLK_TOP_ETHER_125M_SEL, "ether_125m_sel", ether_125m_parents, 0x540, 0, 2, 7), MUX_GATE(CLK_TOP_ETHER_50M_SEL, "ether_50m_sel", ether_50m_parents, 0x540, 8, 2, 15), MUX_GATE(CLK_TOP_JPGDEC_SEL, "jpgdec_sel", jpgdec_parents, 0x540, 16, 4, 23), MUX_GATE(CLK_TOP_SPISLV_SEL, "spislv_sel", spislv_parents, 0x540, 24, 3, 31), /* CLK_CFG_15 */ MUX_GATE(CLK_TOP_ETHER_50M_RMII_SEL, "ether_sel", ether_parents, 0x550, 0, 2, 7), MUX_GATE(CLK_TOP_CAM2TG_SEL, "cam2tg_sel", camtg_parents, 0x550, 8, 4, 15), MUX_GATE(CLK_TOP_DI_SEL, "di_sel", di_parents, 0x550, 16, 3, 23), MUX_GATE(CLK_TOP_TVD_SEL, "tvd_sel", tvd_parents, 0x550, 24, 2, 31), /* CLK_CFG_16 */ MUX_GATE(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents, 0x560, 0, 3, 7), MUX_GATE(CLK_TOP_PWM_INFRA_SEL, "pwm_infra_sel", pwm_parents, 0x560, 8, 2, 15), MUX_GATE(CLK_TOP_MSDC0P_AES_SEL, "msdc0p_aes_sel", msdc0p_aes_parents, 0x560, 16, 2, 23), MUX_GATE(CLK_TOP_CMSYS_SEL, "cmsys_sel", cmsys_parents, 0x560, 24, 3, 31), /* CLK_CFG_17 */ MUX_GATE(CLK_TOP_GCPU_SEL, "gcpu_sel", gcpu_parents, 0x570, 0, 3, 7), /* CLK_AUDDIV_4 */ MUX(CLK_TOP_AUD_APLL1_SEL, "aud_apll1_sel", aud_apll1_parents, 0x134, 0, 1), MUX(CLK_TOP_AUD_APLL2_SEL, "aud_apll2_sel", aud_apll2_parents, 0x134, 1, 1), MUX(CLK_TOP_DA_AUDULL_VTX_6P5M_SEL, "audull_vtx_sel", audull_vtx_parents, 0x134, 31, 1), MUX(CLK_TOP_APLL1_REF_SEL, "apll1_ref_sel", apll1_ref_parents, 0x134, 4, 3), MUX(CLK_TOP_APLL2_REF_SEL, "apll2_ref_sel", apll1_ref_parents, 0x134, 7, 3), }; static const char * const mcu_mp0_parents[] = { "clk26m", "armca35pll_ck", "f_mp0_pll1_ck", "f_mp0_pll2_ck" }; static const char * const mcu_mp2_parents[] = { "clk26m", "armca72pll_ck", "f_big_pll1_ck", "f_big_pll2_ck" }; static const char * const mcu_bus_parents[] = { "clk26m", "cci400_sel", "f_bus_pll1_ck", "f_bus_pll2_ck" }; static struct mtk_composite mcu_muxes[] = { /* mp0_pll_divider_cfg */ MUX_GATE_FLAGS(CLK_MCU_MP0_SEL, "mcu_mp0_sel", mcu_mp0_parents, 0x7A0, 9, 2, -1, CLK_IS_CRITICAL), /* mp2_pll_divider_cfg */ MUX_GATE_FLAGS(CLK_MCU_MP2_SEL, "mcu_mp2_sel", mcu_mp2_parents, 0x7A8, 9, 2, -1, CLK_IS_CRITICAL), /* bus_pll_divider_cfg */ MUX_GATE_FLAGS(CLK_MCU_BUS_SEL, "mcu_bus_sel", mcu_bus_parents, 0x7C0, 9, 2, -1, CLK_IS_CRITICAL), }; static const struct mtk_clk_divider top_adj_divs[] = { DIV_ADJ(CLK_TOP_APLL_DIV0, "apll_div0", "i2so1_sel", 0x124, 0, 8), DIV_ADJ(CLK_TOP_APLL_DIV1, "apll_div1", "i2so2_sel", 0x124, 8, 8), DIV_ADJ(CLK_TOP_APLL_DIV2, "apll_div2", "i2so3_sel", 0x124, 16, 8), DIV_ADJ(CLK_TOP_APLL_DIV3, "apll_div3", "tdmo0_sel", 0x124, 24, 8), DIV_ADJ(CLK_TOP_APLL_DIV4, "apll_div4", "tdmo1_sel", 0x128, 0, 8), DIV_ADJ(CLK_TOP_APLL_DIV5, "apll_div5", "i2si1_sel", 0x128, 8, 8), DIV_ADJ(CLK_TOP_APLL_DIV6, "apll_div6", "i2si2_sel", 0x128, 16, 8), DIV_ADJ(CLK_TOP_APLL_DIV7, "apll_div7", "i2si3_sel", 0x128, 24, 8), }; static const struct mtk_gate_regs top0_cg_regs = { .set_ofs = 0x120, .clr_ofs = 0x120, .sta_ofs = 0x120, }; static const struct mtk_gate_regs top1_cg_regs = { .set_ofs = 0x424, .clr_ofs = 0x424, .sta_ofs = 0x424, }; #define GATE_TOP0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &top0_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr) #define GATE_TOP1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &top1_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv) static const struct mtk_gate top_clks[] = { /* TOP0 */ GATE_TOP0(CLK_TOP_APLL_DIV_PDN0, "apll_div_pdn0", "i2so1_sel", 0), GATE_TOP0(CLK_TOP_APLL_DIV_PDN1, "apll_div_pdn1", "i2so2_sel", 1), GATE_TOP0(CLK_TOP_APLL_DIV_PDN2, "apll_div_pdn2", "i2so3_sel", 2), GATE_TOP0(CLK_TOP_APLL_DIV_PDN3, "apll_div_pdn3", "tdmo0_sel", 3), GATE_TOP0(CLK_TOP_APLL_DIV_PDN4, "apll_div_pdn4", "tdmo1_sel", 4), GATE_TOP0(CLK_TOP_APLL_DIV_PDN5, "apll_div_pdn5", "i2si1_sel", 5), GATE_TOP0(CLK_TOP_APLL_DIV_PDN6, "apll_div_pdn6", "i2si2_sel", 6), GATE_TOP0(CLK_TOP_APLL_DIV_PDN7, "apll_div_pdn7", "i2si3_sel", 7), /* TOP1 */ GATE_TOP1(CLK_TOP_NFI2X_EN, "nfi2x_en", "nfi2x_sel", 0), GATE_TOP1(CLK_TOP_NFIECC_EN, "nfiecc_en", "nfiecc_sel", 1), GATE_TOP1(CLK_TOP_NFI1X_CK_EN, "nfi1x_ck_en", "nfi2x_sel", 2), }; static const struct mtk_gate_regs infra_cg_regs = { .set_ofs = 0x40, .clr_ofs = 0x44, .sta_ofs = 0x48, }; #define GATE_INFRA(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &infra_cg_regs, _shift, &mtk_clk_gate_ops_setclr) static const struct mtk_gate infra_clks[] = { GATE_INFRA(CLK_INFRA_DBGCLK, "infra_dbgclk", "axi_sel", 0), GATE_INFRA(CLK_INFRA_GCE, "infra_gce", "axi_sel", 6), GATE_INFRA(CLK_INFRA_M4U, "infra_m4u", "mem_sel", 8), GATE_INFRA(CLK_INFRA_KP, "infra_kp", "axi_sel", 16), GATE_INFRA(CLK_INFRA_AO_SPI0, "infra_ao_spi0", "spi_sel", 24), GATE_INFRA(CLK_INFRA_AO_SPI1, "infra_ao_spi1", "spislv_sel", 25), GATE_INFRA(CLK_INFRA_AO_UART5, "infra_ao_uart5", "axi_sel", 26), }; static const struct mtk_gate_regs peri0_cg_regs = { .set_ofs = 0x8, .clr_ofs = 0x10, .sta_ofs = 0x18, }; static const struct mtk_gate_regs peri1_cg_regs = { .set_ofs = 0xc, .clr_ofs = 0x14, .sta_ofs = 0x1c, }; static const struct mtk_gate_regs peri2_cg_regs = { .set_ofs = 0x42c, .clr_ofs = 0x42c, .sta_ofs = 0x42c, }; #define GATE_PERI0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &peri0_cg_regs, _shift, &mtk_clk_gate_ops_setclr) #define GATE_PERI1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &peri1_cg_regs, _shift, &mtk_clk_gate_ops_setclr) #define GATE_PERI2(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &peri2_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv) static const struct mtk_gate peri_clks[] = { /* PERI0 */ GATE_PERI0(CLK_PERI_NFI, "per_nfi", "axi_sel", 0), GATE_PERI0(CLK_PERI_THERM, "per_therm", "axi_sel", 1), GATE_PERI0(CLK_PERI_PWM0, "per_pwm0", "pwm_sel", 2), GATE_PERI0(CLK_PERI_PWM1, "per_pwm1", "pwm_sel", 3), GATE_PERI0(CLK_PERI_PWM2, "per_pwm2", "pwm_sel", 4), GATE_PERI0(CLK_PERI_PWM3, "per_pwm3", "pwm_sel", 5), GATE_PERI0(CLK_PERI_PWM4, "per_pwm4", "pwm_sel", 6), GATE_PERI0(CLK_PERI_PWM5, "per_pwm5", "pwm_sel", 7), GATE_PERI0(CLK_PERI_PWM6, "per_pwm6", "pwm_sel", 8), GATE_PERI0(CLK_PERI_PWM7, "per_pwm7", "pwm_sel", 9), GATE_PERI0(CLK_PERI_PWM, "per_pwm", "pwm_sel", 10), GATE_PERI0(CLK_PERI_AP_DMA, "per_ap_dma", "axi_sel", 13), GATE_PERI0(CLK_PERI_MSDC30_0, "per_msdc30_0", "msdc50_0_sel", 14), GATE_PERI0(CLK_PERI_MSDC30_1, "per_msdc30_1", "msdc30_1_sel", 15), GATE_PERI0(CLK_PERI_MSDC30_2, "per_msdc30_2", "msdc30_2_sel", 16), GATE_PERI0(CLK_PERI_MSDC30_3, "per_msdc30_3", "msdc30_3_sel", 17), GATE_PERI0(CLK_PERI_UART0, "per_uart0", "uart_sel", 20), GATE_PERI0(CLK_PERI_UART1, "per_uart1", "uart_sel", 21), GATE_PERI0(CLK_PERI_UART2, "per_uart2", "uart_sel", 22), GATE_PERI0(CLK_PERI_UART3, "per_uart3", "uart_sel", 23), GATE_PERI0(CLK_PERI_I2C0, "per_i2c0", "axi_sel", 24), GATE_PERI0(CLK_PERI_I2C1, "per_i2c1", "axi_sel", 25), GATE_PERI0(CLK_PERI_I2C2, "per_i2c2", "axi_sel", 26), GATE_PERI0(CLK_PERI_I2C3, "per_i2c3", "axi_sel", 27), GATE_PERI0(CLK_PERI_I2C4, "per_i2c4", "axi_sel", 28), GATE_PERI0(CLK_PERI_AUXADC, "per_auxadc", "ltepll_fs26m", 29), GATE_PERI0(CLK_PERI_SPI0, "per_spi0", "spi_sel", 30), /* PERI1 */ GATE_PERI1(CLK_PERI_SPI, "per_spi", "spinor_sel", 1), GATE_PERI1(CLK_PERI_I2C5, "per_i2c5", "axi_sel", 3), GATE_PERI1(CLK_PERI_SPI2, "per_spi2", "spi_sel", 5), GATE_PERI1(CLK_PERI_SPI3, "per_spi3", "spi_sel", 6), GATE_PERI1(CLK_PERI_SPI5, "per_spi5", "spi_sel", 8), GATE_PERI1(CLK_PERI_UART4, "per_uart4", "uart_sel", 9), GATE_PERI1(CLK_PERI_SFLASH, "per_sflash", "uart_sel", 11), GATE_PERI1(CLK_PERI_GMAC, "per_gmac", "uart_sel", 12), GATE_PERI1(CLK_PERI_PCIE0, "per_pcie0", "uart_sel", 14), GATE_PERI1(CLK_PERI_PCIE1, "per_pcie1", "uart_sel", 15), GATE_PERI1(CLK_PERI_GMAC_PCLK, "per_gmac_pclk", "uart_sel", 16), /* PERI2 */ GATE_PERI2(CLK_PERI_MSDC50_0_EN, "per_msdc50_0_en", "msdc50_0_sel", 0), GATE_PERI2(CLK_PERI_MSDC30_1_EN, "per_msdc30_1_en", "msdc30_1_sel", 1), GATE_PERI2(CLK_PERI_MSDC30_2_EN, "per_msdc30_2_en", "msdc30_2_sel", 2), GATE_PERI2(CLK_PERI_MSDC30_3_EN, "per_msdc30_3_en", "msdc30_3_sel", 3), GATE_PERI2(CLK_PERI_MSDC50_0_HCLK_EN, "per_msdc50_0_h", "msdc50_0_h_sel", 4), GATE_PERI2(CLK_PERI_MSDC50_3_HCLK_EN, "per_msdc50_3_h", "msdc50_3_h_sel", 5), GATE_PERI2(CLK_PERI_MSDC30_0_QTR_EN, "per_msdc30_0_q", "axi_sel", 6), GATE_PERI2(CLK_PERI_MSDC30_3_QTR_EN, "per_msdc30_3_q", "mem_sel", 7), }; static u16 infrasys_rst_ofs[] = { 0x30, 0x34, }; static u16 pericfg_rst_ofs[] = { 0x0, 0x4, }; static const struct mtk_clk_rst_desc clk_rst_desc[] = { /* infra */ { .version = MTK_RST_SIMPLE, .rst_bank_ofs = infrasys_rst_ofs, .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs), }, /* peri */ { .version = MTK_RST_SIMPLE, .rst_bank_ofs = pericfg_rst_ofs, .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs), }, }; static const struct mtk_clk_desc topck_desc = { .clks = top_clks, .num_clks = ARRAY_SIZE(top_clks), .fixed_clks = top_fixed_clks, .num_fixed_clks = ARRAY_SIZE(top_fixed_clks), .factor_clks = top_divs, .num_factor_clks = ARRAY_SIZE(top_divs), .composite_clks = top_muxes, .num_composite_clks = ARRAY_SIZE(top_muxes), .divider_clks = top_adj_divs, .num_divider_clks = ARRAY_SIZE(top_adj_divs), .clk_lock = &mt2712_clk_lock, }; static const struct mtk_clk_desc mcu_desc = { .composite_clks = mcu_muxes, .num_composite_clks = ARRAY_SIZE(mcu_muxes), .clk_lock = &mt2712_clk_lock, }; static const struct mtk_clk_desc infra_desc = { .clks = infra_clks, .num_clks = ARRAY_SIZE(infra_clks), .rst_desc = &clk_rst_desc[0], }; static const struct mtk_clk_desc peri_desc = { .clks = peri_clks, .num_clks = ARRAY_SIZE(peri_clks), .rst_desc = &clk_rst_desc[1], }; static const struct of_device_id of_match_clk_mt2712[] = { { .compatible = "mediatek,mt2712-infracfg", .data = &infra_desc }, { .compatible = "mediatek,mt2712-mcucfg", .data = &mcu_desc }, { .compatible = "mediatek,mt2712-pericfg", .data = &peri_desc, }, { .compatible = "mediatek,mt2712-topckgen", .data = &topck_desc }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt2712); static struct platform_driver clk_mt2712_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt2712", .of_match_table = of_match_clk_mt2712, }, }; module_platform_driver(clk_mt2712_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt2712.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2014 MediaTek Inc. * Author: James Liao <[email protected]> */ #include <linux/bitops.h> #include <linux/clk-provider.h> #include <linux/err.h> #include <linux/io.h> #include <linux/mfd/syscon.h> #include <linux/module.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/slab.h> #include "clk-mtk.h" #include "clk-gate.h" #include "clk-mux.h" const struct mtk_gate_regs cg_regs_dummy = { 0, 0, 0 }; EXPORT_SYMBOL_GPL(cg_regs_dummy); static int mtk_clk_dummy_enable(struct clk_hw *hw) { return 0; } static void mtk_clk_dummy_disable(struct clk_hw *hw) { } const struct clk_ops mtk_clk_dummy_ops = { .enable = mtk_clk_dummy_enable, .disable = mtk_clk_dummy_disable, }; EXPORT_SYMBOL_GPL(mtk_clk_dummy_ops); static void mtk_init_clk_data(struct clk_hw_onecell_data *clk_data, unsigned int clk_num) { int i; clk_data->num = clk_num; for (i = 0; i < clk_num; i++) clk_data->hws[i] = ERR_PTR(-ENOENT); } struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev, unsigned int clk_num) { struct clk_hw_onecell_data *clk_data; clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, clk_num), GFP_KERNEL); if (!clk_data) return NULL; mtk_init_clk_data(clk_data, clk_num); return clk_data; } EXPORT_SYMBOL_GPL(mtk_devm_alloc_clk_data); struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num) { struct clk_hw_onecell_data *clk_data; clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL); if (!clk_data) return NULL; mtk_init_clk_data(clk_data, clk_num); return clk_data; } EXPORT_SYMBOL_GPL(mtk_alloc_clk_data); void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data) { kfree(clk_data); } EXPORT_SYMBOL_GPL(mtk_free_clk_data); int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num, struct clk_hw_onecell_data *clk_data) { int i; struct clk_hw *hw; if (!clk_data) return -ENOMEM; for (i = 0; i < num; i++) { const struct mtk_fixed_clk *rc = &clks[i]; if (!IS_ERR_OR_NULL(clk_data->hws[rc->id])) { pr_warn("Trying to register duplicate clock ID: %d\n", rc->id); continue; } hw = clk_hw_register_fixed_rate(NULL, rc->name, rc->parent, 0, rc->rate); if (IS_ERR(hw)) { pr_err("Failed to register clk %s: %pe\n", rc->name, hw); goto err; } clk_data->hws[rc->id] = hw; } return 0; err: while (--i >= 0) { const struct mtk_fixed_clk *rc = &clks[i]; if (IS_ERR_OR_NULL(clk_data->hws[rc->id])) continue; clk_hw_unregister_fixed_rate(clk_data->hws[rc->id]); clk_data->hws[rc->id] = ERR_PTR(-ENOENT); } return PTR_ERR(hw); } EXPORT_SYMBOL_GPL(mtk_clk_register_fixed_clks); void mtk_clk_unregister_fixed_clks(const struct mtk_fixed_clk *clks, int num, struct clk_hw_onecell_data *clk_data) { int i; if (!clk_data) return; for (i = num; i > 0; i--) { const struct mtk_fixed_clk *rc = &clks[i - 1]; if (IS_ERR_OR_NULL(clk_data->hws[rc->id])) continue; clk_hw_unregister_fixed_rate(clk_data->hws[rc->id]); clk_data->hws[rc->id] = ERR_PTR(-ENOENT); } } EXPORT_SYMBOL_GPL(mtk_clk_unregister_fixed_clks); int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num, struct clk_hw_onecell_data *clk_data) { int i; struct clk_hw *hw; if (!clk_data) return -ENOMEM; for (i = 0; i < num; i++) { const struct mtk_fixed_factor *ff = &clks[i]; if (!IS_ERR_OR_NULL(clk_data->hws[ff->id])) { pr_warn("Trying to register duplicate clock ID: %d\n", ff->id); continue; } hw = clk_hw_register_fixed_factor(NULL, ff->name, ff->parent_name, ff->flags, ff->mult, ff->div); if (IS_ERR(hw)) { pr_err("Failed to register clk %s: %pe\n", ff->name, hw); goto err; } clk_data->hws[ff->id] = hw; } return 0; err: while (--i >= 0) { const struct mtk_fixed_factor *ff = &clks[i]; if (IS_ERR_OR_NULL(clk_data->hws[ff->id])) continue; clk_hw_unregister_fixed_factor(clk_data->hws[ff->id]); clk_data->hws[ff->id] = ERR_PTR(-ENOENT); } return PTR_ERR(hw); } EXPORT_SYMBOL_GPL(mtk_clk_register_factors); void mtk_clk_unregister_factors(const struct mtk_fixed_factor *clks, int num, struct clk_hw_onecell_data *clk_data) { int i; if (!clk_data) return; for (i = num; i > 0; i--) { const struct mtk_fixed_factor *ff = &clks[i - 1]; if (IS_ERR_OR_NULL(clk_data->hws[ff->id])) continue; clk_hw_unregister_fixed_factor(clk_data->hws[ff->id]); clk_data->hws[ff->id] = ERR_PTR(-ENOENT); } } EXPORT_SYMBOL_GPL(mtk_clk_unregister_factors); static struct clk_hw *mtk_clk_register_composite(struct device *dev, const struct mtk_composite *mc, void __iomem *base, spinlock_t *lock) { struct clk_hw *hw; struct clk_mux *mux = NULL; struct clk_gate *gate = NULL; struct clk_divider *div = NULL; struct clk_hw *mux_hw = NULL, *gate_hw = NULL, *div_hw = NULL; const struct clk_ops *mux_ops = NULL, *gate_ops = NULL, *div_ops = NULL; const char * const *parent_names; const char *parent; int num_parents; int ret; if (mc->mux_shift >= 0) { mux = kzalloc(sizeof(*mux), GFP_KERNEL); if (!mux) return ERR_PTR(-ENOMEM); mux->reg = base + mc->mux_reg; mux->mask = BIT(mc->mux_width) - 1; mux->shift = mc->mux_shift; mux->lock = lock; mux->flags = mc->mux_flags; mux_hw = &mux->hw; mux_ops = &clk_mux_ops; parent_names = mc->parent_names; num_parents = mc->num_parents; } else { parent = mc->parent; parent_names = &parent; num_parents = 1; } if (mc->gate_shift >= 0) { gate = kzalloc(sizeof(*gate), GFP_KERNEL); if (!gate) { ret = -ENOMEM; goto err_out; } gate->reg = base + mc->gate_reg; gate->bit_idx = mc->gate_shift; gate->flags = CLK_GATE_SET_TO_DISABLE; gate->lock = lock; gate_hw = &gate->hw; gate_ops = &clk_gate_ops; } if (mc->divider_shift >= 0) { div = kzalloc(sizeof(*div), GFP_KERNEL); if (!div) { ret = -ENOMEM; goto err_out; } div->reg = base + mc->divider_reg; div->shift = mc->divider_shift; div->width = mc->divider_width; div->lock = lock; div_hw = &div->hw; div_ops = &clk_divider_ops; } hw = clk_hw_register_composite(dev, mc->name, parent_names, num_parents, mux_hw, mux_ops, div_hw, div_ops, gate_hw, gate_ops, mc->flags); if (IS_ERR(hw)) { ret = PTR_ERR(hw); goto err_out; } return hw; err_out: kfree(div); kfree(gate); kfree(mux); return ERR_PTR(ret); } static void mtk_clk_unregister_composite(struct clk_hw *hw) { struct clk_composite *composite; struct clk_mux *mux = NULL; struct clk_gate *gate = NULL; struct clk_divider *div = NULL; if (!hw) return; composite = to_clk_composite(hw); if (composite->mux_hw) mux = to_clk_mux(composite->mux_hw); if (composite->gate_hw) gate = to_clk_gate(composite->gate_hw); if (composite->rate_hw) div = to_clk_divider(composite->rate_hw); clk_hw_unregister_composite(hw); kfree(div); kfree(gate); kfree(mux); } int mtk_clk_register_composites(struct device *dev, const struct mtk_composite *mcs, int num, void __iomem *base, spinlock_t *lock, struct clk_hw_onecell_data *clk_data) { struct clk_hw *hw; int i; if (!clk_data) return -ENOMEM; for (i = 0; i < num; i++) { const struct mtk_composite *mc = &mcs[i]; if (!IS_ERR_OR_NULL(clk_data->hws[mc->id])) { pr_warn("Trying to register duplicate clock ID: %d\n", mc->id); continue; } hw = mtk_clk_register_composite(dev, mc, base, lock); if (IS_ERR(hw)) { pr_err("Failed to register clk %s: %pe\n", mc->name, hw); goto err; } clk_data->hws[mc->id] = hw; } return 0; err: while (--i >= 0) { const struct mtk_composite *mc = &mcs[i]; if (IS_ERR_OR_NULL(clk_data->hws[mcs->id])) continue; mtk_clk_unregister_composite(clk_data->hws[mc->id]); clk_data->hws[mc->id] = ERR_PTR(-ENOENT); } return PTR_ERR(hw); } EXPORT_SYMBOL_GPL(mtk_clk_register_composites); void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num, struct clk_hw_onecell_data *clk_data) { int i; if (!clk_data) return; for (i = num; i > 0; i--) { const struct mtk_composite *mc = &mcs[i - 1]; if (IS_ERR_OR_NULL(clk_data->hws[mc->id])) continue; mtk_clk_unregister_composite(clk_data->hws[mc->id]); clk_data->hws[mc->id] = ERR_PTR(-ENOENT); } } EXPORT_SYMBOL_GPL(mtk_clk_unregister_composites); int mtk_clk_register_dividers(struct device *dev, const struct mtk_clk_divider *mcds, int num, void __iomem *base, spinlock_t *lock, struct clk_hw_onecell_data *clk_data) { struct clk_hw *hw; int i; if (!clk_data) return -ENOMEM; for (i = 0; i < num; i++) { const struct mtk_clk_divider *mcd = &mcds[i]; if (!IS_ERR_OR_NULL(clk_data->hws[mcd->id])) { pr_warn("Trying to register duplicate clock ID: %d\n", mcd->id); continue; } hw = clk_hw_register_divider(dev, mcd->name, mcd->parent_name, mcd->flags, base + mcd->div_reg, mcd->div_shift, mcd->div_width, mcd->clk_divider_flags, lock); if (IS_ERR(hw)) { pr_err("Failed to register clk %s: %pe\n", mcd->name, hw); goto err; } clk_data->hws[mcd->id] = hw; } return 0; err: while (--i >= 0) { const struct mtk_clk_divider *mcd = &mcds[i]; if (IS_ERR_OR_NULL(clk_data->hws[mcd->id])) continue; clk_hw_unregister_divider(clk_data->hws[mcd->id]); clk_data->hws[mcd->id] = ERR_PTR(-ENOENT); } return PTR_ERR(hw); } EXPORT_SYMBOL_GPL(mtk_clk_register_dividers); void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num, struct clk_hw_onecell_data *clk_data) { int i; if (!clk_data) return; for (i = num; i > 0; i--) { const struct mtk_clk_divider *mcd = &mcds[i - 1]; if (IS_ERR_OR_NULL(clk_data->hws[mcd->id])) continue; clk_hw_unregister_divider(clk_data->hws[mcd->id]); clk_data->hws[mcd->id] = ERR_PTR(-ENOENT); } } EXPORT_SYMBOL_GPL(mtk_clk_unregister_dividers); static int __mtk_clk_simple_probe(struct platform_device *pdev, struct device_node *node) { const struct platform_device_id *id; const struct mtk_clk_desc *mcd; struct clk_hw_onecell_data *clk_data; void __iomem *base = NULL; int num_clks, r; mcd = device_get_match_data(&pdev->dev); if (!mcd) { /* Clock driver wasn't registered from devicetree */ id = platform_get_device_id(pdev); if (id) mcd = (const struct mtk_clk_desc *)id->driver_data; if (!mcd) return -EINVAL; } /* Composite and divider clocks needs us to pass iomem pointer */ if (mcd->composite_clks || mcd->divider_clks) { if (!mcd->shared_io) base = devm_platform_ioremap_resource(pdev, 0); else base = of_iomap(node, 0); if (IS_ERR_OR_NULL(base)) return IS_ERR(base) ? PTR_ERR(base) : -ENOMEM; } /* Calculate how many clk_hw_onecell_data entries to allocate */ num_clks = mcd->num_clks + mcd->num_composite_clks; num_clks += mcd->num_fixed_clks + mcd->num_factor_clks; num_clks += mcd->num_mux_clks + mcd->num_divider_clks; clk_data = mtk_alloc_clk_data(num_clks); if (!clk_data) { r = -ENOMEM; goto free_base; } if (mcd->fixed_clks) { r = mtk_clk_register_fixed_clks(mcd->fixed_clks, mcd->num_fixed_clks, clk_data); if (r) goto free_data; } if (mcd->factor_clks) { r = mtk_clk_register_factors(mcd->factor_clks, mcd->num_factor_clks, clk_data); if (r) goto unregister_fixed_clks; } if (mcd->mux_clks) { r = mtk_clk_register_muxes(&pdev->dev, mcd->mux_clks, mcd->num_mux_clks, node, mcd->clk_lock, clk_data); if (r) goto unregister_factors; } if (mcd->composite_clks) { /* We don't check composite_lock because it's optional */ r = mtk_clk_register_composites(&pdev->dev, mcd->composite_clks, mcd->num_composite_clks, base, mcd->clk_lock, clk_data); if (r) goto unregister_muxes; } if (mcd->divider_clks) { r = mtk_clk_register_dividers(&pdev->dev, mcd->divider_clks, mcd->num_divider_clks, base, mcd->clk_lock, clk_data); if (r) goto unregister_composites; } if (mcd->clks) { r = mtk_clk_register_gates(&pdev->dev, node, mcd->clks, mcd->num_clks, clk_data); if (r) goto unregister_dividers; } if (mcd->clk_notifier_func) { struct clk *mfg_mux = clk_data->hws[mcd->mfg_clk_idx]->clk; r = mcd->clk_notifier_func(&pdev->dev, mfg_mux); if (r) goto unregister_clks; } r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data); if (r) goto unregister_clks; platform_set_drvdata(pdev, clk_data); if (mcd->rst_desc) { r = mtk_register_reset_controller_with_dev(&pdev->dev, mcd->rst_desc); if (r) goto unregister_clks; } return r; unregister_clks: if (mcd->clks) mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data); unregister_dividers: if (mcd->divider_clks) mtk_clk_unregister_dividers(mcd->divider_clks, mcd->num_divider_clks, clk_data); unregister_composites: if (mcd->composite_clks) mtk_clk_unregister_composites(mcd->composite_clks, mcd->num_composite_clks, clk_data); unregister_muxes: if (mcd->mux_clks) mtk_clk_unregister_muxes(mcd->mux_clks, mcd->num_mux_clks, clk_data); unregister_factors: if (mcd->factor_clks) mtk_clk_unregister_factors(mcd->factor_clks, mcd->num_factor_clks, clk_data); unregister_fixed_clks: if (mcd->fixed_clks) mtk_clk_unregister_fixed_clks(mcd->fixed_clks, mcd->num_fixed_clks, clk_data); free_data: mtk_free_clk_data(clk_data); free_base: if (mcd->shared_io && base) iounmap(base); return r; } static void __mtk_clk_simple_remove(struct platform_device *pdev, struct device_node *node) { struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev); const struct mtk_clk_desc *mcd = device_get_match_data(&pdev->dev); of_clk_del_provider(node); if (mcd->clks) mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data); if (mcd->divider_clks) mtk_clk_unregister_dividers(mcd->divider_clks, mcd->num_divider_clks, clk_data); if (mcd->composite_clks) mtk_clk_unregister_composites(mcd->composite_clks, mcd->num_composite_clks, clk_data); if (mcd->mux_clks) mtk_clk_unregister_muxes(mcd->mux_clks, mcd->num_mux_clks, clk_data); if (mcd->factor_clks) mtk_clk_unregister_factors(mcd->factor_clks, mcd->num_factor_clks, clk_data); if (mcd->fixed_clks) mtk_clk_unregister_fixed_clks(mcd->fixed_clks, mcd->num_fixed_clks, clk_data); mtk_free_clk_data(clk_data); } int mtk_clk_pdev_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *node = dev->parent->of_node; return __mtk_clk_simple_probe(pdev, node); } EXPORT_SYMBOL_GPL(mtk_clk_pdev_probe); int mtk_clk_simple_probe(struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; return __mtk_clk_simple_probe(pdev, node); } EXPORT_SYMBOL_GPL(mtk_clk_simple_probe); void mtk_clk_pdev_remove(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *node = dev->parent->of_node; __mtk_clk_simple_remove(pdev, node); } EXPORT_SYMBOL_GPL(mtk_clk_pdev_remove); void mtk_clk_simple_remove(struct platform_device *pdev) { __mtk_clk_simple_remove(pdev, pdev->dev.of_node); } EXPORT_SYMBOL_GPL(mtk_clk_simple_remove); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mtk.c
// SPDX-License-Identifier: GPL-2.0 // // Copyright (c) 2018 MediaTek Inc. // Author: Weiyi Lu <[email protected]> #include <linux/delay.h> #include <linux/mfd/syscon.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include <linux/slab.h> #include "clk-gate.h" #include "clk-mtk.h" #include "clk-mux.h" #include <dt-bindings/clock/mt8183-clk.h> static DEFINE_SPINLOCK(mt8183_clk_lock); static const struct mtk_fixed_clk top_fixed_clks[] = { FIXED_CLK(CLK_TOP_CLK26M, "f_f26m_ck", "clk26m", 26000000), FIXED_CLK(CLK_TOP_ULPOSC, "osc", NULL, 250000), FIXED_CLK(CLK_TOP_UNIVP_192M, "univpll_192m", "univpll", 192000000), }; /* * To retain compatibility with older devicetrees, we keep CLK_TOP_CLK13M * valid, but renamed from "clk13m" (defined as fixed clock in the new * devicetrees) to "clk26m_d2", satisfying the older clock assignments. * This means that on new devicetrees "clk26m_d2" is unused. */ static const struct mtk_fixed_factor top_divs[] = { FACTOR(CLK_TOP_CLK13M, "clk26m_d2", "clk26m", 1, 2), FACTOR(CLK_TOP_F26M_CK_D2, "csw_f26m_ck_d2", "clk26m", 1, 2), FACTOR_FLAGS(CLK_TOP_SYSPLL_CK, "syspll_ck", "mainpll", 1, 1, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D2, "syspll_d2", "syspll_ck", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D2_D2, "syspll_d2_d2", "syspll_d2", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D2_D4, "syspll_d2_d4", "syspll_d2", 1, 4, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D2_D8, "syspll_d2_d8", "syspll_d2", 1, 8, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D2_D16, "syspll_d2_d16", "syspll_d2", 1, 16, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1, 3, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D3_D2, "syspll_d3_d2", "syspll_d3", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D3_D4, "syspll_d3_d4", "syspll_d3", 1, 4, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D3_D8, "syspll_d3_d8", "syspll_d3", 1, 8, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D5_D2, "syspll_d5_d2", "syspll_d5", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D5_D4, "syspll_d5_d4", "syspll_d5", 1, 4, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1, 7, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D7_D2, "syspll_d7_d2", "syspll_d7", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_SYSPLL_D7_D4, "syspll_d7_d4", "syspll_d7", 1, 4, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_CK, "univpll_ck", "univpll", 1, 1, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll_ck", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D2_D2, "univpll_d2_d2", "univpll_d2", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D2_D4, "univpll_d2_d4", "univpll_d2", 1, 4, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D2_D8, "univpll_d2_d8", "univpll_d2", 1, 8, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D3_D2, "univpll_d3_d2", "univpll_d3", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D3_D4, "univpll_d3_d4", "univpll_d3", 1, 4, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D3_D8, "univpll_d3_d8", "univpll_d3", 1, 8, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D5_D2, "univpll_d5_d2", "univpll_d5", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D5_D4, "univpll_d5_d4", "univpll_d5", 1, 4, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D5_D8, "univpll_d5_d8", "univpll_d5", 1, 8, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7, 0), FACTOR_FLAGS(CLK_TOP_UNIVP_192M_CK, "univ_192m_ck", "univpll_192m", 1, 1, 0), FACTOR_FLAGS(CLK_TOP_UNIVP_192M_D2, "univ_192m_d2", "univ_192m_ck", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_UNIVP_192M_D4, "univ_192m_d4", "univ_192m_ck", 1, 4, 0), FACTOR_FLAGS(CLK_TOP_UNIVP_192M_D8, "univ_192m_d8", "univ_192m_ck", 1, 8, 0), FACTOR_FLAGS(CLK_TOP_UNIVP_192M_D16, "univ_192m_d16", "univ_192m_ck", 1, 16, 0), FACTOR_FLAGS(CLK_TOP_UNIVP_192M_D32, "univ_192m_d32", "univ_192m_ck", 1, 32, 0), FACTOR(CLK_TOP_APLL1_CK, "apll1_ck", "apll1", 1, 1), FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1", 1, 2), FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1", 1, 4), FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1", 1, 8), FACTOR(CLK_TOP_APLL2_CK, "apll2_ck", "apll2", 1, 1), FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2", 1, 2), FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2", 1, 4), FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2", 1, 8), FACTOR(CLK_TOP_TVDPLL_CK, "tvdpll_ck", "tvdpll", 1, 1), FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1, 2), FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll", 1, 4), FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll", 1, 8), FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll", 1, 16), FACTOR(CLK_TOP_MMPLL_CK, "mmpll_ck", "mmpll", 1, 1), FACTOR(CLK_TOP_MMPLL_D4, "mmpll_d4", "mmpll", 1, 4), FACTOR(CLK_TOP_MMPLL_D4_D2, "mmpll_d4_d2", "mmpll_d4", 1, 2), FACTOR(CLK_TOP_MMPLL_D4_D4, "mmpll_d4_d4", "mmpll_d4", 1, 4), FACTOR(CLK_TOP_MMPLL_D5, "mmpll_d5", "mmpll", 1, 5), FACTOR(CLK_TOP_MMPLL_D5_D2, "mmpll_d5_d2", "mmpll_d5", 1, 2), FACTOR(CLK_TOP_MMPLL_D5_D4, "mmpll_d5_d4", "mmpll_d5", 1, 4), FACTOR(CLK_TOP_MMPLL_D6, "mmpll_d6", "mmpll", 1, 6), FACTOR(CLK_TOP_MMPLL_D7, "mmpll_d7", "mmpll", 1, 7), FACTOR(CLK_TOP_MFGPLL_CK, "mfgpll_ck", "mfgpll", 1, 1), FACTOR(CLK_TOP_MSDCPLL_CK, "msdcpll_ck", "msdcpll", 1, 1), FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1, 2), FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll", 1, 4), FACTOR(CLK_TOP_MSDCPLL_D8, "msdcpll_d8", "msdcpll", 1, 8), FACTOR(CLK_TOP_MSDCPLL_D16, "msdcpll_d16", "msdcpll", 1, 16), FACTOR(CLK_TOP_AD_OSC_CK, "ad_osc_ck", "osc", 1, 1), FACTOR(CLK_TOP_OSC_D2, "osc_d2", "osc", 1, 2), FACTOR(CLK_TOP_OSC_D4, "osc_d4", "osc", 1, 4), FACTOR(CLK_TOP_OSC_D8, "osc_d8", "osc", 1, 8), FACTOR(CLK_TOP_OSC_D16, "osc_d16", "osc", 1, 16), FACTOR_FLAGS(CLK_TOP_UNIVPLL, "univpll", "univ2pll", 1, 2, 0), FACTOR_FLAGS(CLK_TOP_UNIVPLL_D3_D16, "univpll_d3_d16", "univpll_d3", 1, 16, 0), }; static const char * const axi_parents[] = { "clk26m", "syspll_d2_d4", "syspll_d7", "osc_d4" }; static const char * const mm_parents[] = { "clk26m", "mmpll_d7", "syspll_d3", "univpll_d2_d2", "syspll_d2_d2", "syspll_d3_d2" }; static const char * const img_parents[] = { "clk26m", "mmpll_d6", "univpll_d3", "syspll_d3", "univpll_d2_d2", "syspll_d2_d2", "univpll_d3_d2", "syspll_d3_d2" }; static const char * const cam_parents[] = { "clk26m", "syspll_d2", "mmpll_d6", "syspll_d3", "mmpll_d7", "univpll_d3", "univpll_d2_d2", "syspll_d2_d2", "syspll_d3_d2", "univpll_d3_d2" }; static const char * const dsp_parents[] = { "clk26m", "mmpll_d6", "mmpll_d7", "univpll_d3", "syspll_d3", "univpll_d2_d2", "syspll_d2_d2", "univpll_d3_d2", "syspll_d3_d2" }; static const char * const dsp1_parents[] = { "clk26m", "mmpll_d6", "mmpll_d7", "univpll_d3", "syspll_d3", "univpll_d2_d2", "syspll_d2_d2", "univpll_d3_d2", "syspll_d3_d2" }; static const char * const dsp2_parents[] = { "clk26m", "mmpll_d6", "mmpll_d7", "univpll_d3", "syspll_d3", "univpll_d2_d2", "syspll_d2_d2", "univpll_d3_d2", "syspll_d3_d2" }; static const char * const ipu_if_parents[] = { "clk26m", "mmpll_d6", "mmpll_d7", "univpll_d3", "syspll_d3", "univpll_d2_d2", "syspll_d2_d2", "univpll_d3_d2", "syspll_d3_d2" }; static const char * const mfg_parents[] = { "clk26m", "mfgpll_ck", "univpll_d3", "syspll_d3" }; static const char * const f52m_mfg_parents[] = { "clk26m", "univpll_d3_d2", "univpll_d3_d4", "univpll_d3_d8" }; static const char * const camtg_parents[] = { "clk26m", "univ_192m_d8", "univpll_d3_d8", "univ_192m_d4", "univpll_d3_d16", "csw_f26m_ck_d2", "univ_192m_d16", "univ_192m_d32" }; static const char * const camtg2_parents[] = { "clk26m", "univ_192m_d8", "univpll_d3_d8", "univ_192m_d4", "univpll_d3_d16", "csw_f26m_ck_d2", "univ_192m_d16", "univ_192m_d32" }; static const char * const camtg3_parents[] = { "clk26m", "univ_192m_d8", "univpll_d3_d8", "univ_192m_d4", "univpll_d3_d16", "csw_f26m_ck_d2", "univ_192m_d16", "univ_192m_d32" }; static const char * const camtg4_parents[] = { "clk26m", "univ_192m_d8", "univpll_d3_d8", "univ_192m_d4", "univpll_d3_d16", "csw_f26m_ck_d2", "univ_192m_d16", "univ_192m_d32" }; static const char * const uart_parents[] = { "clk26m", "univpll_d3_d8" }; static const char * const spi_parents[] = { "clk26m", "syspll_d5_d2", "syspll_d3_d4", "msdcpll_d4" }; static const char * const msdc50_hclk_parents[] = { "clk26m", "syspll_d2_d2", "syspll_d3_d2" }; static const char * const msdc50_0_parents[] = { "clk26m", "msdcpll_ck", "msdcpll_d2", "univpll_d2_d4", "syspll_d3_d2", "univpll_d2_d2" }; static const char * const msdc30_1_parents[] = { "clk26m", "univpll_d3_d2", "syspll_d3_d2", "syspll_d7", "msdcpll_d2" }; static const char * const msdc30_2_parents[] = { "clk26m", "univpll_d3_d2", "syspll_d3_d2", "syspll_d7", "msdcpll_d2" }; static const char * const audio_parents[] = { "clk26m", "syspll_d5_d4", "syspll_d7_d4", "syspll_d2_d16" }; static const char * const aud_intbus_parents[] = { "clk26m", "syspll_d2_d4", "syspll_d7_d2" }; static const char * const pmicspi_parents[] = { "clk26m", "syspll_d2_d8", "osc_d8" }; static const char * const fpwrap_ulposc_parents[] = { "clk26m", "osc_d16", "osc_d4", "osc_d8" }; static const char * const atb_parents[] = { "clk26m", "syspll_d2_d2", "syspll_d5" }; static const char * const sspm_parents[] = { "clk26m", "univpll_d2_d4", "syspll_d2_d2", "univpll_d2_d2", "syspll_d3" }; static const char * const dpi0_parents[] = { "clk26m", "tvdpll_d2", "tvdpll_d4", "tvdpll_d8", "tvdpll_d16", "univpll_d5_d2", "univpll_d3_d4", "syspll_d3_d4", "univpll_d3_d8" }; static const char * const scam_parents[] = { "clk26m", "syspll_d5_d2" }; static const char * const disppwm_parents[] = { "clk26m", "univpll_d3_d4", "osc_d2", "osc_d4", "osc_d16" }; static const char * const usb_top_parents[] = { "clk26m", "univpll_d5_d4", "univpll_d3_d4", "univpll_d5_d2" }; static const char * const ssusb_top_xhci_parents[] = { "clk26m", "univpll_d5_d4", "univpll_d3_d4", "univpll_d5_d2" }; static const char * const spm_parents[] = { "clk26m", "syspll_d2_d8" }; static const char * const i2c_parents[] = { "clk26m", "syspll_d2_d8", "univpll_d5_d2" }; static const char * const scp_parents[] = { "clk26m", "univpll_d2_d8", "syspll_d5", "syspll_d2_d2", "univpll_d2_d2", "syspll_d3", "univpll_d3" }; static const char * const seninf_parents[] = { "clk26m", "univpll_d2_d2", "univpll_d3_d2", "univpll_d2_d4" }; static const char * const dxcc_parents[] = { "clk26m", "syspll_d2_d2", "syspll_d2_d4", "syspll_d2_d8" }; static const char * const aud_engen1_parents[] = { "clk26m", "apll1_d2", "apll1_d4", "apll1_d8" }; static const char * const aud_engen2_parents[] = { "clk26m", "apll2_d2", "apll2_d4", "apll2_d8" }; static const char * const faes_ufsfde_parents[] = { "clk26m", "syspll_d2", "syspll_d2_d2", "syspll_d3", "syspll_d2_d4", "univpll_d3" }; static const char * const fufs_parents[] = { "clk26m", "syspll_d2_d4", "syspll_d2_d8", "syspll_d2_d16" }; static const char * const aud_1_parents[] = { "clk26m", "apll1_ck" }; static const char * const aud_2_parents[] = { "clk26m", "apll2_ck" }; /* * CRITICAL CLOCK: * axi_sel is the main bus clock of whole SOC. * spm_sel is the clock of the always-on co-processor. */ static const struct mtk_mux top_muxes[] = { /* CLK_CFG_0 */ MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_AXI, "axi_sel", axi_parents, 0x40, 0x44, 0x48, 0, 2, 7, 0x004, 0, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_MM, "mm_sel", mm_parents, 0x40, 0x44, 0x48, 8, 3, 15, 0x004, 1), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_IMG, "img_sel", img_parents, 0x40, 0x44, 0x48, 16, 3, 23, 0x004, 2), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAM, "cam_sel", cam_parents, 0x40, 0x44, 0x48, 24, 4, 31, 0x004, 3), /* CLK_CFG_1 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DSP, "dsp_sel", dsp_parents, 0x50, 0x54, 0x58, 0, 4, 7, 0x004, 4), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DSP1, "dsp1_sel", dsp1_parents, 0x50, 0x54, 0x58, 8, 4, 15, 0x004, 5), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DSP2, "dsp2_sel", dsp2_parents, 0x50, 0x54, 0x58, 16, 4, 23, 0x004, 6), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_IPU_IF, "ipu_if_sel", ipu_if_parents, 0x50, 0x54, 0x58, 24, 4, 31, 0x004, 7), /* CLK_CFG_2 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_MFG, "mfg_sel", mfg_parents, 0x60, 0x64, 0x68, 0, 2, 7, 0x004, 8), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_F52M_MFG, "f52m_mfg_sel", f52m_mfg_parents, 0x60, 0x64, 0x68, 8, 2, 15, 0x004, 9), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAMTG, "camtg_sel", camtg_parents, 0x60, 0x64, 0x68, 16, 3, 23, 0x004, 10), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAMTG2, "camtg2_sel", camtg2_parents, 0x60, 0x64, 0x68, 24, 3, 31, 0x004, 11), /* CLK_CFG_3 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAMTG3, "camtg3_sel", camtg3_parents, 0x70, 0x74, 0x78, 0, 3, 7, 0x004, 12), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAMTG4, "camtg4_sel", camtg4_parents, 0x70, 0x74, 0x78, 8, 3, 15, 0x004, 13), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_UART, "uart_sel", uart_parents, 0x70, 0x74, 0x78, 16, 1, 23, 0x004, 14), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SPI, "spi_sel", spi_parents, 0x70, 0x74, 0x78, 24, 2, 31, 0x004, 15), /* CLK_CFG_4 */ MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_MSDC50_0_HCLK, "msdc50_hclk_sel", msdc50_hclk_parents, 0x80, 0x84, 0x88, 0, 2, 7, 0x004, 16, 0), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_MSDC50_0, "msdc50_0_sel", msdc50_0_parents, 0x80, 0x84, 0x88, 8, 3, 15, 0x004, 17, 0), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_MSDC30_1, "msdc30_1_sel", msdc30_1_parents, 0x80, 0x84, 0x88, 16, 3, 23, 0x004, 18, 0), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_MSDC30_2, "msdc30_2_sel", msdc30_2_parents, 0x80, 0x84, 0x88, 24, 3, 31, 0x004, 19, 0), /* CLK_CFG_5 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUDIO, "audio_sel", audio_parents, 0x90, 0x94, 0x98, 0, 2, 7, 0x004, 20), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_INTBUS, "aud_intbus_sel", aud_intbus_parents, 0x90, 0x94, 0x98, 8, 2, 15, 0x004, 21), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_PMICSPI, "pmicspi_sel", pmicspi_parents, 0x90, 0x94, 0x98, 16, 2, 23, 0x004, 22), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_FPWRAP_ULPOSC, "fpwrap_ulposc_sel", fpwrap_ulposc_parents, 0x90, 0x94, 0x98, 24, 2, 31, 0x004, 23), /* CLK_CFG_6 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_ATB, "atb_sel", atb_parents, 0xa0, 0xa4, 0xa8, 0, 2, 7, 0x004, 24), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_SSPM, "sspm_sel", sspm_parents, 0xa0, 0xa4, 0xa8, 8, 3, 15, 0x004, 25, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DPI0, "dpi0_sel", dpi0_parents, 0xa0, 0xa4, 0xa8, 16, 4, 23, 0x004, 26), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SCAM, "scam_sel", scam_parents, 0xa0, 0xa4, 0xa8, 24, 1, 31, 0x004, 27), /* CLK_CFG_7 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DISP_PWM, "disppwm_sel", disppwm_parents, 0xb0, 0xb4, 0xb8, 0, 3, 7, 0x004, 28), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_USB_TOP, "usb_top_sel", usb_top_parents, 0xb0, 0xb4, 0xb8, 8, 2, 15, 0x004, 29), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SSUSB_TOP_XHCI, "ssusb_top_xhci_sel", ssusb_top_xhci_parents, 0xb0, 0xb4, 0xb8, 16, 2, 23, 0x004, 30), MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_SPM, "spm_sel", spm_parents, 0xb0, 0xb4, 0xb8, 24, 1, 31, 0x008, 0, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), /* CLK_CFG_8 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_I2C, "i2c_sel", i2c_parents, 0xc0, 0xc4, 0xc8, 0, 2, 7, 0x008, 1), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SCP, "scp_sel", scp_parents, 0xc0, 0xc4, 0xc8, 8, 3, 15, 0x008, 2), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SENINF, "seninf_sel", seninf_parents, 0xc0, 0xc4, 0xc8, 16, 2, 23, 0x008, 3), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DXCC, "dxcc_sel", dxcc_parents, 0xc0, 0xc4, 0xc8, 24, 2, 31, 0x008, 4), /* CLK_CFG_9 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_ENG1, "aud_eng1_sel", aud_engen1_parents, 0xd0, 0xd4, 0xd8, 0, 2, 7, 0x008, 5), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_ENG2, "aud_eng2_sel", aud_engen2_parents, 0xd0, 0xd4, 0xd8, 8, 2, 15, 0x008, 6), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_FAES_UFSFDE, "faes_ufsfde_sel", faes_ufsfde_parents, 0xd0, 0xd4, 0xd8, 16, 3, 23, 0x008, 7), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_FUFS, "fufs_sel", fufs_parents, 0xd0, 0xd4, 0xd8, 24, 2, 31, 0x008, 8), /* CLK_CFG_10 */ MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_1, "aud_1_sel", aud_1_parents, 0xe0, 0xe4, 0xe8, 0, 1, 7, 0x008, 9), MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_2, "aud_2_sel", aud_2_parents, 0xe0, 0xe4, 0xe8, 8, 1, 15, 0x008, 10), }; static const char * const apll_i2s0_parents[] = { "aud_1_sel", "aud_2_sel" }; static const char * const apll_i2s1_parents[] = { "aud_1_sel", "aud_2_sel" }; static const char * const apll_i2s2_parents[] = { "aud_1_sel", "aud_2_sel" }; static const char * const apll_i2s3_parents[] = { "aud_1_sel", "aud_2_sel" }; static const char * const apll_i2s4_parents[] = { "aud_1_sel", "aud_2_sel" }; static const char * const apll_i2s5_parents[] = { "aud_1_sel", "aud_2_sel" }; static const char * const mcu_mp0_parents[] = { "clk26m", "armpll_ll", "armpll_div_pll1", "armpll_div_pll2" }; static const char * const mcu_mp2_parents[] = { "clk26m", "armpll_l", "armpll_div_pll1", "armpll_div_pll2" }; static const char * const mcu_bus_parents[] = { "clk26m", "ccipll", "armpll_div_pll1", "armpll_div_pll2" }; static struct mtk_composite mcu_muxes[] = { /* mp0_pll_divider_cfg */ MUX(CLK_MCU_MP0_SEL, "mcu_mp0_sel", mcu_mp0_parents, 0x7A0, 9, 2), /* mp2_pll_divider_cfg */ MUX(CLK_MCU_MP2_SEL, "mcu_mp2_sel", mcu_mp2_parents, 0x7A8, 9, 2), /* bus_pll_divider_cfg */ MUX(CLK_MCU_BUS_SEL, "mcu_bus_sel", mcu_bus_parents, 0x7C0, 9, 2), }; static struct mtk_composite top_aud_comp[] = { MUX(CLK_TOP_MUX_APLL_I2S0, "apll_i2s0_sel", apll_i2s0_parents, 0x320, 8, 1), MUX(CLK_TOP_MUX_APLL_I2S1, "apll_i2s1_sel", apll_i2s1_parents, 0x320, 9, 1), MUX(CLK_TOP_MUX_APLL_I2S2, "apll_i2s2_sel", apll_i2s2_parents, 0x320, 10, 1), MUX(CLK_TOP_MUX_APLL_I2S3, "apll_i2s3_sel", apll_i2s3_parents, 0x320, 11, 1), MUX(CLK_TOP_MUX_APLL_I2S4, "apll_i2s4_sel", apll_i2s4_parents, 0x320, 12, 1), MUX(CLK_TOP_MUX_APLL_I2S5, "apll_i2s5_sel", apll_i2s5_parents, 0x328, 20, 1), DIV_GATE(CLK_TOP_APLL12_DIV0, "apll12_div0", "apll_i2s0_sel", 0x320, 2, 0x324, 8, 0), DIV_GATE(CLK_TOP_APLL12_DIV1, "apll12_div1", "apll_i2s1_sel", 0x320, 3, 0x324, 8, 8), DIV_GATE(CLK_TOP_APLL12_DIV2, "apll12_div2", "apll_i2s2_sel", 0x320, 4, 0x324, 8, 16), DIV_GATE(CLK_TOP_APLL12_DIV3, "apll12_div3", "apll_i2s3_sel", 0x320, 5, 0x324, 8, 24), DIV_GATE(CLK_TOP_APLL12_DIV4, "apll12_div4", "apll_i2s4_sel", 0x320, 6, 0x328, 8, 0), DIV_GATE(CLK_TOP_APLL12_DIVB, "apll12_divb", "apll12_div4", 0x320, 7, 0x328, 8, 8), }; static const struct mtk_gate_regs top_cg_regs = { .set_ofs = 0x104, .clr_ofs = 0x104, .sta_ofs = 0x104, }; #define GATE_TOP(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &top_cg_regs, _shift, \ &mtk_clk_gate_ops_no_setclr_inv) static const struct mtk_gate top_clks[] = { /* TOP */ GATE_TOP(CLK_TOP_ARMPLL_DIV_PLL1, "armpll_div_pll1", "mainpll", 4), GATE_TOP(CLK_TOP_ARMPLL_DIV_PLL2, "armpll_div_pll2", "univpll", 5), }; static const struct mtk_gate_regs infra0_cg_regs = { .set_ofs = 0x80, .clr_ofs = 0x84, .sta_ofs = 0x90, }; static const struct mtk_gate_regs infra1_cg_regs = { .set_ofs = 0x88, .clr_ofs = 0x8c, .sta_ofs = 0x94, }; static const struct mtk_gate_regs infra2_cg_regs = { .set_ofs = 0xa4, .clr_ofs = 0xa8, .sta_ofs = 0xac, }; static const struct mtk_gate_regs infra3_cg_regs = { .set_ofs = 0xc0, .clr_ofs = 0xc4, .sta_ofs = 0xc8, }; #define GATE_INFRA0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &infra0_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr) #define GATE_INFRA1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &infra1_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr) #define GATE_INFRA2(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &infra2_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr) #define GATE_INFRA2_FLAGS(_id, _name, _parent, _shift, _flag) \ GATE_MTK_FLAGS(_id, _name, _parent, &infra2_cg_regs, \ _shift, &mtk_clk_gate_ops_setclr, _flag) #define GATE_INFRA3(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &infra3_cg_regs, _shift, \ &mtk_clk_gate_ops_setclr) #define GATE_INFRA3_FLAGS(_id, _name, _parent, _shift, _flag) \ GATE_MTK_FLAGS(_id, _name, _parent, &infra3_cg_regs, \ _shift, &mtk_clk_gate_ops_setclr, _flag) static const struct mtk_gate infra_clks[] = { /* INFRA0 */ GATE_INFRA0(CLK_INFRA_PMIC_TMR, "infra_pmic_tmr", "axi_sel", 0), GATE_INFRA0(CLK_INFRA_PMIC_AP, "infra_pmic_ap", "axi_sel", 1), GATE_INFRA0(CLK_INFRA_PMIC_MD, "infra_pmic_md", "axi_sel", 2), GATE_INFRA0(CLK_INFRA_PMIC_CONN, "infra_pmic_conn", "axi_sel", 3), GATE_INFRA0(CLK_INFRA_SCPSYS, "infra_scp", "scp_sel", 4), GATE_INFRA0(CLK_INFRA_SEJ, "infra_sej", "f_f26m_ck", 5), GATE_INFRA0(CLK_INFRA_APXGPT, "infra_apxgpt", "axi_sel", 6), GATE_INFRA0(CLK_INFRA_ICUSB, "infra_icusb", "axi_sel", 8), GATE_INFRA0(CLK_INFRA_GCE, "infra_gce", "axi_sel", 9), GATE_INFRA0(CLK_INFRA_THERM, "infra_therm", "axi_sel", 10), GATE_INFRA0(CLK_INFRA_I2C0, "infra_i2c0", "i2c_sel", 11), GATE_INFRA0(CLK_INFRA_I2C1, "infra_i2c1", "i2c_sel", 12), GATE_INFRA0(CLK_INFRA_I2C2, "infra_i2c2", "i2c_sel", 13), GATE_INFRA0(CLK_INFRA_I2C3, "infra_i2c3", "i2c_sel", 14), GATE_INFRA0(CLK_INFRA_PWM_HCLK, "infra_pwm_hclk", "axi_sel", 15), GATE_INFRA0(CLK_INFRA_PWM1, "infra_pwm1", "i2c_sel", 16), GATE_INFRA0(CLK_INFRA_PWM2, "infra_pwm2", "i2c_sel", 17), GATE_INFRA0(CLK_INFRA_PWM3, "infra_pwm3", "i2c_sel", 18), GATE_INFRA0(CLK_INFRA_PWM4, "infra_pwm4", "i2c_sel", 19), GATE_INFRA0(CLK_INFRA_PWM, "infra_pwm", "i2c_sel", 21), GATE_INFRA0(CLK_INFRA_UART0, "infra_uart0", "uart_sel", 22), GATE_INFRA0(CLK_INFRA_UART1, "infra_uart1", "uart_sel", 23), GATE_INFRA0(CLK_INFRA_UART2, "infra_uart2", "uart_sel", 24), GATE_INFRA0(CLK_INFRA_UART3, "infra_uart3", "uart_sel", 25), GATE_INFRA0(CLK_INFRA_GCE_26M, "infra_gce_26m", "axi_sel", 27), GATE_INFRA0(CLK_INFRA_CQ_DMA_FPC, "infra_cqdma_fpc", "axi_sel", 28), GATE_INFRA0(CLK_INFRA_BTIF, "infra_btif", "axi_sel", 31), /* INFRA1 */ GATE_INFRA1(CLK_INFRA_SPI0, "infra_spi0", "spi_sel", 1), GATE_INFRA1(CLK_INFRA_MSDC0, "infra_msdc0", "msdc50_hclk_sel", 2), GATE_INFRA1(CLK_INFRA_MSDC1, "infra_msdc1", "axi_sel", 4), GATE_INFRA1(CLK_INFRA_MSDC2, "infra_msdc2", "axi_sel", 5), GATE_INFRA1(CLK_INFRA_MSDC0_SCK, "infra_msdc0_sck", "msdc50_0_sel", 6), GATE_INFRA1(CLK_INFRA_DVFSRC, "infra_dvfsrc", "f_f26m_ck", 7), GATE_INFRA1(CLK_INFRA_GCPU, "infra_gcpu", "axi_sel", 8), GATE_INFRA1(CLK_INFRA_TRNG, "infra_trng", "axi_sel", 9), GATE_INFRA1(CLK_INFRA_AUXADC, "infra_auxadc", "f_f26m_ck", 10), GATE_INFRA1(CLK_INFRA_CPUM, "infra_cpum", "axi_sel", 11), GATE_INFRA1(CLK_INFRA_CCIF1_AP, "infra_ccif1_ap", "axi_sel", 12), GATE_INFRA1(CLK_INFRA_CCIF1_MD, "infra_ccif1_md", "axi_sel", 13), GATE_INFRA1(CLK_INFRA_AUXADC_MD, "infra_auxadc_md", "f_f26m_ck", 14), GATE_INFRA1(CLK_INFRA_MSDC1_SCK, "infra_msdc1_sck", "msdc30_1_sel", 16), GATE_INFRA1(CLK_INFRA_MSDC2_SCK, "infra_msdc2_sck", "msdc30_2_sel", 17), GATE_INFRA1(CLK_INFRA_AP_DMA, "infra_apdma", "axi_sel", 18), GATE_INFRA1(CLK_INFRA_XIU, "infra_xiu", "axi_sel", 19), GATE_INFRA1(CLK_INFRA_DEVICE_APC, "infra_device_apc", "axi_sel", 20), GATE_INFRA1(CLK_INFRA_CCIF_AP, "infra_ccif_ap", "axi_sel", 23), GATE_INFRA1(CLK_INFRA_DEBUGSYS, "infra_debugsys", "axi_sel", 24), GATE_INFRA1(CLK_INFRA_AUDIO, "infra_audio", "axi_sel", 25), GATE_INFRA1(CLK_INFRA_CCIF_MD, "infra_ccif_md", "axi_sel", 26), GATE_INFRA1(CLK_INFRA_DXCC_SEC_CORE, "infra_dxcc_sec_core", "dxcc_sel", 27), GATE_INFRA1(CLK_INFRA_DXCC_AO, "infra_dxcc_ao", "dxcc_sel", 28), GATE_INFRA1(CLK_INFRA_DEVMPU_BCLK, "infra_devmpu_bclk", "axi_sel", 30), GATE_INFRA1(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m", "f_f26m_ck", 31), /* INFRA2 */ GATE_INFRA2(CLK_INFRA_IRTX, "infra_irtx", "f_f26m_ck", 0), GATE_INFRA2(CLK_INFRA_USB, "infra_usb", "usb_top_sel", 1), GATE_INFRA2(CLK_INFRA_DISP_PWM, "infra_disppwm", "axi_sel", 2), GATE_INFRA2(CLK_INFRA_CLDMA_BCLK, "infra_cldma_bclk", "axi_sel", 3), GATE_INFRA2(CLK_INFRA_AUDIO_26M_BCLK, "infra_audio_26m_bclk", "f_f26m_ck", 4), GATE_INFRA2(CLK_INFRA_SPI1, "infra_spi1", "spi_sel", 6), GATE_INFRA2(CLK_INFRA_I2C4, "infra_i2c4", "i2c_sel", 7), GATE_INFRA2(CLK_INFRA_MODEM_TEMP_SHARE, "infra_md_tmp_share", "f_f26m_ck", 8), GATE_INFRA2(CLK_INFRA_SPI2, "infra_spi2", "spi_sel", 9), GATE_INFRA2(CLK_INFRA_SPI3, "infra_spi3", "spi_sel", 10), GATE_INFRA2(CLK_INFRA_UNIPRO_SCK, "infra_unipro_sck", "ssusb_top_xhci_sel", 11), GATE_INFRA2(CLK_INFRA_UNIPRO_TICK, "infra_unipro_tick", "fufs_sel", 12), GATE_INFRA2(CLK_INFRA_UFS_MP_SAP_BCLK, "infra_ufs_mp_sap_bck", "fufs_sel", 13), GATE_INFRA2(CLK_INFRA_MD32_BCLK, "infra_md32_bclk", "axi_sel", 14), /* infra_sspm is main clock in co-processor, should not be closed in Linux. */ GATE_INFRA2_FLAGS(CLK_INFRA_SSPM, "infra_sspm", "sspm_sel", 15, CLK_IS_CRITICAL), GATE_INFRA2(CLK_INFRA_UNIPRO_MBIST, "infra_unipro_mbist", "axi_sel", 16), /* infra_sspm_bus_hclk is main clock in co-processor, should not be closed in Linux. */ GATE_INFRA2_FLAGS(CLK_INFRA_SSPM_BUS_HCLK, "infra_sspm_bus_hclk", "axi_sel", 17, CLK_IS_CRITICAL), GATE_INFRA2(CLK_INFRA_I2C5, "infra_i2c5", "i2c_sel", 18), GATE_INFRA2(CLK_INFRA_I2C5_ARBITER, "infra_i2c5_arbiter", "i2c_sel", 19), GATE_INFRA2(CLK_INFRA_I2C5_IMM, "infra_i2c5_imm", "i2c_sel", 20), GATE_INFRA2(CLK_INFRA_I2C1_ARBITER, "infra_i2c1_arbiter", "i2c_sel", 21), GATE_INFRA2(CLK_INFRA_I2C1_IMM, "infra_i2c1_imm", "i2c_sel", 22), GATE_INFRA2(CLK_INFRA_I2C2_ARBITER, "infra_i2c2_arbiter", "i2c_sel", 23), GATE_INFRA2(CLK_INFRA_I2C2_IMM, "infra_i2c2_imm", "i2c_sel", 24), GATE_INFRA2(CLK_INFRA_SPI4, "infra_spi4", "spi_sel", 25), GATE_INFRA2(CLK_INFRA_SPI5, "infra_spi5", "spi_sel", 26), GATE_INFRA2(CLK_INFRA_CQ_DMA, "infra_cqdma", "axi_sel", 27), GATE_INFRA2(CLK_INFRA_UFS, "infra_ufs", "fufs_sel", 28), GATE_INFRA2(CLK_INFRA_AES_UFSFDE, "infra_aes_ufsfde", "faes_ufsfde_sel", 29), GATE_INFRA2(CLK_INFRA_UFS_TICK, "infra_ufs_tick", "fufs_sel", 30), /* INFRA3 */ GATE_INFRA3(CLK_INFRA_MSDC0_SELF, "infra_msdc0_self", "msdc50_0_sel", 0), GATE_INFRA3(CLK_INFRA_MSDC1_SELF, "infra_msdc1_self", "msdc50_0_sel", 1), GATE_INFRA3(CLK_INFRA_MSDC2_SELF, "infra_msdc2_self", "msdc50_0_sel", 2), /* infra_sspm_26m_self is main clock in co-processor, should not be closed in Linux. */ GATE_INFRA3_FLAGS(CLK_INFRA_SSPM_26M_SELF, "infra_sspm_26m_self", "f_f26m_ck", 3, CLK_IS_CRITICAL), /* infra_sspm_32k_self is main clock in co-processor, should not be closed in Linux. */ GATE_INFRA3_FLAGS(CLK_INFRA_SSPM_32K_SELF, "infra_sspm_32k_self", "f_f26m_ck", 4, CLK_IS_CRITICAL), GATE_INFRA3(CLK_INFRA_UFS_AXI, "infra_ufs_axi", "axi_sel", 5), GATE_INFRA3(CLK_INFRA_I2C6, "infra_i2c6", "i2c_sel", 6), GATE_INFRA3(CLK_INFRA_AP_MSDC0, "infra_ap_msdc0", "msdc50_hclk_sel", 7), GATE_INFRA3(CLK_INFRA_MD_MSDC0, "infra_md_msdc0", "msdc50_hclk_sel", 8), GATE_INFRA3(CLK_INFRA_CCIF2_AP, "infra_ccif2_ap", "axi_sel", 16), GATE_INFRA3(CLK_INFRA_CCIF2_MD, "infra_ccif2_md", "axi_sel", 17), GATE_INFRA3(CLK_INFRA_CCIF3_AP, "infra_ccif3_ap", "axi_sel", 18), GATE_INFRA3(CLK_INFRA_CCIF3_MD, "infra_ccif3_md", "axi_sel", 19), GATE_INFRA3(CLK_INFRA_SEJ_F13M, "infra_sej_f13m", "f_f26m_ck", 20), GATE_INFRA3(CLK_INFRA_AES_BCLK, "infra_aes_bclk", "axi_sel", 21), GATE_INFRA3(CLK_INFRA_I2C7, "infra_i2c7", "i2c_sel", 22), GATE_INFRA3(CLK_INFRA_I2C8, "infra_i2c8", "i2c_sel", 23), GATE_INFRA3(CLK_INFRA_FBIST2FPC, "infra_fbist2fpc", "msdc50_0_sel", 24), }; static const struct mtk_gate_regs peri_cg_regs = { .set_ofs = 0x20c, .clr_ofs = 0x20c, .sta_ofs = 0x20c, }; #define GATE_PERI(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &peri_cg_regs, _shift, \ &mtk_clk_gate_ops_no_setclr_inv) static const struct mtk_gate peri_clks[] = { GATE_PERI(CLK_PERI_AXI, "peri_axi", "axi_sel", 31), }; static u16 infra_rst_ofs[] = { INFRA_RST0_SET_OFFSET, INFRA_RST1_SET_OFFSET, INFRA_RST2_SET_OFFSET, INFRA_RST3_SET_OFFSET, }; static const struct mtk_clk_rst_desc clk_rst_desc = { .version = MTK_RST_SET_CLR, .rst_bank_ofs = infra_rst_ofs, .rst_bank_nr = ARRAY_SIZE(infra_rst_ofs), }; /* Register mux notifier for MFG mux */ static int clk_mt8183_reg_mfg_mux_notifier(struct device *dev, struct clk *clk) { struct mtk_mux_nb *mfg_mux_nb; int i; mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL); if (!mfg_mux_nb) return -ENOMEM; for (i = 0; i < ARRAY_SIZE(top_muxes); i++) if (top_muxes[i].id == CLK_TOP_MUX_MFG) break; if (i == ARRAY_SIZE(top_muxes)) return -EINVAL; mfg_mux_nb->ops = top_muxes[i].ops; mfg_mux_nb->bypass_index = 0; /* Bypass to 26M crystal */ return devm_mtk_clk_mux_notifier_register(dev, clk, mfg_mux_nb); } static const struct mtk_clk_desc infra_desc = { .clks = infra_clks, .num_clks = ARRAY_SIZE(infra_clks), .rst_desc = &clk_rst_desc, }; static const struct mtk_clk_desc mcu_desc = { .composite_clks = mcu_muxes, .num_composite_clks = ARRAY_SIZE(mcu_muxes), .clk_lock = &mt8183_clk_lock, }; static const struct mtk_clk_desc peri_desc = { .clks = peri_clks, .num_clks = ARRAY_SIZE(peri_clks), }; static const struct mtk_clk_desc topck_desc = { .fixed_clks = top_fixed_clks, .num_fixed_clks = ARRAY_SIZE(top_fixed_clks), .factor_clks = top_divs, .num_factor_clks = ARRAY_SIZE(top_divs), .mux_clks = top_muxes, .num_mux_clks = ARRAY_SIZE(top_muxes), .composite_clks = top_aud_comp, .num_composite_clks = ARRAY_SIZE(top_aud_comp), .clks = top_clks, .num_clks = ARRAY_SIZE(top_clks), .clk_lock = &mt8183_clk_lock, .clk_notifier_func = clk_mt8183_reg_mfg_mux_notifier, .mfg_clk_idx = CLK_TOP_MUX_MFG, }; static const struct of_device_id of_match_clk_mt8183[] = { { .compatible = "mediatek,mt8183-infracfg", .data = &infra_desc }, { .compatible = "mediatek,mt8183-mcucfg", .data = &mcu_desc }, { .compatible = "mediatek,mt8183-pericfg", .data = &peri_desc, }, { .compatible = "mediatek,mt8183-topckgen", .data = &topck_desc }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8183); static struct platform_driver clk_mt8183_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt8183", .of_match_table = of_match_clk_mt8183, }, }; module_platform_driver(clk_mt8183_drv) MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8183.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2014 MediaTek Inc. * Copyright (c) 2022 Collabora Ltd. * Author: AngeloGioacchino Del Regno <[email protected]> */ #include <dt-bindings/clock/mt8173-clk.h> #include <linux/module.h> #include <linux/platform_device.h> #include "clk-gate.h" #include "clk-mtk.h" static const struct mtk_gate_regs venc_cg_regs = { .set_ofs = 0x4, .clr_ofs = 0x8, .sta_ofs = 0x0, }; #define GATE_VENC(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &venc_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv) static const struct mtk_gate venc_clks[] = { GATE_DUMMY(CLK_DUMMY, "venc_dummy"), GATE_VENC(CLK_VENC_CKE0, "venc_cke0", "mm_sel", 0), GATE_VENC(CLK_VENC_CKE1, "venc_cke1", "venc_sel", 4), GATE_VENC(CLK_VENC_CKE2, "venc_cke2", "venc_sel", 8), GATE_VENC(CLK_VENC_CKE3, "venc_cke3", "venc_sel", 12), }; static const struct mtk_gate venclt_clks[] = { GATE_DUMMY(CLK_DUMMY, "venclt_dummy"), GATE_VENC(CLK_VENCLT_CKE0, "venclt_cke0", "mm_sel", 0), GATE_VENC(CLK_VENCLT_CKE1, "venclt_cke1", "venclt_sel", 4), }; static const struct mtk_clk_desc venc_desc = { .clks = venc_clks, .num_clks = ARRAY_SIZE(venc_clks), }; static const struct mtk_clk_desc venc_lt_desc = { .clks = venclt_clks, .num_clks = ARRAY_SIZE(venclt_clks), }; static const struct of_device_id of_match_clk_mt8173_vencsys[] = { { .compatible = "mediatek,mt8173-vencsys", .data = &venc_desc }, { .compatible = "mediatek,mt8173-vencltsys", .data = &venc_lt_desc }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt8173_vencsys); static struct platform_driver clk_mt8173_vencsys_drv = { .driver = { .name = "clk-mt8173-vencsys", .of_match_table = of_match_clk_mt8173_vencsys, }, .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, }; module_platform_driver(clk_mt8173_vencsys_drv); MODULE_DESCRIPTION("MediaTek MT8173 vencsys clocks driver"); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt8173-vencsys.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2021 MediaTek Inc. * Author: Sam Shih <[email protected]> * Author: Wenzhen Yu <[email protected]> * Author: Jianhui Zhao <[email protected]> * Author: Daniel Golle <[email protected]> */ #include <linux/clk-provider.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include "clk-mtk.h" #include "clk-gate.h" #include "clk-mux.h" #include <dt-bindings/clock/mediatek,mt7981-clk.h> #include <linux/clk.h> static DEFINE_SPINLOCK(mt7981_clk_lock); static const struct mtk_fixed_factor infra_divs[] = { FACTOR(CLK_INFRA_66M_MCK, "infra_66m_mck", "sysaxi_sel", 1, 2), }; static const char *const infra_uart_parent[] __initconst = { "csw_f26m_sel", "uart_sel" }; static const char *const infra_spi0_parents[] __initconst = { "i2c_sel", "spi_sel" }; static const char *const infra_spi1_parents[] __initconst = { "i2c_sel", "spim_mst_sel" }; static const char *const infra_pwm1_parents[] __initconst = { "pwm_sel" }; static const char *const infra_pwm_bsel_parents[] __initconst = { "cb_rtc_32p7k", "csw_f26m_sel", "infra_66m_mck", "pwm_sel" }; static const char *const infra_pcie_parents[] __initconst = { "cb_rtc_32p7k", "csw_f26m_sel", "cb_cksq_40m", "pextp_tl_ck_sel" }; static const struct mtk_mux infra_muxes[] = { /* MODULE_CLK_SEL_0 */ MUX_GATE_CLR_SET_UPD(CLK_INFRA_UART0_SEL, "infra_uart0_sel", infra_uart_parent, 0x0018, 0x0010, 0x0014, 0, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_UART1_SEL, "infra_uart1_sel", infra_uart_parent, 0x0018, 0x0010, 0x0014, 1, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_UART2_SEL, "infra_uart2_sel", infra_uart_parent, 0x0018, 0x0010, 0x0014, 2, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_SPI0_SEL, "infra_spi0_sel", infra_spi0_parents, 0x0018, 0x0010, 0x0014, 4, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_SPI1_SEL, "infra_spi1_sel", infra_spi1_parents, 0x0018, 0x0010, 0x0014, 5, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_SPI2_SEL, "infra_spi2_sel", infra_spi0_parents, 0x0018, 0x0010, 0x0014, 6, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_PWM1_SEL, "infra_pwm1_sel", infra_pwm1_parents, 0x0018, 0x0010, 0x0014, 9, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_PWM2_SEL, "infra_pwm2_sel", infra_pwm1_parents, 0x0018, 0x0010, 0x0014, 11, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_PWM3_SEL, "infra_pwm3_sel", infra_pwm1_parents, 0x0018, 0x0010, 0x0014, 15, 1, -1, -1, -1), MUX_GATE_CLR_SET_UPD(CLK_INFRA_PWM_BSEL, "infra_pwm_bsel", infra_pwm_bsel_parents, 0x0018, 0x0010, 0x0014, 13, 2, -1, -1, -1), /* MODULE_CLK_SEL_1 */ MUX_GATE_CLR_SET_UPD(CLK_INFRA_PCIE_SEL, "infra_pcie_sel", infra_pcie_parents, 0x0028, 0x0020, 0x0024, 0, 2, -1, -1, -1), }; static const struct mtk_gate_regs infra0_cg_regs = { .set_ofs = 0x40, .clr_ofs = 0x44, .sta_ofs = 0x48, }; static const struct mtk_gate_regs infra1_cg_regs = { .set_ofs = 0x50, .clr_ofs = 0x54, .sta_ofs = 0x58, }; static const struct mtk_gate_regs infra2_cg_regs = { .set_ofs = 0x60, .clr_ofs = 0x64, .sta_ofs = 0x68, }; #define GATE_INFRA0(_id, _name, _parent, _shift) \ { \ .id = _id, .name = _name, .parent_name = _parent, \ .regs = &infra0_cg_regs, .shift = _shift, \ .ops = &mtk_clk_gate_ops_setclr, \ } #define GATE_INFRA1(_id, _name, _parent, _shift) \ { \ .id = _id, .name = _name, .parent_name = _parent, \ .regs = &infra1_cg_regs, .shift = _shift, \ .ops = &mtk_clk_gate_ops_setclr, \ } #define GATE_INFRA2(_id, _name, _parent, _shift) \ { \ .id = _id, .name = _name, .parent_name = _parent, \ .regs = &infra2_cg_regs, .shift = _shift, \ .ops = &mtk_clk_gate_ops_setclr, \ } static const struct mtk_gate infra_clks[] = { /* INFRA0 */ GATE_INFRA0(CLK_INFRA_GPT_STA, "infra_gpt_sta", "infra_66m_mck", 0), GATE_INFRA0(CLK_INFRA_PWM_HCK, "infra_pwm_hck", "infra_66m_mck", 1), GATE_INFRA0(CLK_INFRA_PWM_STA, "infra_pwm_sta", "infra_pwm_bsel", 2), GATE_INFRA0(CLK_INFRA_PWM1_CK, "infra_pwm1", "infra_pwm1_sel", 3), GATE_INFRA0(CLK_INFRA_PWM2_CK, "infra_pwm2", "infra_pwm2_sel", 4), GATE_INFRA0(CLK_INFRA_CQ_DMA_CK, "infra_cq_dma", "sysaxi", 6), GATE_INFRA0(CLK_INFRA_AUD_BUS_CK, "infra_aud_bus", "sysaxi", 8), GATE_INFRA0(CLK_INFRA_AUD_26M_CK, "infra_aud_26m", "csw_f26m_sel", 9), GATE_INFRA0(CLK_INFRA_AUD_L_CK, "infra_aud_l", "aud_l", 10), GATE_INFRA0(CLK_INFRA_AUD_AUD_CK, "infra_aud_aud", "a1sys", 11), GATE_INFRA0(CLK_INFRA_AUD_EG2_CK, "infra_aud_eg2", "a_tuner", 13), GATE_INFRA0(CLK_INFRA_DRAMC_26M_CK, "infra_dramc_26m", "csw_f26m_sel", 14), GATE_INFRA0(CLK_INFRA_DBG_CK, "infra_dbg", "infra_66m_mck", 15), GATE_INFRA0(CLK_INFRA_AP_DMA_CK, "infra_ap_dma", "infra_66m_mck", 16), GATE_INFRA0(CLK_INFRA_SEJ_CK, "infra_sej", "infra_66m_mck", 24), GATE_INFRA0(CLK_INFRA_SEJ_13M_CK, "infra_sej_13m", "csw_f26m_sel", 25), GATE_INFRA0(CLK_INFRA_PWM3_CK, "infra_pwm3", "infra_pwm3_sel", 27), /* INFRA1 */ GATE_INFRA1(CLK_INFRA_THERM_CK, "infra_therm", "csw_f26m_sel", 0), GATE_INFRA1(CLK_INFRA_I2C0_CK, "infra_i2c0", "i2c_bck", 1), GATE_INFRA1(CLK_INFRA_UART0_CK, "infra_uart0", "infra_uart0_sel", 2), GATE_INFRA1(CLK_INFRA_UART1_CK, "infra_uart1", "infra_uart1_sel", 3), GATE_INFRA1(CLK_INFRA_UART2_CK, "infra_uart2", "infra_uart2_sel", 4), GATE_INFRA1(CLK_INFRA_SPI2_CK, "infra_spi2", "infra_spi2_sel", 6), GATE_INFRA1(CLK_INFRA_SPI2_HCK_CK, "infra_spi2_hck", "infra_66m_mck", 7), GATE_INFRA1(CLK_INFRA_NFI1_CK, "infra_nfi1", "nfi1x", 8), GATE_INFRA1(CLK_INFRA_SPINFI1_CK, "infra_spinfi1", "spinfi_bck", 9), GATE_INFRA1(CLK_INFRA_NFI_HCK_CK, "infra_nfi_hck", "infra_66m_mck", 10), GATE_INFRA1(CLK_INFRA_SPI0_CK, "infra_spi0", "infra_spi0_sel", 11), GATE_INFRA1(CLK_INFRA_SPI1_CK, "infra_spi1", "infra_spi1_sel", 12), GATE_INFRA1(CLK_INFRA_SPI0_HCK_CK, "infra_spi0_hck", "infra_66m_mck", 13), GATE_INFRA1(CLK_INFRA_SPI1_HCK_CK, "infra_spi1_hck", "infra_66m_mck", 14), GATE_INFRA1(CLK_INFRA_FRTC_CK, "infra_frtc", "cb_rtc_32k", 15), GATE_INFRA1(CLK_INFRA_MSDC_CK, "infra_msdc", "emmc_400m", 16), GATE_INFRA1(CLK_INFRA_MSDC_HCK_CK, "infra_msdc_hck", "emmc_208m", 17), GATE_INFRA1(CLK_INFRA_MSDC_133M_CK, "infra_msdc_133m", "sysaxi", 18), GATE_INFRA1(CLK_INFRA_MSDC_66M_CK, "infra_msdc_66m", "sysaxi", 19), GATE_INFRA1(CLK_INFRA_ADC_26M_CK, "infra_adc_26m", "infra_adc_frc", 20), GATE_INFRA1(CLK_INFRA_ADC_FRC_CK, "infra_adc_frc", "csw_f26m", 21), GATE_INFRA1(CLK_INFRA_FBIST2FPC_CK, "infra_fbist2fpc", "nfi1x", 23), GATE_INFRA1(CLK_INFRA_I2C_MCK_CK, "infra_i2c_mck", "sysaxi", 25), GATE_INFRA1(CLK_INFRA_I2C_PCK_CK, "infra_i2c_pck", "infra_66m_mck", 26), /* INFRA2 */ GATE_INFRA2(CLK_INFRA_IUSB_133_CK, "infra_iusb_133", "sysaxi", 0), GATE_INFRA2(CLK_INFRA_IUSB_66M_CK, "infra_iusb_66m", "sysaxi", 1), GATE_INFRA2(CLK_INFRA_IUSB_SYS_CK, "infra_iusb_sys", "u2u3_sys", 2), GATE_INFRA2(CLK_INFRA_IUSB_CK, "infra_iusb", "u2u3_ref", 3), GATE_INFRA2(CLK_INFRA_IPCIE_CK, "infra_ipcie", "pextp_tl", 12), GATE_INFRA2(CLK_INFRA_IPCIE_PIPE_CK, "infra_ipcie_pipe", "cb_cksq_40m", 13), GATE_INFRA2(CLK_INFRA_IPCIER_CK, "infra_ipcier", "csw_f26m", 14), GATE_INFRA2(CLK_INFRA_IPCIEB_CK, "infra_ipcieb", "sysaxi", 15), }; static const struct mtk_clk_desc infracfg_desc = { .factor_clks = infra_divs, .num_factor_clks = ARRAY_SIZE(infra_divs), .mux_clks = infra_muxes, .num_mux_clks = ARRAY_SIZE(infra_muxes), .clks = infra_clks, .num_clks = ARRAY_SIZE(infra_clks), .clk_lock = &mt7981_clk_lock, }; static const struct of_device_id of_match_clk_mt7981_infracfg[] = { { .compatible = "mediatek,mt7981-infracfg", .data = &infracfg_desc }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt7981_infracfg); static struct platform_driver clk_mt7981_infracfg_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt7981-infracfg", .of_match_table = of_match_clk_mt7981_infracfg, }, }; module_platform_driver(clk_mt7981_infracfg_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt7981-infracfg.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2014 MediaTek Inc. * Author: Shunli Wang <[email protected]> */ #include <linux/clk-provider.h> #include <linux/platform_device.h> #include "clk-mtk.h" #include "clk-gate.h" #include <dt-bindings/clock/mt2701-clk.h> static const struct mtk_gate_regs vdec0_cg_regs = { .set_ofs = 0x0000, .clr_ofs = 0x0004, .sta_ofs = 0x0000, }; static const struct mtk_gate_regs vdec1_cg_regs = { .set_ofs = 0x0008, .clr_ofs = 0x000c, .sta_ofs = 0x0008, }; #define GATE_VDEC0(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &vdec0_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv) #define GATE_VDEC1(_id, _name, _parent, _shift) \ GATE_MTK(_id, _name, _parent, &vdec1_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv) static const struct mtk_gate vdec_clks[] = { GATE_VDEC0(CLK_VDEC_CKGEN, "vdec_cken", "vdec_sel", 0), GATE_VDEC1(CLK_VDEC_LARB, "vdec_larb_cken", "mm_sel", 0), }; static const struct mtk_clk_desc vdec_desc = { .clks = vdec_clks, .num_clks = ARRAY_SIZE(vdec_clks), }; static const struct of_device_id of_match_clk_mt2701_vdec[] = { { .compatible = "mediatek,mt2701-vdecsys", .data = &vdec_desc, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, of_match_clk_mt2701_vdec); static struct platform_driver clk_mt2701_vdec_drv = { .probe = mtk_clk_simple_probe, .remove_new = mtk_clk_simple_remove, .driver = { .name = "clk-mt2701-vdec", .of_match_table = of_match_clk_mt2701_vdec, }, }; module_platform_driver(clk_mt2701_vdec_drv); MODULE_LICENSE("GPL");
linux-master
drivers/clk/mediatek/clk-mt2701-vdec.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/ */ #include <linux/clk-provider.h> #include <linux/kernel.h> #include <linux/mfd/syscon.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/slab.h> struct ti_syscon_gate_clk_priv { struct clk_hw hw; struct regmap *regmap; u32 reg; u32 idx; }; struct ti_syscon_gate_clk_data { char *name; u32 offset; u32 bit_idx; }; static struct ti_syscon_gate_clk_priv *to_ti_syscon_gate_clk_priv(struct clk_hw *hw) { return container_of(hw, struct ti_syscon_gate_clk_priv, hw); } static int ti_syscon_gate_clk_enable(struct clk_hw *hw) { struct ti_syscon_gate_clk_priv *priv = to_ti_syscon_gate_clk_priv(hw); return regmap_write_bits(priv->regmap, priv->reg, priv->idx, priv->idx); } static void ti_syscon_gate_clk_disable(struct clk_hw *hw) { struct ti_syscon_gate_clk_priv *priv = to_ti_syscon_gate_clk_priv(hw); regmap_write_bits(priv->regmap, priv->reg, priv->idx, 0); } static int ti_syscon_gate_clk_is_enabled(struct clk_hw *hw) { unsigned int val; struct ti_syscon_gate_clk_priv *priv = to_ti_syscon_gate_clk_priv(hw); regmap_read(priv->regmap, priv->reg, &val); return !!(val & priv->idx); } static const struct clk_ops ti_syscon_gate_clk_ops = { .enable = ti_syscon_gate_clk_enable, .disable = ti_syscon_gate_clk_disable, .is_enabled = ti_syscon_gate_clk_is_enabled, }; static struct clk_hw *ti_syscon_gate_clk_register(struct device *dev, struct regmap *regmap, const char *parent_name, const struct ti_syscon_gate_clk_data *data) { struct ti_syscon_gate_clk_priv *priv; struct clk_init_data init; char *name = NULL; int ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return ERR_PTR(-ENOMEM); init.ops = &ti_syscon_gate_clk_ops; if (parent_name) { name = kasprintf(GFP_KERNEL, "%s:%s", data->name, parent_name); init.name = name; init.parent_names = &parent_name; init.num_parents = 1; init.flags = CLK_SET_RATE_PARENT; } else { init.name = data->name; init.parent_names = NULL; init.num_parents = 0; init.flags = 0; } priv->regmap = regmap; priv->reg = data->offset; priv->idx = BIT(data->bit_idx); priv->hw.init = &init; ret = devm_clk_hw_register(dev, &priv->hw); if (name) kfree(init.name); if (ret) return ERR_PTR(ret); return &priv->hw; } static int ti_syscon_gate_clk_probe(struct platform_device *pdev) { const struct ti_syscon_gate_clk_data *data, *p; struct clk_hw_onecell_data *hw_data; struct device *dev = &pdev->dev; int num_clks, num_parents, i; const char *parent_name; struct regmap *regmap; data = device_get_match_data(dev); if (!data) return -EINVAL; regmap = device_node_to_regmap(dev->of_node); if (IS_ERR(regmap)) return dev_err_probe(dev, PTR_ERR(regmap), "failed to get regmap\n"); num_clks = 0; for (p = data; p->name; p++) num_clks++; num_parents = of_clk_get_parent_count(dev->of_node); if (of_device_is_compatible(dev->of_node, "ti,am62-audio-refclk") && num_parents == 0) { return dev_err_probe(dev, -EINVAL, "must specify a parent clock\n"); } hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, num_clks), GFP_KERNEL); if (!hw_data) return -ENOMEM; hw_data->num = num_clks; parent_name = of_clk_get_parent_name(dev->of_node, 0); for (i = 0; i < num_clks; i++) { hw_data->hws[i] = ti_syscon_gate_clk_register(dev, regmap, parent_name, &data[i]); if (IS_ERR(hw_data->hws[i])) dev_warn(dev, "failed to register %s\n", data[i].name); } if (num_clks == 1) return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw_data->hws[0]); return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, hw_data); } #define TI_SYSCON_CLK_GATE(_name, _offset, _bit_idx) \ { \ .name = _name, \ .offset = (_offset), \ .bit_idx = (_bit_idx), \ } static const struct ti_syscon_gate_clk_data am654_clk_data[] = { TI_SYSCON_CLK_GATE("ehrpwm_tbclk0", 0x0, 0), TI_SYSCON_CLK_GATE("ehrpwm_tbclk1", 0x4, 0), TI_SYSCON_CLK_GATE("ehrpwm_tbclk2", 0x8, 0), TI_SYSCON_CLK_GATE("ehrpwm_tbclk3", 0xc, 0), TI_SYSCON_CLK_GATE("ehrpwm_tbclk4", 0x10, 0), TI_SYSCON_CLK_GATE("ehrpwm_tbclk5", 0x14, 0), { /* Sentinel */ }, }; static const struct ti_syscon_gate_clk_data am64_clk_data[] = { TI_SYSCON_CLK_GATE("epwm_tbclk0", 0x0, 0), TI_SYSCON_CLK_GATE("epwm_tbclk1", 0x0, 1), TI_SYSCON_CLK_GATE("epwm_tbclk2", 0x0, 2), TI_SYSCON_CLK_GATE("epwm_tbclk3", 0x0, 3), TI_SYSCON_CLK_GATE("epwm_tbclk4", 0x0, 4), TI_SYSCON_CLK_GATE("epwm_tbclk5", 0x0, 5), TI_SYSCON_CLK_GATE("epwm_tbclk6", 0x0, 6), TI_SYSCON_CLK_GATE("epwm_tbclk7", 0x0, 7), TI_SYSCON_CLK_GATE("epwm_tbclk8", 0x0, 8), { /* Sentinel */ }, }; static const struct ti_syscon_gate_clk_data am62_clk_data[] = { TI_SYSCON_CLK_GATE("epwm_tbclk0", 0x0, 0), TI_SYSCON_CLK_GATE("epwm_tbclk1", 0x0, 1), TI_SYSCON_CLK_GATE("epwm_tbclk2", 0x0, 2), { /* Sentinel */ }, }; static const struct ti_syscon_gate_clk_data am62_audio_clk_data[] = { TI_SYSCON_CLK_GATE("audio_refclk", 0x0, 15), { /* Sentinel */ }, }; static const struct of_device_id ti_syscon_gate_clk_ids[] = { { .compatible = "ti,am654-ehrpwm-tbclk", .data = &am654_clk_data, }, { .compatible = "ti,am64-epwm-tbclk", .data = &am64_clk_data, }, { .compatible = "ti,am62-epwm-tbclk", .data = &am62_clk_data, }, { .compatible = "ti,am62-audio-refclk", .data = &am62_audio_clk_data, }, { } }; MODULE_DEVICE_TABLE(of, ti_syscon_gate_clk_ids); static struct platform_driver ti_syscon_gate_clk_driver = { .probe = ti_syscon_gate_clk_probe, .driver = { .name = "ti-syscon-gate-clk", .of_match_table = ti_syscon_gate_clk_ids, }, }; module_platform_driver(ti_syscon_gate_clk_driver); MODULE_AUTHOR("Vignesh Raghavendra <[email protected]>"); MODULE_DESCRIPTION("Syscon backed gate-clock driver"); MODULE_LICENSE("GPL");
linux-master
drivers/clk/keystone/syscon-clk.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Clock driver for Keystone 2 based devices * * Copyright (C) 2013 Texas Instruments. * Murali Karicheri <[email protected]> * Santosh Shilimkar <[email protected]> */ #include <linux/clk-provider.h> #include <linux/err.h> #include <linux/io.h> #include <linux/slab.h> #include <linux/of_address.h> #include <linux/of.h> #include <linux/module.h> /* PSC register offsets */ #define PTCMD 0x120 #define PTSTAT 0x128 #define PDSTAT 0x200 #define PDCTL 0x300 #define MDSTAT 0x800 #define MDCTL 0xa00 /* PSC module states */ #define PSC_STATE_SWRSTDISABLE 0 #define PSC_STATE_SYNCRST 1 #define PSC_STATE_DISABLE 2 #define PSC_STATE_ENABLE 3 #define MDSTAT_STATE_MASK 0x3f #define MDSTAT_MCKOUT BIT(12) #define PDSTAT_STATE_MASK 0x1f #define MDCTL_FORCE BIT(31) #define MDCTL_LRESET BIT(8) #define PDCTL_NEXT BIT(0) /* Maximum timeout to bail out state transition for module */ #define STATE_TRANS_MAX_COUNT 0xffff static void __iomem *domain_transition_base; /** * struct clk_psc_data - PSC data * @control_base: Base address for a PSC control * @domain_base: Base address for a PSC domain * @domain_id: PSC domain id number */ struct clk_psc_data { void __iomem *control_base; void __iomem *domain_base; u32 domain_id; }; /** * struct clk_psc - PSC clock structure * @hw: clk_hw for the psc * @psc_data: PSC driver specific data * @lock: Spinlock used by the driver */ struct clk_psc { struct clk_hw hw; struct clk_psc_data *psc_data; spinlock_t *lock; }; static DEFINE_SPINLOCK(psc_lock); #define to_clk_psc(_hw) container_of(_hw, struct clk_psc, hw) static void psc_config(void __iomem *control_base, void __iomem *domain_base, u32 next_state, u32 domain_id) { u32 ptcmd, pdstat, pdctl, mdstat, mdctl, ptstat; u32 count = STATE_TRANS_MAX_COUNT; mdctl = readl(control_base + MDCTL); mdctl &= ~MDSTAT_STATE_MASK; mdctl |= next_state; /* For disable, we always put the module in local reset */ if (next_state == PSC_STATE_DISABLE) mdctl &= ~MDCTL_LRESET; writel(mdctl, control_base + MDCTL); pdstat = readl(domain_base + PDSTAT); if (!(pdstat & PDSTAT_STATE_MASK)) { pdctl = readl(domain_base + PDCTL); pdctl |= PDCTL_NEXT; writel(pdctl, domain_base + PDCTL); } ptcmd = 1 << domain_id; writel(ptcmd, domain_transition_base + PTCMD); do { ptstat = readl(domain_transition_base + PTSTAT); } while (((ptstat >> domain_id) & 1) && count--); count = STATE_TRANS_MAX_COUNT; do { mdstat = readl(control_base + MDSTAT); } while (!((mdstat & MDSTAT_STATE_MASK) == next_state) && count--); } static int keystone_clk_is_enabled(struct clk_hw *hw) { struct clk_psc *psc = to_clk_psc(hw); struct clk_psc_data *data = psc->psc_data; u32 mdstat = readl(data->control_base + MDSTAT); return (mdstat & MDSTAT_MCKOUT) ? 1 : 0; } static int keystone_clk_enable(struct clk_hw *hw) { struct clk_psc *psc = to_clk_psc(hw); struct clk_psc_data *data = psc->psc_data; unsigned long flags = 0; if (psc->lock) spin_lock_irqsave(psc->lock, flags); psc_config(data->control_base, data->domain_base, PSC_STATE_ENABLE, data->domain_id); if (psc->lock) spin_unlock_irqrestore(psc->lock, flags); return 0; } static void keystone_clk_disable(struct clk_hw *hw) { struct clk_psc *psc = to_clk_psc(hw); struct clk_psc_data *data = psc->psc_data; unsigned long flags = 0; if (psc->lock) spin_lock_irqsave(psc->lock, flags); psc_config(data->control_base, data->domain_base, PSC_STATE_DISABLE, data->domain_id); if (psc->lock) spin_unlock_irqrestore(psc->lock, flags); } static const struct clk_ops clk_psc_ops = { .enable = keystone_clk_enable, .disable = keystone_clk_disable, .is_enabled = keystone_clk_is_enabled, }; /** * clk_register_psc - register psc clock * @dev: device that is registering this clock * @name: name of this clock * @parent_name: name of clock's parent * @psc_data: platform data to configure this clock * @lock: spinlock used by this clock */ static struct clk *clk_register_psc(struct device *dev, const char *name, const char *parent_name, struct clk_psc_data *psc_data, spinlock_t *lock) { struct clk_init_data init; struct clk_psc *psc; struct clk *clk; psc = kzalloc(sizeof(*psc), GFP_KERNEL); if (!psc) return ERR_PTR(-ENOMEM); init.name = name; init.ops = &clk_psc_ops; init.flags = 0; init.parent_names = (parent_name ? &parent_name : NULL); init.num_parents = (parent_name ? 1 : 0); psc->psc_data = psc_data; psc->lock = lock; psc->hw.init = &init; clk = clk_register(NULL, &psc->hw); if (IS_ERR(clk)) kfree(psc); return clk; } /** * of_psc_clk_init - initialize psc clock through DT * @node: device tree node for this clock * @lock: spinlock used by this clock */ static void __init of_psc_clk_init(struct device_node *node, spinlock_t *lock) { const char *clk_name = node->name; const char *parent_name; struct clk_psc_data *data; struct clk *clk; int i; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) { pr_err("%s: Out of memory\n", __func__); return; } i = of_property_match_string(node, "reg-names", "control"); data->control_base = of_iomap(node, i); if (!data->control_base) { pr_err("%s: control ioremap failed\n", __func__); goto out; } i = of_property_match_string(node, "reg-names", "domain"); data->domain_base = of_iomap(node, i); if (!data->domain_base) { pr_err("%s: domain ioremap failed\n", __func__); goto unmap_ctrl; } of_property_read_u32(node, "domain-id", &data->domain_id); /* Domain transition registers at fixed address space of domain_id 0 */ if (!domain_transition_base && !data->domain_id) domain_transition_base = data->domain_base; of_property_read_string(node, "clock-output-names", &clk_name); parent_name = of_clk_get_parent_name(node, 0); if (!parent_name) { pr_err("%s: Parent clock not found\n", __func__); goto unmap_domain; } clk = clk_register_psc(NULL, clk_name, parent_name, data, lock); if (!IS_ERR(clk)) { of_clk_add_provider(node, of_clk_src_simple_get, clk); return; } pr_err("%s: error registering clk %pOFn\n", __func__, node); unmap_domain: iounmap(data->domain_base); unmap_ctrl: iounmap(data->control_base); out: kfree(data); return; } /** * of_keystone_psc_clk_init - initialize psc clock through DT * @node: device tree node for this clock */ static void __init of_keystone_psc_clk_init(struct device_node *node) { of_psc_clk_init(node, &psc_lock); } CLK_OF_DECLARE(keystone_gate_clk, "ti,keystone,psc-clock", of_keystone_psc_clk_init); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Clock driver for Keystone 2 based devices"); MODULE_AUTHOR("Murali Karicheri <[email protected]>"); MODULE_AUTHOR("Santosh Shilimkar <[email protected]>");
linux-master
drivers/clk/keystone/gate.c
// SPDX-License-Identifier: GPL-2.0-only /* * SCI Clock driver for keystone based devices * * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/ * Tero Kristo <[email protected]> */ #include <linux/clk-provider.h> #include <linux/err.h> #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/soc/ti/ti_sci_protocol.h> #include <linux/bsearch.h> #include <linux/list_sort.h> #define SCI_CLK_SSC_ENABLE BIT(0) #define SCI_CLK_ALLOW_FREQ_CHANGE BIT(1) #define SCI_CLK_INPUT_TERMINATION BIT(2) /** * struct sci_clk_provider - TI SCI clock provider representation * @sci: Handle to the System Control Interface protocol handler * @ops: Pointer to the SCI ops to be used by the clocks * @dev: Device pointer for the clock provider * @clocks: Clocks array for this device * @num_clocks: Total number of clocks for this provider */ struct sci_clk_provider { const struct ti_sci_handle *sci; const struct ti_sci_clk_ops *ops; struct device *dev; struct sci_clk **clocks; int num_clocks; }; /** * struct sci_clk - TI SCI clock representation * @hw: Hardware clock cookie for common clock framework * @dev_id: Device index * @clk_id: Clock index * @num_parents: Number of parents for this clock * @provider: Master clock provider * @flags: Flags for the clock * @node: Link for handling clocks probed via DT * @cached_req: Cached requested freq for determine rate calls * @cached_res: Cached result freq for determine rate calls */ struct sci_clk { struct clk_hw hw; u16 dev_id; u32 clk_id; u32 num_parents; struct sci_clk_provider *provider; u8 flags; struct list_head node; unsigned long cached_req; unsigned long cached_res; }; #define to_sci_clk(_hw) container_of(_hw, struct sci_clk, hw) /** * sci_clk_prepare - Prepare (enable) a TI SCI clock * @hw: clock to prepare * * Prepares a clock to be actively used. Returns the SCI protocol status. */ static int sci_clk_prepare(struct clk_hw *hw) { struct sci_clk *clk = to_sci_clk(hw); bool enable_ssc = clk->flags & SCI_CLK_SSC_ENABLE; bool allow_freq_change = clk->flags & SCI_CLK_ALLOW_FREQ_CHANGE; bool input_termination = clk->flags & SCI_CLK_INPUT_TERMINATION; return clk->provider->ops->get_clock(clk->provider->sci, clk->dev_id, clk->clk_id, enable_ssc, allow_freq_change, input_termination); } /** * sci_clk_unprepare - Un-prepares (disables) a TI SCI clock * @hw: clock to unprepare * * Un-prepares a clock from active state. */ static void sci_clk_unprepare(struct clk_hw *hw) { struct sci_clk *clk = to_sci_clk(hw); int ret; ret = clk->provider->ops->put_clock(clk->provider->sci, clk->dev_id, clk->clk_id); if (ret) dev_err(clk->provider->dev, "unprepare failed for dev=%d, clk=%d, ret=%d\n", clk->dev_id, clk->clk_id, ret); } /** * sci_clk_is_prepared - Check if a TI SCI clock is prepared or not * @hw: clock to check status for * * Checks if a clock is prepared (enabled) in hardware. Returns non-zero * value if clock is enabled, zero otherwise. */ static int sci_clk_is_prepared(struct clk_hw *hw) { struct sci_clk *clk = to_sci_clk(hw); bool req_state, current_state; int ret; ret = clk->provider->ops->is_on(clk->provider->sci, clk->dev_id, clk->clk_id, &req_state, &current_state); if (ret) { dev_err(clk->provider->dev, "is_prepared failed for dev=%d, clk=%d, ret=%d\n", clk->dev_id, clk->clk_id, ret); return 0; } return req_state; } /** * sci_clk_recalc_rate - Get clock rate for a TI SCI clock * @hw: clock to get rate for * @parent_rate: parent rate provided by common clock framework, not used * * Gets the current clock rate of a TI SCI clock. Returns the current * clock rate, or zero in failure. */ static unsigned long sci_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct sci_clk *clk = to_sci_clk(hw); u64 freq; int ret; ret = clk->provider->ops->get_freq(clk->provider->sci, clk->dev_id, clk->clk_id, &freq); if (ret) { dev_err(clk->provider->dev, "recalc-rate failed for dev=%d, clk=%d, ret=%d\n", clk->dev_id, clk->clk_id, ret); return 0; } return freq; } /** * sci_clk_determine_rate - Determines a clock rate a clock can be set to * @hw: clock to change rate for * @req: requested rate configuration for the clock * * Determines a suitable clock rate and parent for a TI SCI clock. * The parent handling is un-used, as generally the parent clock rates * are not known by the kernel; instead these are internally handled * by the firmware. Returns 0 on success, negative error value on failure. */ static int sci_clk_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct sci_clk *clk = to_sci_clk(hw); int ret; u64 new_rate; if (clk->cached_req && clk->cached_req == req->rate) { req->rate = clk->cached_res; return 0; } ret = clk->provider->ops->get_best_match_freq(clk->provider->sci, clk->dev_id, clk->clk_id, req->min_rate, req->rate, req->max_rate, &new_rate); if (ret) { dev_err(clk->provider->dev, "determine-rate failed for dev=%d, clk=%d, ret=%d\n", clk->dev_id, clk->clk_id, ret); return ret; } clk->cached_req = req->rate; clk->cached_res = new_rate; req->rate = new_rate; return 0; } /** * sci_clk_set_rate - Set rate for a TI SCI clock * @hw: clock to change rate for * @rate: target rate for the clock * @parent_rate: rate of the clock parent, not used for TI SCI clocks * * Sets a clock frequency for a TI SCI clock. Returns the TI SCI * protocol status. */ static int sci_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct sci_clk *clk = to_sci_clk(hw); return clk->provider->ops->set_freq(clk->provider->sci, clk->dev_id, clk->clk_id, rate / 10 * 9, rate, rate / 10 * 11); } /** * sci_clk_get_parent - Get the current parent of a TI SCI clock * @hw: clock to get parent for * * Returns the index of the currently selected parent for a TI SCI clock. */ static u8 sci_clk_get_parent(struct clk_hw *hw) { struct sci_clk *clk = to_sci_clk(hw); u32 parent_id = 0; int ret; ret = clk->provider->ops->get_parent(clk->provider->sci, clk->dev_id, clk->clk_id, (void *)&parent_id); if (ret) { dev_err(clk->provider->dev, "get-parent failed for dev=%d, clk=%d, ret=%d\n", clk->dev_id, clk->clk_id, ret); return 0; } parent_id = parent_id - clk->clk_id - 1; return (u8)parent_id; } /** * sci_clk_set_parent - Set the parent of a TI SCI clock * @hw: clock to set parent for * @index: new parent index for the clock * * Sets the parent of a TI SCI clock. Return TI SCI protocol status. */ static int sci_clk_set_parent(struct clk_hw *hw, u8 index) { struct sci_clk *clk = to_sci_clk(hw); clk->cached_req = 0; return clk->provider->ops->set_parent(clk->provider->sci, clk->dev_id, clk->clk_id, index + 1 + clk->clk_id); } static const struct clk_ops sci_clk_ops = { .prepare = sci_clk_prepare, .unprepare = sci_clk_unprepare, .is_prepared = sci_clk_is_prepared, .recalc_rate = sci_clk_recalc_rate, .determine_rate = sci_clk_determine_rate, .set_rate = sci_clk_set_rate, .get_parent = sci_clk_get_parent, .set_parent = sci_clk_set_parent, }; /** * _sci_clk_get - Gets a handle for an SCI clock * @provider: Handle to SCI clock provider * @sci_clk: Handle to the SCI clock to populate * * Gets a handle to an existing TI SCI hw clock, or builds a new clock * entry and registers it with the common clock framework. Called from * the common clock framework, when a corresponding of_clk_get call is * executed, or recursively from itself when parsing parent clocks. * Returns 0 on success, negative error code on failure. */ static int _sci_clk_build(struct sci_clk_provider *provider, struct sci_clk *sci_clk) { struct clk_init_data init = { NULL }; char *name = NULL; char **parent_names = NULL; int i; int ret = 0; name = kasprintf(GFP_KERNEL, "clk:%d:%d", sci_clk->dev_id, sci_clk->clk_id); if (!name) return -ENOMEM; init.name = name; /* * From kernel point of view, we only care about a clocks parents, * if it has more than 1 possible parent. In this case, it is going * to have mux functionality. Otherwise it is going to act as a root * clock. */ if (sci_clk->num_parents < 2) sci_clk->num_parents = 0; if (sci_clk->num_parents) { parent_names = kcalloc(sci_clk->num_parents, sizeof(char *), GFP_KERNEL); if (!parent_names) { ret = -ENOMEM; goto err; } for (i = 0; i < sci_clk->num_parents; i++) { char *parent_name; parent_name = kasprintf(GFP_KERNEL, "clk:%d:%d", sci_clk->dev_id, sci_clk->clk_id + 1 + i); if (!parent_name) { ret = -ENOMEM; goto err; } parent_names[i] = parent_name; } init.parent_names = (void *)parent_names; } init.ops = &sci_clk_ops; init.num_parents = sci_clk->num_parents; sci_clk->hw.init = &init; ret = devm_clk_hw_register(provider->dev, &sci_clk->hw); if (ret) dev_err(provider->dev, "failed clk register with %d\n", ret); err: if (parent_names) { for (i = 0; i < sci_clk->num_parents; i++) kfree(parent_names[i]); kfree(parent_names); } kfree(name); return ret; } static int _cmp_sci_clk(const void *a, const void *b) { const struct sci_clk *ca = a; const struct sci_clk *cb = *(struct sci_clk **)b; if (ca->dev_id == cb->dev_id && ca->clk_id == cb->clk_id) return 0; if (ca->dev_id > cb->dev_id || (ca->dev_id == cb->dev_id && ca->clk_id > cb->clk_id)) return 1; return -1; } /** * sci_clk_get - Xlate function for getting clock handles * @clkspec: device tree clock specifier * @data: pointer to the clock provider * * Xlate function for retrieving clock TI SCI hw clock handles based on * device tree clock specifier. Called from the common clock framework, * when a corresponding of_clk_get call is executed. Returns a pointer * to the TI SCI hw clock struct, or ERR_PTR value in failure. */ static struct clk_hw *sci_clk_get(struct of_phandle_args *clkspec, void *data) { struct sci_clk_provider *provider = data; struct sci_clk **clk; struct sci_clk key; if (clkspec->args_count != 2) return ERR_PTR(-EINVAL); key.dev_id = clkspec->args[0]; key.clk_id = clkspec->args[1]; clk = bsearch(&key, provider->clocks, provider->num_clocks, sizeof(clk), _cmp_sci_clk); if (!clk) return ERR_PTR(-ENODEV); return &(*clk)->hw; } static int ti_sci_init_clocks(struct sci_clk_provider *p) { int i; int ret; for (i = 0; i < p->num_clocks; i++) { ret = _sci_clk_build(p, p->clocks[i]); if (ret) return ret; } return 0; } static const struct of_device_id ti_sci_clk_of_match[] = { { .compatible = "ti,k2g-sci-clk" }, { /* Sentinel */ }, }; MODULE_DEVICE_TABLE(of, ti_sci_clk_of_match); #ifdef CONFIG_TI_SCI_CLK_PROBE_FROM_FW static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider) { int ret; int num_clks = 0; struct sci_clk **clks = NULL; struct sci_clk **tmp_clks; struct sci_clk *sci_clk; int max_clks = 0; int clk_id = 0; int dev_id = 0; u32 num_parents = 0; int gap_size = 0; struct device *dev = provider->dev; while (1) { ret = provider->ops->get_num_parents(provider->sci, dev_id, clk_id, (void *)&num_parents); if (ret) { gap_size++; if (!clk_id) { if (gap_size >= 5) break; dev_id++; } else { if (gap_size >= 2) { dev_id++; clk_id = 0; gap_size = 0; } else { clk_id++; } } continue; } gap_size = 0; if (num_clks == max_clks) { tmp_clks = devm_kmalloc_array(dev, max_clks + 64, sizeof(sci_clk), GFP_KERNEL); memcpy(tmp_clks, clks, max_clks * sizeof(sci_clk)); if (max_clks) devm_kfree(dev, clks); max_clks += 64; clks = tmp_clks; } sci_clk = devm_kzalloc(dev, sizeof(*sci_clk), GFP_KERNEL); if (!sci_clk) return -ENOMEM; sci_clk->dev_id = dev_id; sci_clk->clk_id = clk_id; sci_clk->provider = provider; sci_clk->num_parents = num_parents; clks[num_clks] = sci_clk; clk_id++; num_clks++; } provider->clocks = devm_kmalloc_array(dev, num_clks, sizeof(sci_clk), GFP_KERNEL); if (!provider->clocks) return -ENOMEM; memcpy(provider->clocks, clks, num_clks * sizeof(sci_clk)); provider->num_clocks = num_clks; devm_kfree(dev, clks); return 0; } #else static int _cmp_sci_clk_list(void *priv, const struct list_head *a, const struct list_head *b) { struct sci_clk *ca = container_of(a, struct sci_clk, node); struct sci_clk *cb = container_of(b, struct sci_clk, node); return _cmp_sci_clk(ca, &cb); } static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) { struct device *dev = provider->dev; struct device_node *np = NULL; int ret; int index; struct of_phandle_args args; struct list_head clks; struct sci_clk *sci_clk, *prev; int num_clks = 0; int num_parents; int clk_id; const char * const clk_names[] = { "clocks", "assigned-clocks", "assigned-clock-parents", NULL }; const char * const *clk_name; INIT_LIST_HEAD(&clks); clk_name = clk_names; while (*clk_name) { np = of_find_node_with_property(np, *clk_name); if (!np) { clk_name++; continue; } if (!of_device_is_available(np)) continue; index = 0; do { ret = of_parse_phandle_with_args(np, *clk_name, "#clock-cells", index, &args); if (ret) break; if (args.args_count == 2 && args.np == dev->of_node) { sci_clk = devm_kzalloc(dev, sizeof(*sci_clk), GFP_KERNEL); if (!sci_clk) return -ENOMEM; sci_clk->dev_id = args.args[0]; sci_clk->clk_id = args.args[1]; sci_clk->provider = provider; provider->ops->get_num_parents(provider->sci, sci_clk->dev_id, sci_clk->clk_id, (void *)&sci_clk->num_parents); list_add_tail(&sci_clk->node, &clks); num_clks++; num_parents = sci_clk->num_parents; if (num_parents == 1) num_parents = 0; /* * Linux kernel has inherent limitation * of 255 clock parents at the moment. * Right now, it is not expected that * any mux clock from sci-clk driver * would exceed that limit either, but * the ABI basically provides that * possibility. Print out a warning if * this happens for any clock. */ if (num_parents >= 255) { dev_warn(dev, "too many parents for dev=%d, clk=%d (%d), cropping to 255.\n", sci_clk->dev_id, sci_clk->clk_id, num_parents); num_parents = 255; } clk_id = args.args[1] + 1; while (num_parents--) { sci_clk = devm_kzalloc(dev, sizeof(*sci_clk), GFP_KERNEL); if (!sci_clk) return -ENOMEM; sci_clk->dev_id = args.args[0]; sci_clk->clk_id = clk_id++; sci_clk->provider = provider; list_add_tail(&sci_clk->node, &clks); num_clks++; } } index++; } while (args.np); } list_sort(NULL, &clks, _cmp_sci_clk_list); provider->clocks = devm_kmalloc_array(dev, num_clks, sizeof(sci_clk), GFP_KERNEL); if (!provider->clocks) return -ENOMEM; num_clks = 0; prev = NULL; list_for_each_entry(sci_clk, &clks, node) { if (prev && prev->dev_id == sci_clk->dev_id && prev->clk_id == sci_clk->clk_id) continue; provider->clocks[num_clks++] = sci_clk; prev = sci_clk; } provider->num_clocks = num_clks; return 0; } #endif /** * ti_sci_clk_probe - Probe function for the TI SCI clock driver * @pdev: platform device pointer to be probed * * Probes the TI SCI clock device. Allocates a new clock provider * and registers this to the common clock framework. Also applies * any required flags to the identified clocks via clock lists * supplied from DT. Returns 0 for success, negative error value * for failure. */ static int ti_sci_clk_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; struct sci_clk_provider *provider; const struct ti_sci_handle *handle; int ret; handle = devm_ti_sci_get_handle(dev); if (IS_ERR(handle)) return PTR_ERR(handle); provider = devm_kzalloc(dev, sizeof(*provider), GFP_KERNEL); if (!provider) return -ENOMEM; provider->sci = handle; provider->ops = &handle->ops.clk_ops; provider->dev = dev; #ifdef CONFIG_TI_SCI_CLK_PROBE_FROM_FW ret = ti_sci_scan_clocks_from_fw(provider); if (ret) { dev_err(dev, "scan clocks from FW failed: %d\n", ret); return ret; } #else ret = ti_sci_scan_clocks_from_dt(provider); if (ret) { dev_err(dev, "scan clocks from DT failed: %d\n", ret); return ret; } #endif ret = ti_sci_init_clocks(provider); if (ret) { pr_err("ti-sci-init-clocks failed.\n"); return ret; } return of_clk_add_hw_provider(np, sci_clk_get, provider); } /** * ti_sci_clk_remove - Remove TI SCI clock device * @pdev: platform device pointer for the device to be removed * * Removes the TI SCI device. Unregisters the clock provider registered * via common clock framework. Any memory allocated for the device will * be free'd silently via the devm framework. Returns 0 always. */ static void ti_sci_clk_remove(struct platform_device *pdev) { of_clk_del_provider(pdev->dev.of_node); } static struct platform_driver ti_sci_clk_driver = { .probe = ti_sci_clk_probe, .remove_new = ti_sci_clk_remove, .driver = { .name = "ti-sci-clk", .of_match_table = of_match_ptr(ti_sci_clk_of_match), }, }; module_platform_driver(ti_sci_clk_driver); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("TI System Control Interface(SCI) Clock driver"); MODULE_AUTHOR("Tero Kristo"); MODULE_ALIAS("platform:ti-sci-clk");
linux-master
drivers/clk/keystone/sci-clk.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * PLL clock driver for Keystone devices * * Copyright (C) 2013 Texas Instruments Inc. * Murali Karicheri <[email protected]> * Santosh Shilimkar <[email protected]> */ #include <linux/clk-provider.h> #include <linux/err.h> #include <linux/io.h> #include <linux/slab.h> #include <linux/of_address.h> #include <linux/of.h> #include <linux/module.h> #define PLLM_LOW_MASK 0x3f #define PLLM_HIGH_MASK 0x7ffc0 #define MAIN_PLLM_HIGH_MASK 0x7f000 #define PLLM_HIGH_SHIFT 6 #define PLLD_MASK 0x3f #define CLKOD_MASK 0x780000 #define CLKOD_SHIFT 19 /** * struct clk_pll_data - pll data structure * @has_pllctrl: If set to non zero, lower 6 bits of multiplier is in pllm * register of pll controller, else it is in the pll_ctrl0((bit 11-6) * @phy_pllm: Physical address of PLLM in pll controller. Used when * has_pllctrl is non zero. * @phy_pll_ctl0: Physical address of PLL ctrl0. This could be that of * Main PLL or any other PLLs in the device such as ARM PLL, DDR PLL * or PA PLL available on keystone2. These PLLs are controlled by * this register. Main PLL is controlled by a PLL controller. * @pllm: PLL register map address for multiplier bits * @pllod: PLL register map address for post divider bits * @pll_ctl0: PLL controller map address * @pllm_lower_mask: multiplier lower mask * @pllm_upper_mask: multiplier upper mask * @pllm_upper_shift: multiplier upper shift * @plld_mask: divider mask * @clkod_mask: output divider mask * @clkod_shift: output divider shift * @plld_mask: divider mask * @postdiv: Fixed post divider */ struct clk_pll_data { bool has_pllctrl; u32 phy_pllm; u32 phy_pll_ctl0; void __iomem *pllm; void __iomem *pllod; void __iomem *pll_ctl0; u32 pllm_lower_mask; u32 pllm_upper_mask; u32 pllm_upper_shift; u32 plld_mask; u32 clkod_mask; u32 clkod_shift; u32 postdiv; }; /** * struct clk_pll - Main pll clock * @hw: clk_hw for the pll * @pll_data: PLL driver specific data */ struct clk_pll { struct clk_hw hw; struct clk_pll_data *pll_data; }; #define to_clk_pll(_hw) container_of(_hw, struct clk_pll, hw) static unsigned long clk_pllclk_recalc(struct clk_hw *hw, unsigned long parent_rate) { struct clk_pll *pll = to_clk_pll(hw); struct clk_pll_data *pll_data = pll->pll_data; unsigned long rate = parent_rate; u32 mult = 0, prediv, postdiv, val; /* * get bits 0-5 of multiplier from pllctrl PLLM register * if has_pllctrl is non zero */ if (pll_data->has_pllctrl) { val = readl(pll_data->pllm); mult = (val & pll_data->pllm_lower_mask); } /* bit6-12 of PLLM is in Main PLL control register */ val = readl(pll_data->pll_ctl0); mult |= ((val & pll_data->pllm_upper_mask) >> pll_data->pllm_upper_shift); prediv = (val & pll_data->plld_mask); if (!pll_data->has_pllctrl) /* read post divider from od bits*/ postdiv = ((val & pll_data->clkod_mask) >> pll_data->clkod_shift) + 1; else if (pll_data->pllod) { postdiv = readl(pll_data->pllod); postdiv = ((postdiv & pll_data->clkod_mask) >> pll_data->clkod_shift) + 1; } else postdiv = pll_data->postdiv; rate /= (prediv + 1); rate = (rate * (mult + 1)); rate /= postdiv; return rate; } static const struct clk_ops clk_pll_ops = { .recalc_rate = clk_pllclk_recalc, }; static struct clk *clk_register_pll(struct device *dev, const char *name, const char *parent_name, struct clk_pll_data *pll_data) { struct clk_init_data init; struct clk_pll *pll; struct clk *clk; pll = kzalloc(sizeof(*pll), GFP_KERNEL); if (!pll) return ERR_PTR(-ENOMEM); init.name = name; init.ops = &clk_pll_ops; init.flags = 0; init.parent_names = (parent_name ? &parent_name : NULL); init.num_parents = (parent_name ? 1 : 0); pll->pll_data = pll_data; pll->hw.init = &init; clk = clk_register(NULL, &pll->hw); if (IS_ERR(clk)) goto out; return clk; out: kfree(pll); return NULL; } /** * _of_pll_clk_init - PLL initialisation via DT * @node: device tree node for this clock * @pllctrl: If true, lower 6 bits of multiplier is in pllm register of * pll controller, else it is in the control register0(bit 11-6) */ static void __init _of_pll_clk_init(struct device_node *node, bool pllctrl) { struct clk_pll_data *pll_data; const char *parent_name; struct clk *clk; int i; pll_data = kzalloc(sizeof(*pll_data), GFP_KERNEL); if (!pll_data) { pr_err("%s: Out of memory\n", __func__); return; } parent_name = of_clk_get_parent_name(node, 0); if (of_property_read_u32(node, "fixed-postdiv", &pll_data->postdiv)) { /* assume the PLL has output divider register bits */ pll_data->clkod_mask = CLKOD_MASK; pll_data->clkod_shift = CLKOD_SHIFT; /* * Check if there is an post-divider register. If not * assume od bits are part of control register. */ i = of_property_match_string(node, "reg-names", "post-divider"); pll_data->pllod = of_iomap(node, i); } i = of_property_match_string(node, "reg-names", "control"); pll_data->pll_ctl0 = of_iomap(node, i); if (!pll_data->pll_ctl0) { pr_err("%s: ioremap failed\n", __func__); iounmap(pll_data->pllod); goto out; } pll_data->pllm_lower_mask = PLLM_LOW_MASK; pll_data->pllm_upper_shift = PLLM_HIGH_SHIFT; pll_data->plld_mask = PLLD_MASK; pll_data->has_pllctrl = pllctrl; if (!pll_data->has_pllctrl) { pll_data->pllm_upper_mask = PLLM_HIGH_MASK; } else { pll_data->pllm_upper_mask = MAIN_PLLM_HIGH_MASK; i = of_property_match_string(node, "reg-names", "multiplier"); pll_data->pllm = of_iomap(node, i); if (!pll_data->pllm) { iounmap(pll_data->pll_ctl0); iounmap(pll_data->pllod); goto out; } } clk = clk_register_pll(NULL, node->name, parent_name, pll_data); if (!IS_ERR_OR_NULL(clk)) { of_clk_add_provider(node, of_clk_src_simple_get, clk); return; } out: pr_err("%s: error initializing pll %pOFn\n", __func__, node); kfree(pll_data); } /** * of_keystone_pll_clk_init - PLL initialisation DT wrapper * @node: device tree node for this clock */ static void __init of_keystone_pll_clk_init(struct device_node *node) { _of_pll_clk_init(node, false); } CLK_OF_DECLARE(keystone_pll_clock, "ti,keystone,pll-clock", of_keystone_pll_clk_init); /** * of_keystone_main_pll_clk_init - Main PLL initialisation DT wrapper * @node: device tree node for this clock */ static void __init of_keystone_main_pll_clk_init(struct device_node *node) { _of_pll_clk_init(node, true); } CLK_OF_DECLARE(keystone_main_pll_clock, "ti,keystone,main-pll-clock", of_keystone_main_pll_clk_init); /** * of_pll_div_clk_init - PLL divider setup function * @node: device tree node for this clock */ static void __init of_pll_div_clk_init(struct device_node *node) { const char *parent_name; void __iomem *reg; u32 shift, mask; struct clk *clk; const char *clk_name = node->name; of_property_read_string(node, "clock-output-names", &clk_name); reg = of_iomap(node, 0); if (!reg) { pr_err("%s: ioremap failed\n", __func__); return; } parent_name = of_clk_get_parent_name(node, 0); if (!parent_name) { pr_err("%s: missing parent clock\n", __func__); iounmap(reg); return; } if (of_property_read_u32(node, "bit-shift", &shift)) { pr_err("%s: missing 'shift' property\n", __func__); iounmap(reg); return; } if (of_property_read_u32(node, "bit-mask", &mask)) { pr_err("%s: missing 'bit-mask' property\n", __func__); iounmap(reg); return; } clk = clk_register_divider(NULL, clk_name, parent_name, 0, reg, shift, mask, 0, NULL); if (clk) { of_clk_add_provider(node, of_clk_src_simple_get, clk); } else { pr_err("%s: error registering divider %s\n", __func__, clk_name); iounmap(reg); } } CLK_OF_DECLARE(pll_divider_clock, "ti,keystone,pll-divider-clock", of_pll_div_clk_init); /** * of_pll_mux_clk_init - PLL mux setup function * @node: device tree node for this clock */ static void __init of_pll_mux_clk_init(struct device_node *node) { void __iomem *reg; u32 shift, mask; struct clk *clk; const char *parents[2]; const char *clk_name = node->name; of_property_read_string(node, "clock-output-names", &clk_name); reg = of_iomap(node, 0); if (!reg) { pr_err("%s: ioremap failed\n", __func__); return; } of_clk_parent_fill(node, parents, 2); if (!parents[0] || !parents[1]) { pr_err("%s: missing parent clocks\n", __func__); return; } if (of_property_read_u32(node, "bit-shift", &shift)) { pr_err("%s: missing 'shift' property\n", __func__); return; } if (of_property_read_u32(node, "bit-mask", &mask)) { pr_err("%s: missing 'bit-mask' property\n", __func__); return; } clk = clk_register_mux(NULL, clk_name, (const char **)&parents, ARRAY_SIZE(parents) , 0, reg, shift, mask, 0, NULL); if (clk) of_clk_add_provider(node, of_clk_src_simple_get, clk); else pr_err("%s: error registering mux %s\n", __func__, clk_name); } CLK_OF_DECLARE(pll_mux_clock, "ti,keystone,pll-mux-clock", of_pll_mux_clk_init); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("PLL clock driver for Keystone devices"); MODULE_AUTHOR("Murali Karicheri <[email protected]>"); MODULE_AUTHOR("Santosh Shilimkar <[email protected]>");
linux-master
drivers/clk/keystone/pll.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2020 BAIKAL ELECTRONICS, JSC * * Authors: * Serge Semin <[email protected]> * Dmitry Dunaev <[email protected]> * * Baikal-T1 CCU PLL clocks driver */ #define pr_fmt(fmt) "bt1-ccu-pll: " fmt #include <linux/kernel.h> #include <linux/platform_device.h> #include <linux/printk.h> #include <linux/slab.h> #include <linux/clk-provider.h> #include <linux/mfd/syscon.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/ioport.h> #include <linux/regmap.h> #include <dt-bindings/clock/bt1-ccu.h> #include "ccu-pll.h" #define CCU_CPU_PLL_BASE 0x000 #define CCU_SATA_PLL_BASE 0x008 #define CCU_DDR_PLL_BASE 0x010 #define CCU_PCIE_PLL_BASE 0x018 #define CCU_ETH_PLL_BASE 0x020 #define CCU_PLL_INFO(_id, _name, _pname, _base, _flags, _features) \ { \ .id = _id, \ .name = _name, \ .parent_name = _pname, \ .base = _base, \ .flags = _flags, \ .features = _features, \ } #define CCU_PLL_NUM ARRAY_SIZE(pll_info) struct ccu_pll_info { unsigned int id; const char *name; const char *parent_name; unsigned int base; unsigned long flags; unsigned long features; }; /* * Alas we have to mark all PLLs as critical. CPU and DDR PLLs are sources of * CPU cores and DDR controller reference clocks, due to which they obviously * shouldn't be ever gated. SATA and PCIe PLLs are the parents of APB-bus and * DDR controller AXI-bus clocks. If they are gated the system will be * unusable. Moreover disabling SATA and Ethernet PLLs causes automatic reset * of the corresponding subsystems. So until we aren't ready to re-initialize * all the devices consuming those PLLs, they will be marked as critical too. */ static const struct ccu_pll_info pll_info[] = { CCU_PLL_INFO(CCU_CPU_PLL, "cpu_pll", "ref_clk", CCU_CPU_PLL_BASE, CLK_IS_CRITICAL, CCU_PLL_BASIC), CCU_PLL_INFO(CCU_SATA_PLL, "sata_pll", "ref_clk", CCU_SATA_PLL_BASE, CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0), CCU_PLL_INFO(CCU_DDR_PLL, "ddr_pll", "ref_clk", CCU_DDR_PLL_BASE, CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0), CCU_PLL_INFO(CCU_PCIE_PLL, "pcie_pll", "ref_clk", CCU_PCIE_PLL_BASE, CLK_IS_CRITICAL, CCU_PLL_BASIC), CCU_PLL_INFO(CCU_ETH_PLL, "eth_pll", "ref_clk", CCU_ETH_PLL_BASE, CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0) }; struct ccu_pll_data { struct device_node *np; struct regmap *sys_regs; struct ccu_pll *plls[CCU_PLL_NUM]; }; static struct ccu_pll_data *pll_data; static struct ccu_pll *ccu_pll_find_desc(struct ccu_pll_data *data, unsigned int clk_id) { int idx; for (idx = 0; idx < CCU_PLL_NUM; ++idx) { if (pll_info[idx].id == clk_id) return data->plls[idx]; } return ERR_PTR(-EINVAL); } static struct ccu_pll_data *ccu_pll_create_data(struct device_node *np) { struct ccu_pll_data *data; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return ERR_PTR(-ENOMEM); data->np = np; return data; } static void ccu_pll_free_data(struct ccu_pll_data *data) { kfree(data); } static int ccu_pll_find_sys_regs(struct ccu_pll_data *data) { data->sys_regs = syscon_node_to_regmap(data->np->parent); if (IS_ERR(data->sys_regs)) { pr_err("Failed to find syscon regs for '%s'\n", of_node_full_name(data->np)); return PTR_ERR(data->sys_regs); } return 0; } static struct clk_hw *ccu_pll_of_clk_hw_get(struct of_phandle_args *clkspec, void *priv) { struct ccu_pll_data *data = priv; struct ccu_pll *pll; unsigned int clk_id; clk_id = clkspec->args[0]; pll = ccu_pll_find_desc(data, clk_id); if (IS_ERR(pll)) { if (pll != ERR_PTR(-EPROBE_DEFER)) pr_info("Invalid PLL clock ID %d specified\n", clk_id); return ERR_CAST(pll); } return ccu_pll_get_clk_hw(pll); } static int ccu_pll_clk_register(struct ccu_pll_data *data, bool defer) { int idx, ret; for (idx = 0; idx < CCU_PLL_NUM; ++idx) { const struct ccu_pll_info *info = &pll_info[idx]; struct ccu_pll_init_data init = {0}; /* Defer non-basic PLLs allocation for the probe stage */ if (!!(info->features & CCU_PLL_BASIC) ^ defer) { if (!data->plls[idx]) data->plls[idx] = ERR_PTR(-EPROBE_DEFER); continue; } init.id = info->id; init.name = info->name; init.parent_name = info->parent_name; init.base = info->base; init.sys_regs = data->sys_regs; init.np = data->np; init.flags = info->flags; init.features = info->features; data->plls[idx] = ccu_pll_hw_register(&init); if (IS_ERR(data->plls[idx])) { ret = PTR_ERR(data->plls[idx]); pr_err("Couldn't register PLL hw '%s'\n", init.name); goto err_hw_unregister; } } return 0; err_hw_unregister: for (--idx; idx >= 0; --idx) { if (!!(pll_info[idx].features & CCU_PLL_BASIC) ^ defer) continue; ccu_pll_hw_unregister(data->plls[idx]); } return ret; } static void ccu_pll_clk_unregister(struct ccu_pll_data *data, bool defer) { int idx; /* Uninstall only the clocks registered on the specfied stage */ for (idx = 0; idx < CCU_PLL_NUM; ++idx) { if (!!(pll_info[idx].features & CCU_PLL_BASIC) ^ defer) continue; ccu_pll_hw_unregister(data->plls[idx]); } } static int ccu_pll_of_register(struct ccu_pll_data *data) { int ret; ret = of_clk_add_hw_provider(data->np, ccu_pll_of_clk_hw_get, data); if (ret) { pr_err("Couldn't register PLL provider of '%s'\n", of_node_full_name(data->np)); } return ret; } static int ccu_pll_probe(struct platform_device *pdev) { struct ccu_pll_data *data = pll_data; if (!data) return -EINVAL; return ccu_pll_clk_register(data, false); } static const struct of_device_id ccu_pll_of_match[] = { { .compatible = "baikal,bt1-ccu-pll" }, { } }; static struct platform_driver ccu_pll_driver = { .probe = ccu_pll_probe, .driver = { .name = "clk-ccu-pll", .of_match_table = ccu_pll_of_match, .suppress_bind_attrs = true, }, }; builtin_platform_driver(ccu_pll_driver); static __init void ccu_pll_init(struct device_node *np) { struct ccu_pll_data *data; int ret; data = ccu_pll_create_data(np); if (IS_ERR(data)) return; ret = ccu_pll_find_sys_regs(data); if (ret) goto err_free_data; ret = ccu_pll_clk_register(data, true); if (ret) goto err_free_data; ret = ccu_pll_of_register(data); if (ret) goto err_clk_unregister; pll_data = data; return; err_clk_unregister: ccu_pll_clk_unregister(data, true); err_free_data: ccu_pll_free_data(data); } CLK_OF_DECLARE_DRIVER(ccu_pll, "baikal,bt1-ccu-pll", ccu_pll_init);
linux-master
drivers/clk/baikal-t1/clk-ccu-pll.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2020 BAIKAL ELECTRONICS, JSC * * Authors: * Serge Semin <[email protected]> * Dmitry Dunaev <[email protected]> * * Baikal-T1 CCU Dividers interface driver */ #define pr_fmt(fmt) "bt1-ccu-div: " fmt #include <linux/kernel.h> #include <linux/printk.h> #include <linux/bits.h> #include <linux/bitfield.h> #include <linux/slab.h> #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/spinlock.h> #include <linux/regmap.h> #include <linux/delay.h> #include <linux/time64.h> #include <linux/debugfs.h> #include "ccu-div.h" #define CCU_DIV_CTL 0x00 #define CCU_DIV_CTL_EN BIT(0) #define CCU_DIV_CTL_RST BIT(1) #define CCU_DIV_CTL_SET_CLKDIV BIT(2) #define CCU_DIV_CTL_CLKDIV_FLD 4 #define CCU_DIV_CTL_CLKDIV_MASK(_width) \ GENMASK((_width) + CCU_DIV_CTL_CLKDIV_FLD - 1, CCU_DIV_CTL_CLKDIV_FLD) #define CCU_DIV_CTL_LOCK_SHIFTED BIT(27) #define CCU_DIV_CTL_GATE_REF_BUF BIT(28) #define CCU_DIV_CTL_LOCK_NORMAL BIT(31) #define CCU_DIV_LOCK_CHECK_RETRIES 50 #define CCU_DIV_CLKDIV_MIN 0 #define CCU_DIV_CLKDIV_MAX(_mask) \ ((_mask) >> CCU_DIV_CTL_CLKDIV_FLD) /* * Use the next two methods until there are generic field setter and * getter available with non-constant mask support. */ static inline u32 ccu_div_get(u32 mask, u32 val) { return (val & mask) >> CCU_DIV_CTL_CLKDIV_FLD; } static inline u32 ccu_div_prep(u32 mask, u32 val) { return (val << CCU_DIV_CTL_CLKDIV_FLD) & mask; } static inline unsigned long ccu_div_lock_delay_ns(unsigned long ref_clk, unsigned long div) { u64 ns = 4ULL * (div ?: 1) * NSEC_PER_SEC; do_div(ns, ref_clk); return ns; } static inline unsigned long ccu_div_calc_freq(unsigned long ref_clk, unsigned long div) { return ref_clk / (div ?: 1); } static int ccu_div_var_update_clkdiv(struct ccu_div *div, unsigned long parent_rate, unsigned long divider) { unsigned long nd; u32 val = 0; u32 lock; int count; nd = ccu_div_lock_delay_ns(parent_rate, divider); if (div->features & CCU_DIV_LOCK_SHIFTED) lock = CCU_DIV_CTL_LOCK_SHIFTED; else lock = CCU_DIV_CTL_LOCK_NORMAL; regmap_update_bits(div->sys_regs, div->reg_ctl, CCU_DIV_CTL_SET_CLKDIV, CCU_DIV_CTL_SET_CLKDIV); /* * Until there is nsec-version of readl_poll_timeout() is available * we have to implement the next polling loop. */ count = CCU_DIV_LOCK_CHECK_RETRIES; do { ndelay(nd); regmap_read(div->sys_regs, div->reg_ctl, &val); if (val & lock) return 0; } while (--count); return -ETIMEDOUT; } static int ccu_div_var_enable(struct clk_hw *hw) { struct clk_hw *parent_hw = clk_hw_get_parent(hw); struct ccu_div *div = to_ccu_div(hw); unsigned long flags; u32 val = 0; int ret; if (!parent_hw) { pr_err("Can't enable '%s' with no parent", clk_hw_get_name(hw)); return -EINVAL; } regmap_read(div->sys_regs, div->reg_ctl, &val); if (val & CCU_DIV_CTL_EN) return 0; spin_lock_irqsave(&div->lock, flags); ret = ccu_div_var_update_clkdiv(div, clk_hw_get_rate(parent_hw), ccu_div_get(div->mask, val)); if (!ret) regmap_update_bits(div->sys_regs, div->reg_ctl, CCU_DIV_CTL_EN, CCU_DIV_CTL_EN); spin_unlock_irqrestore(&div->lock, flags); if (ret) pr_err("Divider '%s' lock timed out\n", clk_hw_get_name(hw)); return ret; } static int ccu_div_gate_enable(struct clk_hw *hw) { struct ccu_div *div = to_ccu_div(hw); unsigned long flags; spin_lock_irqsave(&div->lock, flags); regmap_update_bits(div->sys_regs, div->reg_ctl, CCU_DIV_CTL_EN, CCU_DIV_CTL_EN); spin_unlock_irqrestore(&div->lock, flags); return 0; } static void ccu_div_gate_disable(struct clk_hw *hw) { struct ccu_div *div = to_ccu_div(hw); unsigned long flags; spin_lock_irqsave(&div->lock, flags); regmap_update_bits(div->sys_regs, div->reg_ctl, CCU_DIV_CTL_EN, 0); spin_unlock_irqrestore(&div->lock, flags); } static int ccu_div_gate_is_enabled(struct clk_hw *hw) { struct ccu_div *div = to_ccu_div(hw); u32 val = 0; regmap_read(div->sys_regs, div->reg_ctl, &val); return !!(val & CCU_DIV_CTL_EN); } static int ccu_div_buf_enable(struct clk_hw *hw) { struct ccu_div *div = to_ccu_div(hw); unsigned long flags; spin_lock_irqsave(&div->lock, flags); regmap_update_bits(div->sys_regs, div->reg_ctl, CCU_DIV_CTL_GATE_REF_BUF, 0); spin_unlock_irqrestore(&div->lock, flags); return 0; } static void ccu_div_buf_disable(struct clk_hw *hw) { struct ccu_div *div = to_ccu_div(hw); unsigned long flags; spin_lock_irqsave(&div->lock, flags); regmap_update_bits(div->sys_regs, div->reg_ctl, CCU_DIV_CTL_GATE_REF_BUF, CCU_DIV_CTL_GATE_REF_BUF); spin_unlock_irqrestore(&div->lock, flags); } static int ccu_div_buf_is_enabled(struct clk_hw *hw) { struct ccu_div *div = to_ccu_div(hw); u32 val = 0; regmap_read(div->sys_regs, div->reg_ctl, &val); return !(val & CCU_DIV_CTL_GATE_REF_BUF); } static unsigned long ccu_div_var_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct ccu_div *div = to_ccu_div(hw); unsigned long divider; u32 val = 0; regmap_read(div->sys_regs, div->reg_ctl, &val); divider = ccu_div_get(div->mask, val); return ccu_div_calc_freq(parent_rate, divider); } static inline unsigned long ccu_div_var_calc_divider(unsigned long rate, unsigned long parent_rate, unsigned int mask) { unsigned long divider; divider = parent_rate / rate; return clamp_t(unsigned long, divider, CCU_DIV_CLKDIV_MIN, CCU_DIV_CLKDIV_MAX(mask)); } static long ccu_div_var_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { struct ccu_div *div = to_ccu_div(hw); unsigned long divider; divider = ccu_div_var_calc_divider(rate, *parent_rate, div->mask); return ccu_div_calc_freq(*parent_rate, divider); } /* * This method is used for the clock divider blocks, which support the * on-the-fly rate change. So due to lacking the EN bit functionality * they can't be gated before the rate adjustment. */ static int ccu_div_var_set_rate_slow(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct ccu_div *div = to_ccu_div(hw); unsigned long flags, divider; u32 val; int ret; divider = ccu_div_var_calc_divider(rate, parent_rate, div->mask); if (divider == 1 && div->features & CCU_DIV_SKIP_ONE) { divider = 0; } else if (div->features & CCU_DIV_SKIP_ONE_TO_THREE) { if (divider == 1 || divider == 2) divider = 0; else if (divider == 3) divider = 4; } val = ccu_div_prep(div->mask, divider); spin_lock_irqsave(&div->lock, flags); regmap_update_bits(div->sys_regs, div->reg_ctl, div->mask, val); ret = ccu_div_var_update_clkdiv(div, parent_rate, divider); spin_unlock_irqrestore(&div->lock, flags); if (ret) pr_err("Divider '%s' lock timed out\n", clk_hw_get_name(hw)); return ret; } /* * This method is used for the clock divider blocks, which don't support * the on-the-fly rate change. */ static int ccu_div_var_set_rate_fast(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct ccu_div *div = to_ccu_div(hw); unsigned long flags, divider; u32 val; divider = ccu_div_var_calc_divider(rate, parent_rate, div->mask); val = ccu_div_prep(div->mask, divider); /* * Also disable the clock divider block if it was enabled by default * or by the bootloader. */ spin_lock_irqsave(&div->lock, flags); regmap_update_bits(div->sys_regs, div->reg_ctl, div->mask | CCU_DIV_CTL_EN, val); spin_unlock_irqrestore(&div->lock, flags); return 0; } static unsigned long ccu_div_fixed_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct ccu_div *div = to_ccu_div(hw); return ccu_div_calc_freq(parent_rate, div->divider); } static long ccu_div_fixed_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { struct ccu_div *div = to_ccu_div(hw); return ccu_div_calc_freq(*parent_rate, div->divider); } static int ccu_div_fixed_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { return 0; } #ifdef CONFIG_DEBUG_FS struct ccu_div_dbgfs_bit { struct ccu_div *div; const char *name; u32 mask; }; #define CCU_DIV_DBGFS_BIT_ATTR(_name, _mask) { \ .name = _name, \ .mask = _mask \ } static const struct ccu_div_dbgfs_bit ccu_div_bits[] = { CCU_DIV_DBGFS_BIT_ATTR("div_en", CCU_DIV_CTL_EN), CCU_DIV_DBGFS_BIT_ATTR("div_rst", CCU_DIV_CTL_RST), CCU_DIV_DBGFS_BIT_ATTR("div_bypass", CCU_DIV_CTL_SET_CLKDIV), CCU_DIV_DBGFS_BIT_ATTR("div_buf", CCU_DIV_CTL_GATE_REF_BUF), CCU_DIV_DBGFS_BIT_ATTR("div_lock", CCU_DIV_CTL_LOCK_NORMAL) }; #define CCU_DIV_DBGFS_BIT_NUM ARRAY_SIZE(ccu_div_bits) /* * It can be dangerous to change the Divider settings behind clock framework * back, therefore we don't provide any kernel config based compile time option * for this feature to enable. */ #undef CCU_DIV_ALLOW_WRITE_DEBUGFS #ifdef CCU_DIV_ALLOW_WRITE_DEBUGFS static int ccu_div_dbgfs_bit_set(void *priv, u64 val) { const struct ccu_div_dbgfs_bit *bit = priv; struct ccu_div *div = bit->div; unsigned long flags; spin_lock_irqsave(&div->lock, flags); regmap_update_bits(div->sys_regs, div->reg_ctl, bit->mask, val ? bit->mask : 0); spin_unlock_irqrestore(&div->lock, flags); return 0; } static int ccu_div_dbgfs_var_clkdiv_set(void *priv, u64 val) { struct ccu_div *div = priv; unsigned long flags; u32 data; val = clamp_t(u64, val, CCU_DIV_CLKDIV_MIN, CCU_DIV_CLKDIV_MAX(div->mask)); data = ccu_div_prep(div->mask, val); spin_lock_irqsave(&div->lock, flags); regmap_update_bits(div->sys_regs, div->reg_ctl, div->mask, data); spin_unlock_irqrestore(&div->lock, flags); return 0; } #define ccu_div_dbgfs_mode 0644 #else /* !CCU_DIV_ALLOW_WRITE_DEBUGFS */ #define ccu_div_dbgfs_bit_set NULL #define ccu_div_dbgfs_var_clkdiv_set NULL #define ccu_div_dbgfs_mode 0444 #endif /* !CCU_DIV_ALLOW_WRITE_DEBUGFS */ static int ccu_div_dbgfs_bit_get(void *priv, u64 *val) { const struct ccu_div_dbgfs_bit *bit = priv; struct ccu_div *div = bit->div; u32 data = 0; regmap_read(div->sys_regs, div->reg_ctl, &data); *val = !!(data & bit->mask); return 0; } DEFINE_DEBUGFS_ATTRIBUTE(ccu_div_dbgfs_bit_fops, ccu_div_dbgfs_bit_get, ccu_div_dbgfs_bit_set, "%llu\n"); static int ccu_div_dbgfs_var_clkdiv_get(void *priv, u64 *val) { struct ccu_div *div = priv; u32 data = 0; regmap_read(div->sys_regs, div->reg_ctl, &data); *val = ccu_div_get(div->mask, data); return 0; } DEFINE_DEBUGFS_ATTRIBUTE(ccu_div_dbgfs_var_clkdiv_fops, ccu_div_dbgfs_var_clkdiv_get, ccu_div_dbgfs_var_clkdiv_set, "%llu\n"); static int ccu_div_dbgfs_fixed_clkdiv_get(void *priv, u64 *val) { struct ccu_div *div = priv; *val = div->divider; return 0; } DEFINE_DEBUGFS_ATTRIBUTE(ccu_div_dbgfs_fixed_clkdiv_fops, ccu_div_dbgfs_fixed_clkdiv_get, NULL, "%llu\n"); static void ccu_div_var_debug_init(struct clk_hw *hw, struct dentry *dentry) { struct ccu_div *div = to_ccu_div(hw); struct ccu_div_dbgfs_bit *bits; int didx, bidx, num = 2; const char *name; num += !!(div->flags & CLK_SET_RATE_GATE) + !!(div->features & CCU_DIV_RESET_DOMAIN); bits = kcalloc(num, sizeof(*bits), GFP_KERNEL); if (!bits) return; for (didx = 0, bidx = 0; bidx < CCU_DIV_DBGFS_BIT_NUM; ++bidx) { name = ccu_div_bits[bidx].name; if (!(div->flags & CLK_SET_RATE_GATE) && !strcmp("div_en", name)) { continue; } if (!(div->features & CCU_DIV_RESET_DOMAIN) && !strcmp("div_rst", name)) { continue; } if (!strcmp("div_buf", name)) continue; bits[didx] = ccu_div_bits[bidx]; bits[didx].div = div; if (div->features & CCU_DIV_LOCK_SHIFTED && !strcmp("div_lock", name)) { bits[didx].mask = CCU_DIV_CTL_LOCK_SHIFTED; } debugfs_create_file_unsafe(bits[didx].name, ccu_div_dbgfs_mode, dentry, &bits[didx], &ccu_div_dbgfs_bit_fops); ++didx; } debugfs_create_file_unsafe("div_clkdiv", ccu_div_dbgfs_mode, dentry, div, &ccu_div_dbgfs_var_clkdiv_fops); } static void ccu_div_gate_debug_init(struct clk_hw *hw, struct dentry *dentry) { struct ccu_div *div = to_ccu_div(hw); struct ccu_div_dbgfs_bit *bit; bit = kmalloc(sizeof(*bit), GFP_KERNEL); if (!bit) return; *bit = ccu_div_bits[0]; bit->div = div; debugfs_create_file_unsafe(bit->name, ccu_div_dbgfs_mode, dentry, bit, &ccu_div_dbgfs_bit_fops); debugfs_create_file_unsafe("div_clkdiv", 0400, dentry, div, &ccu_div_dbgfs_fixed_clkdiv_fops); } static void ccu_div_buf_debug_init(struct clk_hw *hw, struct dentry *dentry) { struct ccu_div *div = to_ccu_div(hw); struct ccu_div_dbgfs_bit *bit; bit = kmalloc(sizeof(*bit), GFP_KERNEL); if (!bit) return; *bit = ccu_div_bits[3]; bit->div = div; debugfs_create_file_unsafe(bit->name, ccu_div_dbgfs_mode, dentry, bit, &ccu_div_dbgfs_bit_fops); } static void ccu_div_fixed_debug_init(struct clk_hw *hw, struct dentry *dentry) { struct ccu_div *div = to_ccu_div(hw); debugfs_create_file_unsafe("div_clkdiv", 0400, dentry, div, &ccu_div_dbgfs_fixed_clkdiv_fops); } #else /* !CONFIG_DEBUG_FS */ #define ccu_div_var_debug_init NULL #define ccu_div_gate_debug_init NULL #define ccu_div_buf_debug_init NULL #define ccu_div_fixed_debug_init NULL #endif /* !CONFIG_DEBUG_FS */ static const struct clk_ops ccu_div_var_gate_to_set_ops = { .enable = ccu_div_var_enable, .disable = ccu_div_gate_disable, .is_enabled = ccu_div_gate_is_enabled, .recalc_rate = ccu_div_var_recalc_rate, .round_rate = ccu_div_var_round_rate, .set_rate = ccu_div_var_set_rate_fast, .debug_init = ccu_div_var_debug_init }; static const struct clk_ops ccu_div_var_nogate_ops = { .recalc_rate = ccu_div_var_recalc_rate, .round_rate = ccu_div_var_round_rate, .set_rate = ccu_div_var_set_rate_slow, .debug_init = ccu_div_var_debug_init }; static const struct clk_ops ccu_div_gate_ops = { .enable = ccu_div_gate_enable, .disable = ccu_div_gate_disable, .is_enabled = ccu_div_gate_is_enabled, .recalc_rate = ccu_div_fixed_recalc_rate, .round_rate = ccu_div_fixed_round_rate, .set_rate = ccu_div_fixed_set_rate, .debug_init = ccu_div_gate_debug_init }; static const struct clk_ops ccu_div_buf_ops = { .enable = ccu_div_buf_enable, .disable = ccu_div_buf_disable, .is_enabled = ccu_div_buf_is_enabled, .debug_init = ccu_div_buf_debug_init }; static const struct clk_ops ccu_div_fixed_ops = { .recalc_rate = ccu_div_fixed_recalc_rate, .round_rate = ccu_div_fixed_round_rate, .set_rate = ccu_div_fixed_set_rate, .debug_init = ccu_div_fixed_debug_init }; struct ccu_div *ccu_div_hw_register(const struct ccu_div_init_data *div_init) { struct clk_parent_data parent_data = { }; struct clk_init_data hw_init = { }; struct ccu_div *div; int ret; if (!div_init) return ERR_PTR(-EINVAL); div = kzalloc(sizeof(*div), GFP_KERNEL); if (!div) return ERR_PTR(-ENOMEM); /* * Note since Baikal-T1 System Controller registers are MMIO-backed * we won't check the regmap IO operations return status, because it * must be zero anyway. */ div->hw.init = &hw_init; div->id = div_init->id; div->reg_ctl = div_init->base + CCU_DIV_CTL; div->sys_regs = div_init->sys_regs; div->flags = div_init->flags; div->features = div_init->features; spin_lock_init(&div->lock); hw_init.name = div_init->name; hw_init.flags = div_init->flags; if (div_init->type == CCU_DIV_VAR) { if (hw_init.flags & CLK_SET_RATE_GATE) hw_init.ops = &ccu_div_var_gate_to_set_ops; else hw_init.ops = &ccu_div_var_nogate_ops; div->mask = CCU_DIV_CTL_CLKDIV_MASK(div_init->width); } else if (div_init->type == CCU_DIV_GATE) { hw_init.ops = &ccu_div_gate_ops; div->divider = div_init->divider; } else if (div_init->type == CCU_DIV_BUF) { hw_init.ops = &ccu_div_buf_ops; } else if (div_init->type == CCU_DIV_FIXED) { hw_init.ops = &ccu_div_fixed_ops; div->divider = div_init->divider; } else { ret = -EINVAL; goto err_free_div; } if (!div_init->parent_name) { ret = -EINVAL; goto err_free_div; } parent_data.fw_name = div_init->parent_name; parent_data.name = div_init->parent_name; hw_init.parent_data = &parent_data; hw_init.num_parents = 1; ret = of_clk_hw_register(div_init->np, &div->hw); if (ret) goto err_free_div; return div; err_free_div: kfree(div); return ERR_PTR(ret); } void ccu_div_hw_unregister(struct ccu_div *div) { clk_hw_unregister(&div->hw); kfree(div); }
linux-master
drivers/clk/baikal-t1/ccu-div.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC * * Authors: * Serge Semin <[email protected]> * * Baikal-T1 CCU Resets interface driver */ #define pr_fmt(fmt) "bt1-ccu-rst: " fmt #include <linux/bits.h> #include <linux/delay.h> #include <linux/kernel.h> #include <linux/of.h> #include <linux/printk.h> #include <linux/regmap.h> #include <linux/reset-controller.h> #include <linux/slab.h> #include <dt-bindings/reset/bt1-ccu.h> #include "ccu-rst.h" #define CCU_AXI_MAIN_BASE 0x030 #define CCU_AXI_DDR_BASE 0x034 #define CCU_AXI_SATA_BASE 0x038 #define CCU_AXI_GMAC0_BASE 0x03C #define CCU_AXI_GMAC1_BASE 0x040 #define CCU_AXI_XGMAC_BASE 0x044 #define CCU_AXI_PCIE_M_BASE 0x048 #define CCU_AXI_PCIE_S_BASE 0x04C #define CCU_AXI_USB_BASE 0x050 #define CCU_AXI_HWA_BASE 0x054 #define CCU_AXI_SRAM_BASE 0x058 #define CCU_SYS_DDR_BASE 0x02c #define CCU_SYS_SATA_REF_BASE 0x060 #define CCU_SYS_APB_BASE 0x064 #define CCU_SYS_PCIE_BASE 0x144 #define CCU_RST_DELAY_US 1 #define CCU_RST_TRIG(_base, _ofs) \ { \ .type = CCU_RST_TRIG, \ .base = _base, \ .mask = BIT(_ofs), \ } #define CCU_RST_DIR(_base, _ofs) \ { \ .type = CCU_RST_DIR, \ .base = _base, \ .mask = BIT(_ofs), \ } struct ccu_rst_info { enum ccu_rst_type type; unsigned int base; unsigned int mask; }; /* * Each AXI-bus clock divider is equipped with the corresponding clock-consumer * domain reset (it's self-deasserted reset control). */ static const struct ccu_rst_info axi_rst_info[] = { [CCU_AXI_MAIN_RST] = CCU_RST_TRIG(CCU_AXI_MAIN_BASE, 1), [CCU_AXI_DDR_RST] = CCU_RST_TRIG(CCU_AXI_DDR_BASE, 1), [CCU_AXI_SATA_RST] = CCU_RST_TRIG(CCU_AXI_SATA_BASE, 1), [CCU_AXI_GMAC0_RST] = CCU_RST_TRIG(CCU_AXI_GMAC0_BASE, 1), [CCU_AXI_GMAC1_RST] = CCU_RST_TRIG(CCU_AXI_GMAC1_BASE, 1), [CCU_AXI_XGMAC_RST] = CCU_RST_TRIG(CCU_AXI_XGMAC_BASE, 1), [CCU_AXI_PCIE_M_RST] = CCU_RST_TRIG(CCU_AXI_PCIE_M_BASE, 1), [CCU_AXI_PCIE_S_RST] = CCU_RST_TRIG(CCU_AXI_PCIE_S_BASE, 1), [CCU_AXI_USB_RST] = CCU_RST_TRIG(CCU_AXI_USB_BASE, 1), [CCU_AXI_HWA_RST] = CCU_RST_TRIG(CCU_AXI_HWA_BASE, 1), [CCU_AXI_SRAM_RST] = CCU_RST_TRIG(CCU_AXI_SRAM_BASE, 1), }; /* * SATA reference clock domain and APB-bus domain are connected with the * sefl-deasserted reset control, which can be activated via the corresponding * clock divider register. DDR and PCIe sub-domains can be reset with directly * controlled reset signals. Resetting the DDR controller though won't end up * well while the Linux kernel is working. */ static const struct ccu_rst_info sys_rst_info[] = { [CCU_SYS_SATA_REF_RST] = CCU_RST_TRIG(CCU_SYS_SATA_REF_BASE, 1), [CCU_SYS_APB_RST] = CCU_RST_TRIG(CCU_SYS_APB_BASE, 1), [CCU_SYS_DDR_FULL_RST] = CCU_RST_DIR(CCU_SYS_DDR_BASE, 1), [CCU_SYS_DDR_INIT_RST] = CCU_RST_DIR(CCU_SYS_DDR_BASE, 2), [CCU_SYS_PCIE_PCS_PHY_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 0), [CCU_SYS_PCIE_PIPE0_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 4), [CCU_SYS_PCIE_CORE_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 8), [CCU_SYS_PCIE_PWR_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 9), [CCU_SYS_PCIE_STICKY_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 10), [CCU_SYS_PCIE_NSTICKY_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 11), [CCU_SYS_PCIE_HOT_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 12), }; static int ccu_rst_reset(struct reset_controller_dev *rcdev, unsigned long idx) { struct ccu_rst *rst = to_ccu_rst(rcdev); const struct ccu_rst_info *info = &rst->rsts_info[idx]; if (info->type != CCU_RST_TRIG) return -EOPNOTSUPP; regmap_update_bits(rst->sys_regs, info->base, info->mask, info->mask); /* The next delay must be enough to cover all the resets. */ udelay(CCU_RST_DELAY_US); return 0; } static int ccu_rst_set(struct reset_controller_dev *rcdev, unsigned long idx, bool high) { struct ccu_rst *rst = to_ccu_rst(rcdev); const struct ccu_rst_info *info = &rst->rsts_info[idx]; if (info->type != CCU_RST_DIR) return high ? -EOPNOTSUPP : 0; return regmap_update_bits(rst->sys_regs, info->base, info->mask, high ? info->mask : 0); } static int ccu_rst_assert(struct reset_controller_dev *rcdev, unsigned long idx) { return ccu_rst_set(rcdev, idx, true); } static int ccu_rst_deassert(struct reset_controller_dev *rcdev, unsigned long idx) { return ccu_rst_set(rcdev, idx, false); } static int ccu_rst_status(struct reset_controller_dev *rcdev, unsigned long idx) { struct ccu_rst *rst = to_ccu_rst(rcdev); const struct ccu_rst_info *info = &rst->rsts_info[idx]; u32 val; if (info->type != CCU_RST_DIR) return -EOPNOTSUPP; regmap_read(rst->sys_regs, info->base, &val); return !!(val & info->mask); } static const struct reset_control_ops ccu_rst_ops = { .reset = ccu_rst_reset, .assert = ccu_rst_assert, .deassert = ccu_rst_deassert, .status = ccu_rst_status, }; struct ccu_rst *ccu_rst_hw_register(const struct ccu_rst_init_data *rst_init) { struct ccu_rst *rst; int ret; if (!rst_init) return ERR_PTR(-EINVAL); rst = kzalloc(sizeof(*rst), GFP_KERNEL); if (!rst) return ERR_PTR(-ENOMEM); rst->sys_regs = rst_init->sys_regs; if (of_device_is_compatible(rst_init->np, "baikal,bt1-ccu-axi")) { rst->rcdev.nr_resets = ARRAY_SIZE(axi_rst_info); rst->rsts_info = axi_rst_info; } else if (of_device_is_compatible(rst_init->np, "baikal,bt1-ccu-sys")) { rst->rcdev.nr_resets = ARRAY_SIZE(sys_rst_info); rst->rsts_info = sys_rst_info; } else { pr_err("Incompatible DT node '%s' specified\n", of_node_full_name(rst_init->np)); ret = -EINVAL; goto err_kfree_rst; } rst->rcdev.owner = THIS_MODULE; rst->rcdev.ops = &ccu_rst_ops; rst->rcdev.of_node = rst_init->np; ret = reset_controller_register(&rst->rcdev); if (ret) { pr_err("Couldn't register '%s' reset controller\n", of_node_full_name(rst_init->np)); goto err_kfree_rst; } return rst; err_kfree_rst: kfree(rst); return ERR_PTR(ret); } void ccu_rst_hw_unregister(struct ccu_rst *rst) { reset_controller_unregister(&rst->rcdev); kfree(rst); }
linux-master
drivers/clk/baikal-t1/ccu-rst.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2020 BAIKAL ELECTRONICS, JSC * * Authors: * Serge Semin <[email protected]> * Dmitry Dunaev <[email protected]> * * Baikal-T1 CCU Dividers clock driver */ #define pr_fmt(fmt) "bt1-ccu-div: " fmt #include <linux/kernel.h> #include <linux/platform_device.h> #include <linux/printk.h> #include <linux/slab.h> #include <linux/clk-provider.h> #include <linux/reset-controller.h> #include <linux/mfd/syscon.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/ioport.h> #include <linux/regmap.h> #include <dt-bindings/clock/bt1-ccu.h> #include "ccu-div.h" #include "ccu-rst.h" #define CCU_AXI_MAIN_BASE 0x030 #define CCU_AXI_DDR_BASE 0x034 #define CCU_AXI_SATA_BASE 0x038 #define CCU_AXI_GMAC0_BASE 0x03C #define CCU_AXI_GMAC1_BASE 0x040 #define CCU_AXI_XGMAC_BASE 0x044 #define CCU_AXI_PCIE_M_BASE 0x048 #define CCU_AXI_PCIE_S_BASE 0x04C #define CCU_AXI_USB_BASE 0x050 #define CCU_AXI_HWA_BASE 0x054 #define CCU_AXI_SRAM_BASE 0x058 #define CCU_SYS_SATA_REF_BASE 0x060 #define CCU_SYS_APB_BASE 0x064 #define CCU_SYS_GMAC0_BASE 0x068 #define CCU_SYS_GMAC1_BASE 0x06C #define CCU_SYS_XGMAC_BASE 0x070 #define CCU_SYS_USB_BASE 0x074 #define CCU_SYS_PVT_BASE 0x078 #define CCU_SYS_HWA_BASE 0x07C #define CCU_SYS_UART_BASE 0x084 #define CCU_SYS_TIMER0_BASE 0x088 #define CCU_SYS_TIMER1_BASE 0x08C #define CCU_SYS_TIMER2_BASE 0x090 #define CCU_SYS_WDT_BASE 0x150 #define CCU_DIV_VAR_INFO(_id, _name, _pname, _base, _width, _flags, _features) \ { \ .id = _id, \ .name = _name, \ .parent_name = _pname, \ .base = _base, \ .type = CCU_DIV_VAR, \ .width = _width, \ .flags = _flags, \ .features = _features \ } #define CCU_DIV_GATE_INFO(_id, _name, _pname, _base, _divider) \ { \ .id = _id, \ .name = _name, \ .parent_name = _pname, \ .base = _base, \ .type = CCU_DIV_GATE, \ .divider = _divider \ } #define CCU_DIV_BUF_INFO(_id, _name, _pname, _base, _flags) \ { \ .id = _id, \ .name = _name, \ .parent_name = _pname, \ .base = _base, \ .type = CCU_DIV_BUF, \ .flags = _flags \ } #define CCU_DIV_FIXED_INFO(_id, _name, _pname, _divider) \ { \ .id = _id, \ .name = _name, \ .parent_name = _pname, \ .type = CCU_DIV_FIXED, \ .divider = _divider \ } struct ccu_div_info { unsigned int id; const char *name; const char *parent_name; unsigned int base; enum ccu_div_type type; union { unsigned int width; unsigned int divider; }; unsigned long flags; unsigned long features; }; struct ccu_div_data { struct device_node *np; struct regmap *sys_regs; unsigned int divs_num; const struct ccu_div_info *divs_info; struct ccu_div **divs; struct ccu_rst *rsts; }; /* * AXI Main Interconnect (axi_main_clk) and DDR AXI-bus (axi_ddr_clk) clocks * must be left enabled in any case, since former one is responsible for * clocking a bus between CPU cores and the rest of the SoC components, while * the later is clocking the AXI-bus between DDR controller and the Main * Interconnect. So should any of these clocks get to be disabled, the system * will literally stop working. That's why we marked them as critical. */ static const struct ccu_div_info axi_info[] = { CCU_DIV_VAR_INFO(CCU_AXI_MAIN_CLK, "axi_main_clk", "pcie_clk", CCU_AXI_MAIN_BASE, 4, CLK_IS_CRITICAL, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_DDR_CLK, "axi_ddr_clk", "sata_clk", CCU_AXI_DDR_BASE, 4, CLK_IS_CRITICAL | CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_SATA_CLK, "axi_sata_clk", "sata_clk", CCU_AXI_SATA_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_GMAC0_CLK, "axi_gmac0_clk", "eth_clk", CCU_AXI_GMAC0_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_GMAC1_CLK, "axi_gmac1_clk", "eth_clk", CCU_AXI_GMAC1_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_XGMAC_CLK, "axi_xgmac_clk", "eth_clk", CCU_AXI_XGMAC_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_PCIE_M_CLK, "axi_pcie_m_clk", "pcie_clk", CCU_AXI_PCIE_M_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_PCIE_S_CLK, "axi_pcie_s_clk", "pcie_clk", CCU_AXI_PCIE_S_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_USB_CLK, "axi_usb_clk", "sata_clk", CCU_AXI_USB_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_HWA_CLK, "axi_hwa_clk", "sata_clk", CCU_AXI_HWA_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN), CCU_DIV_VAR_INFO(CCU_AXI_SRAM_CLK, "axi_sram_clk", "eth_clk", CCU_AXI_SRAM_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN) }; /* * APB-bus clock is marked as critical since it's a main communication bus * for the SoC devices registers IO-operations. */ static const struct ccu_div_info sys_info[] = { CCU_DIV_VAR_INFO(CCU_SYS_SATA_CLK, "sys_sata_clk", "sata_clk", CCU_SYS_SATA_REF_BASE, 4, CLK_SET_RATE_GATE, CCU_DIV_SKIP_ONE | CCU_DIV_LOCK_SHIFTED | CCU_DIV_RESET_DOMAIN), CCU_DIV_BUF_INFO(CCU_SYS_SATA_REF_CLK, "sys_sata_ref_clk", "sys_sata_clk", CCU_SYS_SATA_REF_BASE, CLK_SET_RATE_PARENT), CCU_DIV_VAR_INFO(CCU_SYS_APB_CLK, "sys_apb_clk", "pcie_clk", CCU_SYS_APB_BASE, 5, CLK_IS_CRITICAL, CCU_DIV_BASIC | CCU_DIV_RESET_DOMAIN), CCU_DIV_GATE_INFO(CCU_SYS_GMAC0_TX_CLK, "sys_gmac0_tx_clk", "eth_clk", CCU_SYS_GMAC0_BASE, 5), CCU_DIV_FIXED_INFO(CCU_SYS_GMAC0_PTP_CLK, "sys_gmac0_ptp_clk", "eth_clk", 10), CCU_DIV_GATE_INFO(CCU_SYS_GMAC1_TX_CLK, "sys_gmac1_tx_clk", "eth_clk", CCU_SYS_GMAC1_BASE, 5), CCU_DIV_FIXED_INFO(CCU_SYS_GMAC1_PTP_CLK, "sys_gmac1_ptp_clk", "eth_clk", 10), CCU_DIV_GATE_INFO(CCU_SYS_XGMAC_CLK, "sys_xgmac_clk", "eth_clk", CCU_SYS_XGMAC_BASE, 1), CCU_DIV_FIXED_INFO(CCU_SYS_XGMAC_REF_CLK, "sys_xgmac_ref_clk", "sys_xgmac_clk", 8), CCU_DIV_FIXED_INFO(CCU_SYS_XGMAC_PTP_CLK, "sys_xgmac_ptp_clk", "sys_xgmac_clk", 8), CCU_DIV_GATE_INFO(CCU_SYS_USB_CLK, "sys_usb_clk", "eth_clk", CCU_SYS_USB_BASE, 10), CCU_DIV_VAR_INFO(CCU_SYS_PVT_CLK, "sys_pvt_clk", "ref_clk", CCU_SYS_PVT_BASE, 5, CLK_SET_RATE_GATE, 0), CCU_DIV_VAR_INFO(CCU_SYS_HWA_CLK, "sys_hwa_clk", "sata_clk", CCU_SYS_HWA_BASE, 4, CLK_SET_RATE_GATE, 0), CCU_DIV_VAR_INFO(CCU_SYS_UART_CLK, "sys_uart_clk", "eth_clk", CCU_SYS_UART_BASE, 17, CLK_SET_RATE_GATE, 0), CCU_DIV_FIXED_INFO(CCU_SYS_I2C1_CLK, "sys_i2c1_clk", "eth_clk", 10), CCU_DIV_FIXED_INFO(CCU_SYS_I2C2_CLK, "sys_i2c2_clk", "eth_clk", 10), CCU_DIV_FIXED_INFO(CCU_SYS_GPIO_CLK, "sys_gpio_clk", "ref_clk", 25), CCU_DIV_VAR_INFO(CCU_SYS_TIMER0_CLK, "sys_timer0_clk", "ref_clk", CCU_SYS_TIMER0_BASE, 17, CLK_SET_RATE_GATE, CCU_DIV_BASIC), CCU_DIV_VAR_INFO(CCU_SYS_TIMER1_CLK, "sys_timer1_clk", "ref_clk", CCU_SYS_TIMER1_BASE, 17, CLK_SET_RATE_GATE, CCU_DIV_BASIC), CCU_DIV_VAR_INFO(CCU_SYS_TIMER2_CLK, "sys_timer2_clk", "ref_clk", CCU_SYS_TIMER2_BASE, 17, CLK_SET_RATE_GATE, CCU_DIV_BASIC), CCU_DIV_VAR_INFO(CCU_SYS_WDT_CLK, "sys_wdt_clk", "eth_clk", CCU_SYS_WDT_BASE, 17, CLK_SET_RATE_GATE, CCU_DIV_SKIP_ONE_TO_THREE) }; static struct ccu_div_data *axi_data; static struct ccu_div_data *sys_data; static void ccu_div_set_data(struct ccu_div_data *data) { struct device_node *np = data->np; if (of_device_is_compatible(np, "baikal,bt1-ccu-axi")) axi_data = data; else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys")) sys_data = data; else pr_err("Invalid DT node '%s' specified\n", of_node_full_name(np)); } static struct ccu_div_data *ccu_div_get_data(struct device_node *np) { if (of_device_is_compatible(np, "baikal,bt1-ccu-axi")) return axi_data; else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys")) return sys_data; pr_err("Invalid DT node '%s' specified\n", of_node_full_name(np)); return NULL; } static struct ccu_div *ccu_div_find_desc(struct ccu_div_data *data, unsigned int clk_id) { int idx; for (idx = 0; idx < data->divs_num; ++idx) { if (data->divs_info[idx].id == clk_id) return data->divs[idx]; } return ERR_PTR(-EINVAL); } static struct ccu_div_data *ccu_div_create_data(struct device_node *np) { struct ccu_div_data *data; int ret; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return ERR_PTR(-ENOMEM); data->np = np; if (of_device_is_compatible(np, "baikal,bt1-ccu-axi")) { data->divs_num = ARRAY_SIZE(axi_info); data->divs_info = axi_info; } else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys")) { data->divs_num = ARRAY_SIZE(sys_info); data->divs_info = sys_info; } else { pr_err("Incompatible DT node '%s' specified\n", of_node_full_name(np)); ret = -EINVAL; goto err_kfree_data; } data->divs = kcalloc(data->divs_num, sizeof(*data->divs), GFP_KERNEL); if (!data->divs) { ret = -ENOMEM; goto err_kfree_data; } return data; err_kfree_data: kfree(data); return ERR_PTR(ret); } static void ccu_div_free_data(struct ccu_div_data *data) { kfree(data->divs); kfree(data); } static int ccu_div_find_sys_regs(struct ccu_div_data *data) { data->sys_regs = syscon_node_to_regmap(data->np->parent); if (IS_ERR(data->sys_regs)) { pr_err("Failed to find syscon regs for '%s'\n", of_node_full_name(data->np)); return PTR_ERR(data->sys_regs); } return 0; } static struct clk_hw *ccu_div_of_clk_hw_get(struct of_phandle_args *clkspec, void *priv) { struct ccu_div_data *data = priv; struct ccu_div *div; unsigned int clk_id; clk_id = clkspec->args[0]; div = ccu_div_find_desc(data, clk_id); if (IS_ERR(div)) { if (div != ERR_PTR(-EPROBE_DEFER)) pr_info("Invalid clock ID %d specified\n", clk_id); return ERR_CAST(div); } return ccu_div_get_clk_hw(div); } static int ccu_div_clk_register(struct ccu_div_data *data, bool defer) { int idx, ret; for (idx = 0; idx < data->divs_num; ++idx) { const struct ccu_div_info *info = &data->divs_info[idx]; struct ccu_div_init_data init = {0}; if (!!(info->features & CCU_DIV_BASIC) ^ defer) { if (!data->divs[idx]) data->divs[idx] = ERR_PTR(-EPROBE_DEFER); continue; } init.id = info->id; init.name = info->name; init.parent_name = info->parent_name; init.np = data->np; init.type = info->type; init.flags = info->flags; init.features = info->features; if (init.type == CCU_DIV_VAR) { init.base = info->base; init.sys_regs = data->sys_regs; init.width = info->width; } else if (init.type == CCU_DIV_GATE) { init.base = info->base; init.sys_regs = data->sys_regs; init.divider = info->divider; } else if (init.type == CCU_DIV_BUF) { init.base = info->base; init.sys_regs = data->sys_regs; } else { init.divider = info->divider; } data->divs[idx] = ccu_div_hw_register(&init); if (IS_ERR(data->divs[idx])) { ret = PTR_ERR(data->divs[idx]); pr_err("Couldn't register divider '%s' hw\n", init.name); goto err_hw_unregister; } } return 0; err_hw_unregister: for (--idx; idx >= 0; --idx) { if (!!(data->divs_info[idx].features & CCU_DIV_BASIC) ^ defer) continue; ccu_div_hw_unregister(data->divs[idx]); } return ret; } static void ccu_div_clk_unregister(struct ccu_div_data *data, bool defer) { int idx; /* Uninstall only the clocks registered on the specfied stage */ for (idx = 0; idx < data->divs_num; ++idx) { if (!!(data->divs_info[idx].features & CCU_DIV_BASIC) ^ defer) continue; ccu_div_hw_unregister(data->divs[idx]); } } static int ccu_div_of_register(struct ccu_div_data *data) { int ret; ret = of_clk_add_hw_provider(data->np, ccu_div_of_clk_hw_get, data); if (ret) { pr_err("Couldn't register dividers '%s' clock provider\n", of_node_full_name(data->np)); } return ret; } static int ccu_div_rst_register(struct ccu_div_data *data) { struct ccu_rst_init_data init = {0}; init.sys_regs = data->sys_regs; init.np = data->np; data->rsts = ccu_rst_hw_register(&init); if (IS_ERR(data->rsts)) { pr_err("Couldn't register divider '%s' reset controller\n", of_node_full_name(data->np)); return PTR_ERR(data->rsts); } return 0; } static int ccu_div_probe(struct platform_device *pdev) { struct ccu_div_data *data; int ret; data = ccu_div_get_data(dev_of_node(&pdev->dev)); if (!data) return -EINVAL; ret = ccu_div_clk_register(data, false); if (ret) return ret; ret = ccu_div_rst_register(data); if (ret) goto err_clk_unregister; return 0; err_clk_unregister: ccu_div_clk_unregister(data, false); return ret; } static const struct of_device_id ccu_div_of_match[] = { { .compatible = "baikal,bt1-ccu-axi" }, { .compatible = "baikal,bt1-ccu-sys" }, { } }; static struct platform_driver ccu_div_driver = { .probe = ccu_div_probe, .driver = { .name = "clk-ccu-div", .of_match_table = ccu_div_of_match, .suppress_bind_attrs = true, }, }; builtin_platform_driver(ccu_div_driver); static __init void ccu_div_init(struct device_node *np) { struct ccu_div_data *data; int ret; data = ccu_div_create_data(np); if (IS_ERR(data)) return; ret = ccu_div_find_sys_regs(data); if (ret) goto err_free_data; ret = ccu_div_clk_register(data, true); if (ret) goto err_free_data; ret = ccu_div_of_register(data); if (ret) goto err_clk_unregister; ccu_div_set_data(data); return; err_clk_unregister: ccu_div_clk_unregister(data, true); err_free_data: ccu_div_free_data(data); } CLK_OF_DECLARE_DRIVER(ccu_axi, "baikal,bt1-ccu-axi", ccu_div_init); CLK_OF_DECLARE_DRIVER(ccu_sys, "baikal,bt1-ccu-sys", ccu_div_init);
linux-master
drivers/clk/baikal-t1/clk-ccu-div.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2020 BAIKAL ELECTRONICS, JSC * * Authors: * Serge Semin <[email protected]> * Dmitry Dunaev <[email protected]> * * Baikal-T1 CCU PLL interface driver */ #define pr_fmt(fmt) "bt1-ccu-pll: " fmt #include <linux/kernel.h> #include <linux/printk.h> #include <linux/limits.h> #include <linux/bits.h> #include <linux/bitfield.h> #include <linux/slab.h> #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/spinlock.h> #include <linux/regmap.h> #include <linux/iopoll.h> #include <linux/time64.h> #include <linux/rational.h> #include <linux/debugfs.h> #include "ccu-pll.h" #define CCU_PLL_CTL 0x000 #define CCU_PLL_CTL_EN BIT(0) #define CCU_PLL_CTL_RST BIT(1) #define CCU_PLL_CTL_CLKR_FLD 2 #define CCU_PLL_CTL_CLKR_MASK GENMASK(7, CCU_PLL_CTL_CLKR_FLD) #define CCU_PLL_CTL_CLKF_FLD 8 #define CCU_PLL_CTL_CLKF_MASK GENMASK(20, CCU_PLL_CTL_CLKF_FLD) #define CCU_PLL_CTL_CLKOD_FLD 21 #define CCU_PLL_CTL_CLKOD_MASK GENMASK(24, CCU_PLL_CTL_CLKOD_FLD) #define CCU_PLL_CTL_BYPASS BIT(30) #define CCU_PLL_CTL_LOCK BIT(31) #define CCU_PLL_CTL1 0x004 #define CCU_PLL_CTL1_BWADJ_FLD 3 #define CCU_PLL_CTL1_BWADJ_MASK GENMASK(14, CCU_PLL_CTL1_BWADJ_FLD) #define CCU_PLL_LOCK_CHECK_RETRIES 50 #define CCU_PLL_NR_MAX \ ((CCU_PLL_CTL_CLKR_MASK >> CCU_PLL_CTL_CLKR_FLD) + 1) #define CCU_PLL_NF_MAX \ ((CCU_PLL_CTL_CLKF_MASK >> (CCU_PLL_CTL_CLKF_FLD + 1)) + 1) #define CCU_PLL_OD_MAX \ ((CCU_PLL_CTL_CLKOD_MASK >> CCU_PLL_CTL_CLKOD_FLD) + 1) #define CCU_PLL_NB_MAX \ ((CCU_PLL_CTL1_BWADJ_MASK >> CCU_PLL_CTL1_BWADJ_FLD) + 1) #define CCU_PLL_FDIV_MIN 427000UL #define CCU_PLL_FDIV_MAX 3500000000UL #define CCU_PLL_FOUT_MIN 200000000UL #define CCU_PLL_FOUT_MAX 2500000000UL #define CCU_PLL_FVCO_MIN 700000000UL #define CCU_PLL_FVCO_MAX 3500000000UL #define CCU_PLL_CLKOD_FACTOR 2 static inline unsigned long ccu_pll_lock_delay_us(unsigned long ref_clk, unsigned long nr) { u64 us = 500ULL * nr * USEC_PER_SEC; do_div(us, ref_clk); return us; } static inline unsigned long ccu_pll_calc_freq(unsigned long ref_clk, unsigned long nr, unsigned long nf, unsigned long od) { u64 tmp = ref_clk; do_div(tmp, nr); tmp *= nf; do_div(tmp, od); return tmp; } static int ccu_pll_reset(struct ccu_pll *pll, unsigned long ref_clk, unsigned long nr) { unsigned long ud, ut; u32 val; ud = ccu_pll_lock_delay_us(ref_clk, nr); ut = ud * CCU_PLL_LOCK_CHECK_RETRIES; regmap_update_bits(pll->sys_regs, pll->reg_ctl, CCU_PLL_CTL_RST, CCU_PLL_CTL_RST); return regmap_read_poll_timeout_atomic(pll->sys_regs, pll->reg_ctl, val, val & CCU_PLL_CTL_LOCK, ud, ut); } static int ccu_pll_enable(struct clk_hw *hw) { struct clk_hw *parent_hw = clk_hw_get_parent(hw); struct ccu_pll *pll = to_ccu_pll(hw); unsigned long flags; u32 val = 0; int ret; if (!parent_hw) { pr_err("Can't enable '%s' with no parent", clk_hw_get_name(hw)); return -EINVAL; } regmap_read(pll->sys_regs, pll->reg_ctl, &val); if (val & CCU_PLL_CTL_EN) return 0; spin_lock_irqsave(&pll->lock, flags); regmap_write(pll->sys_regs, pll->reg_ctl, val | CCU_PLL_CTL_EN); ret = ccu_pll_reset(pll, clk_hw_get_rate(parent_hw), FIELD_GET(CCU_PLL_CTL_CLKR_MASK, val) + 1); spin_unlock_irqrestore(&pll->lock, flags); if (ret) pr_err("PLL '%s' reset timed out\n", clk_hw_get_name(hw)); return ret; } static void ccu_pll_disable(struct clk_hw *hw) { struct ccu_pll *pll = to_ccu_pll(hw); unsigned long flags; spin_lock_irqsave(&pll->lock, flags); regmap_update_bits(pll->sys_regs, pll->reg_ctl, CCU_PLL_CTL_EN, 0); spin_unlock_irqrestore(&pll->lock, flags); } static int ccu_pll_is_enabled(struct clk_hw *hw) { struct ccu_pll *pll = to_ccu_pll(hw); u32 val = 0; regmap_read(pll->sys_regs, pll->reg_ctl, &val); return !!(val & CCU_PLL_CTL_EN); } static unsigned long ccu_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct ccu_pll *pll = to_ccu_pll(hw); unsigned long nr, nf, od; u32 val = 0; regmap_read(pll->sys_regs, pll->reg_ctl, &val); nr = FIELD_GET(CCU_PLL_CTL_CLKR_MASK, val) + 1; nf = FIELD_GET(CCU_PLL_CTL_CLKF_MASK, val) + 1; od = FIELD_GET(CCU_PLL_CTL_CLKOD_MASK, val) + 1; return ccu_pll_calc_freq(parent_rate, nr, nf, od); } static void ccu_pll_calc_factors(unsigned long rate, unsigned long parent_rate, unsigned long *nr, unsigned long *nf, unsigned long *od) { unsigned long err, freq, min_err = ULONG_MAX; unsigned long num, denom, n1, d1, nri; unsigned long nr_max, nf_max, od_max; /* * Make sure PLL is working with valid input signal (Fdiv). If * you want to speed the function up just reduce CCU_PLL_NR_MAX. * This will cause a worse approximation though. */ nri = (parent_rate / CCU_PLL_FDIV_MAX) + 1; nr_max = min(parent_rate / CCU_PLL_FDIV_MIN, CCU_PLL_NR_MAX); /* * Find a closest [nr;nf;od] vector taking into account the * limitations like: 1) 700MHz <= Fvco <= 3.5GHz, 2) PLL Od is * either 1 or even number within the acceptable range (alas 1s * is also excluded by the next loop). */ for (; nri <= nr_max; ++nri) { /* Use Od factor to fulfill the limitation 2). */ num = CCU_PLL_CLKOD_FACTOR * rate; denom = parent_rate / nri; /* * Make sure Fvco is within the acceptable range to fulfill * the condition 1). Note due to the CCU_PLL_CLKOD_FACTOR value * the actual upper limit is also divided by that factor. * It's not big problem for us since practically there is no * need in clocks with that high frequency. */ nf_max = min(CCU_PLL_FVCO_MAX / denom, CCU_PLL_NF_MAX); od_max = CCU_PLL_OD_MAX / CCU_PLL_CLKOD_FACTOR; /* * Bypass the out-of-bound values, which can't be properly * handled by the rational fraction approximation algorithm. */ if (num / denom >= nf_max) { n1 = nf_max; d1 = 1; } else if (denom / num >= od_max) { n1 = 1; d1 = od_max; } else { rational_best_approximation(num, denom, nf_max, od_max, &n1, &d1); } /* Select the best approximation of the target rate. */ freq = ccu_pll_calc_freq(parent_rate, nri, n1, d1); err = abs((int64_t)freq - num); if (err < min_err) { min_err = err; *nr = nri; *nf = n1; *od = CCU_PLL_CLKOD_FACTOR * d1; } } } static long ccu_pll_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { unsigned long nr = 1, nf = 1, od = 1; ccu_pll_calc_factors(rate, *parent_rate, &nr, &nf, &od); return ccu_pll_calc_freq(*parent_rate, nr, nf, od); } /* * This method is used for PLLs, which support the on-the-fly dividers * adjustment. So there is no need in gating such clocks. */ static int ccu_pll_set_rate_reset(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct ccu_pll *pll = to_ccu_pll(hw); unsigned long nr, nf, od; unsigned long flags; u32 mask, val; int ret; ccu_pll_calc_factors(rate, parent_rate, &nr, &nf, &od); mask = CCU_PLL_CTL_CLKR_MASK | CCU_PLL_CTL_CLKF_MASK | CCU_PLL_CTL_CLKOD_MASK; val = FIELD_PREP(CCU_PLL_CTL_CLKR_MASK, nr - 1) | FIELD_PREP(CCU_PLL_CTL_CLKF_MASK, nf - 1) | FIELD_PREP(CCU_PLL_CTL_CLKOD_MASK, od - 1); spin_lock_irqsave(&pll->lock, flags); regmap_update_bits(pll->sys_regs, pll->reg_ctl, mask, val); ret = ccu_pll_reset(pll, parent_rate, nr); spin_unlock_irqrestore(&pll->lock, flags); if (ret) pr_err("PLL '%s' reset timed out\n", clk_hw_get_name(hw)); return ret; } /* * This method is used for PLLs, which don't support the on-the-fly dividers * adjustment. So the corresponding clocks are supposed to be gated first. */ static int ccu_pll_set_rate_norst(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct ccu_pll *pll = to_ccu_pll(hw); unsigned long nr, nf, od; unsigned long flags; u32 mask, val; ccu_pll_calc_factors(rate, parent_rate, &nr, &nf, &od); /* * Disable PLL if it was enabled by default or left enabled by the * system bootloader. */ mask = CCU_PLL_CTL_CLKR_MASK | CCU_PLL_CTL_CLKF_MASK | CCU_PLL_CTL_CLKOD_MASK | CCU_PLL_CTL_EN; val = FIELD_PREP(CCU_PLL_CTL_CLKR_MASK, nr - 1) | FIELD_PREP(CCU_PLL_CTL_CLKF_MASK, nf - 1) | FIELD_PREP(CCU_PLL_CTL_CLKOD_MASK, od - 1); spin_lock_irqsave(&pll->lock, flags); regmap_update_bits(pll->sys_regs, pll->reg_ctl, mask, val); spin_unlock_irqrestore(&pll->lock, flags); return 0; } #ifdef CONFIG_DEBUG_FS struct ccu_pll_dbgfs_bit { struct ccu_pll *pll; const char *name; unsigned int reg; u32 mask; }; struct ccu_pll_dbgfs_fld { struct ccu_pll *pll; const char *name; unsigned int reg; unsigned int lsb; u32 mask; u32 min; u32 max; }; #define CCU_PLL_DBGFS_BIT_ATTR(_name, _reg, _mask) \ { \ .name = _name, \ .reg = _reg, \ .mask = _mask \ } #define CCU_PLL_DBGFS_FLD_ATTR(_name, _reg, _lsb, _mask, _min, _max) \ { \ .name = _name, \ .reg = _reg, \ .lsb = _lsb, \ .mask = _mask, \ .min = _min, \ .max = _max \ } static const struct ccu_pll_dbgfs_bit ccu_pll_bits[] = { CCU_PLL_DBGFS_BIT_ATTR("pll_en", CCU_PLL_CTL, CCU_PLL_CTL_EN), CCU_PLL_DBGFS_BIT_ATTR("pll_rst", CCU_PLL_CTL, CCU_PLL_CTL_RST), CCU_PLL_DBGFS_BIT_ATTR("pll_bypass", CCU_PLL_CTL, CCU_PLL_CTL_BYPASS), CCU_PLL_DBGFS_BIT_ATTR("pll_lock", CCU_PLL_CTL, CCU_PLL_CTL_LOCK) }; #define CCU_PLL_DBGFS_BIT_NUM ARRAY_SIZE(ccu_pll_bits) static const struct ccu_pll_dbgfs_fld ccu_pll_flds[] = { CCU_PLL_DBGFS_FLD_ATTR("pll_nr", CCU_PLL_CTL, CCU_PLL_CTL_CLKR_FLD, CCU_PLL_CTL_CLKR_MASK, 1, CCU_PLL_NR_MAX), CCU_PLL_DBGFS_FLD_ATTR("pll_nf", CCU_PLL_CTL, CCU_PLL_CTL_CLKF_FLD, CCU_PLL_CTL_CLKF_MASK, 1, CCU_PLL_NF_MAX), CCU_PLL_DBGFS_FLD_ATTR("pll_od", CCU_PLL_CTL, CCU_PLL_CTL_CLKOD_FLD, CCU_PLL_CTL_CLKOD_MASK, 1, CCU_PLL_OD_MAX), CCU_PLL_DBGFS_FLD_ATTR("pll_nb", CCU_PLL_CTL1, CCU_PLL_CTL1_BWADJ_FLD, CCU_PLL_CTL1_BWADJ_MASK, 1, CCU_PLL_NB_MAX) }; #define CCU_PLL_DBGFS_FLD_NUM ARRAY_SIZE(ccu_pll_flds) /* * It can be dangerous to change the PLL settings behind clock framework back, * therefore we don't provide any kernel config based compile time option for * this feature to enable. */ #undef CCU_PLL_ALLOW_WRITE_DEBUGFS #ifdef CCU_PLL_ALLOW_WRITE_DEBUGFS static int ccu_pll_dbgfs_bit_set(void *priv, u64 val) { const struct ccu_pll_dbgfs_bit *bit = priv; struct ccu_pll *pll = bit->pll; unsigned long flags; spin_lock_irqsave(&pll->lock, flags); regmap_update_bits(pll->sys_regs, pll->reg_ctl + bit->reg, bit->mask, val ? bit->mask : 0); spin_unlock_irqrestore(&pll->lock, flags); return 0; } static int ccu_pll_dbgfs_fld_set(void *priv, u64 val) { struct ccu_pll_dbgfs_fld *fld = priv; struct ccu_pll *pll = fld->pll; unsigned long flags; u32 data; val = clamp_t(u64, val, fld->min, fld->max); data = ((val - 1) << fld->lsb) & fld->mask; spin_lock_irqsave(&pll->lock, flags); regmap_update_bits(pll->sys_regs, pll->reg_ctl + fld->reg, fld->mask, data); spin_unlock_irqrestore(&pll->lock, flags); return 0; } #define ccu_pll_dbgfs_mode 0644 #else /* !CCU_PLL_ALLOW_WRITE_DEBUGFS */ #define ccu_pll_dbgfs_bit_set NULL #define ccu_pll_dbgfs_fld_set NULL #define ccu_pll_dbgfs_mode 0444 #endif /* !CCU_PLL_ALLOW_WRITE_DEBUGFS */ static int ccu_pll_dbgfs_bit_get(void *priv, u64 *val) { struct ccu_pll_dbgfs_bit *bit = priv; struct ccu_pll *pll = bit->pll; u32 data = 0; regmap_read(pll->sys_regs, pll->reg_ctl + bit->reg, &data); *val = !!(data & bit->mask); return 0; } DEFINE_DEBUGFS_ATTRIBUTE(ccu_pll_dbgfs_bit_fops, ccu_pll_dbgfs_bit_get, ccu_pll_dbgfs_bit_set, "%llu\n"); static int ccu_pll_dbgfs_fld_get(void *priv, u64 *val) { struct ccu_pll_dbgfs_fld *fld = priv; struct ccu_pll *pll = fld->pll; u32 data = 0; regmap_read(pll->sys_regs, pll->reg_ctl + fld->reg, &data); *val = ((data & fld->mask) >> fld->lsb) + 1; return 0; } DEFINE_DEBUGFS_ATTRIBUTE(ccu_pll_dbgfs_fld_fops, ccu_pll_dbgfs_fld_get, ccu_pll_dbgfs_fld_set, "%llu\n"); static void ccu_pll_debug_init(struct clk_hw *hw, struct dentry *dentry) { struct ccu_pll *pll = to_ccu_pll(hw); struct ccu_pll_dbgfs_bit *bits; struct ccu_pll_dbgfs_fld *flds; int idx; bits = kcalloc(CCU_PLL_DBGFS_BIT_NUM, sizeof(*bits), GFP_KERNEL); if (!bits) return; for (idx = 0; idx < CCU_PLL_DBGFS_BIT_NUM; ++idx) { bits[idx] = ccu_pll_bits[idx]; bits[idx].pll = pll; debugfs_create_file_unsafe(bits[idx].name, ccu_pll_dbgfs_mode, dentry, &bits[idx], &ccu_pll_dbgfs_bit_fops); } flds = kcalloc(CCU_PLL_DBGFS_FLD_NUM, sizeof(*flds), GFP_KERNEL); if (!flds) return; for (idx = 0; idx < CCU_PLL_DBGFS_FLD_NUM; ++idx) { flds[idx] = ccu_pll_flds[idx]; flds[idx].pll = pll; debugfs_create_file_unsafe(flds[idx].name, ccu_pll_dbgfs_mode, dentry, &flds[idx], &ccu_pll_dbgfs_fld_fops); } } #else /* !CONFIG_DEBUG_FS */ #define ccu_pll_debug_init NULL #endif /* !CONFIG_DEBUG_FS */ static const struct clk_ops ccu_pll_gate_to_set_ops = { .enable = ccu_pll_enable, .disable = ccu_pll_disable, .is_enabled = ccu_pll_is_enabled, .recalc_rate = ccu_pll_recalc_rate, .round_rate = ccu_pll_round_rate, .set_rate = ccu_pll_set_rate_norst, .debug_init = ccu_pll_debug_init }; static const struct clk_ops ccu_pll_straight_set_ops = { .enable = ccu_pll_enable, .disable = ccu_pll_disable, .is_enabled = ccu_pll_is_enabled, .recalc_rate = ccu_pll_recalc_rate, .round_rate = ccu_pll_round_rate, .set_rate = ccu_pll_set_rate_reset, .debug_init = ccu_pll_debug_init }; struct ccu_pll *ccu_pll_hw_register(const struct ccu_pll_init_data *pll_init) { struct clk_parent_data parent_data = { }; struct clk_init_data hw_init = { }; struct ccu_pll *pll; int ret; if (!pll_init) return ERR_PTR(-EINVAL); pll = kzalloc(sizeof(*pll), GFP_KERNEL); if (!pll) return ERR_PTR(-ENOMEM); /* * Note since Baikal-T1 System Controller registers are MMIO-backed * we won't check the regmap IO operations return status, because it * must be zero anyway. */ pll->hw.init = &hw_init; pll->reg_ctl = pll_init->base + CCU_PLL_CTL; pll->reg_ctl1 = pll_init->base + CCU_PLL_CTL1; pll->sys_regs = pll_init->sys_regs; pll->id = pll_init->id; spin_lock_init(&pll->lock); hw_init.name = pll_init->name; hw_init.flags = pll_init->flags; if (hw_init.flags & CLK_SET_RATE_GATE) hw_init.ops = &ccu_pll_gate_to_set_ops; else hw_init.ops = &ccu_pll_straight_set_ops; if (!pll_init->parent_name) { ret = -EINVAL; goto err_free_pll; } parent_data.fw_name = pll_init->parent_name; hw_init.parent_data = &parent_data; hw_init.num_parents = 1; ret = of_clk_hw_register(pll_init->np, &pll->hw); if (ret) goto err_free_pll; return pll; err_free_pll: kfree(pll); return ERR_PTR(ret); } void ccu_pll_hw_unregister(struct ccu_pll *pll) { clk_hw_unregister(&pll->hw); kfree(pll); }
linux-master
drivers/clk/baikal-t1/ccu-pll.c
// SPDX-License-Identifier: GPL-2.0-only /* * Zynq clock controller * * Copyright (C) 2012 - 2013 Xilinx * * Sören Brinkmann <[email protected]> */ #include <linux/clk/zynq.h> #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/io.h> static void __iomem *zynq_clkc_base; #define SLCR_ARMPLL_CTRL (zynq_clkc_base + 0x00) #define SLCR_DDRPLL_CTRL (zynq_clkc_base + 0x04) #define SLCR_IOPLL_CTRL (zynq_clkc_base + 0x08) #define SLCR_PLL_STATUS (zynq_clkc_base + 0x0c) #define SLCR_ARM_CLK_CTRL (zynq_clkc_base + 0x20) #define SLCR_DDR_CLK_CTRL (zynq_clkc_base + 0x24) #define SLCR_DCI_CLK_CTRL (zynq_clkc_base + 0x28) #define SLCR_APER_CLK_CTRL (zynq_clkc_base + 0x2c) #define SLCR_GEM0_CLK_CTRL (zynq_clkc_base + 0x40) #define SLCR_GEM1_CLK_CTRL (zynq_clkc_base + 0x44) #define SLCR_SMC_CLK_CTRL (zynq_clkc_base + 0x48) #define SLCR_LQSPI_CLK_CTRL (zynq_clkc_base + 0x4c) #define SLCR_SDIO_CLK_CTRL (zynq_clkc_base + 0x50) #define SLCR_UART_CLK_CTRL (zynq_clkc_base + 0x54) #define SLCR_SPI_CLK_CTRL (zynq_clkc_base + 0x58) #define SLCR_CAN_CLK_CTRL (zynq_clkc_base + 0x5c) #define SLCR_CAN_MIOCLK_CTRL (zynq_clkc_base + 0x60) #define SLCR_DBG_CLK_CTRL (zynq_clkc_base + 0x64) #define SLCR_PCAP_CLK_CTRL (zynq_clkc_base + 0x68) #define SLCR_FPGA0_CLK_CTRL (zynq_clkc_base + 0x70) #define SLCR_621_TRUE (zynq_clkc_base + 0xc4) #define SLCR_SWDT_CLK_SEL (zynq_clkc_base + 0x204) #define NUM_MIO_PINS 54 #define DBG_CLK_CTRL_CLKACT_TRC BIT(0) #define DBG_CLK_CTRL_CPU_1XCLKACT BIT(1) enum zynq_clk { armpll, ddrpll, iopll, cpu_6or4x, cpu_3or2x, cpu_2x, cpu_1x, ddr2x, ddr3x, dci, lqspi, smc, pcap, gem0, gem1, fclk0, fclk1, fclk2, fclk3, can0, can1, sdio0, sdio1, uart0, uart1, spi0, spi1, dma, usb0_aper, usb1_aper, gem0_aper, gem1_aper, sdio0_aper, sdio1_aper, spi0_aper, spi1_aper, can0_aper, can1_aper, i2c0_aper, i2c1_aper, uart0_aper, uart1_aper, gpio_aper, lqspi_aper, smc_aper, swdt, dbg_trc, dbg_apb, clk_max}; static struct clk *ps_clk; static struct clk *clks[clk_max]; static struct clk_onecell_data clk_data; static DEFINE_SPINLOCK(armpll_lock); static DEFINE_SPINLOCK(ddrpll_lock); static DEFINE_SPINLOCK(iopll_lock); static DEFINE_SPINLOCK(armclk_lock); static DEFINE_SPINLOCK(swdtclk_lock); static DEFINE_SPINLOCK(ddrclk_lock); static DEFINE_SPINLOCK(dciclk_lock); static DEFINE_SPINLOCK(gem0clk_lock); static DEFINE_SPINLOCK(gem1clk_lock); static DEFINE_SPINLOCK(canclk_lock); static DEFINE_SPINLOCK(canmioclk_lock); static DEFINE_SPINLOCK(dbgclk_lock); static DEFINE_SPINLOCK(aperclk_lock); static const char *const armpll_parents[] __initconst = {"armpll_int", "ps_clk"}; static const char *const ddrpll_parents[] __initconst = {"ddrpll_int", "ps_clk"}; static const char *const iopll_parents[] __initconst = {"iopll_int", "ps_clk"}; static const char *gem0_mux_parents[] __initdata = {"gem0_div1", "dummy_name"}; static const char *gem1_mux_parents[] __initdata = {"gem1_div1", "dummy_name"}; static const char *const can0_mio_mux2_parents[] __initconst = {"can0_gate", "can0_mio_mux"}; static const char *const can1_mio_mux2_parents[] __initconst = {"can1_gate", "can1_mio_mux"}; static const char *dbg_emio_mux_parents[] __initdata = {"dbg_div", "dummy_name"}; static const char *const dbgtrc_emio_input_names[] __initconst = { "trace_emio_clk"}; static const char *const gem0_emio_input_names[] __initconst = { "gem0_emio_clk"}; static const char *const gem1_emio_input_names[] __initconst = { "gem1_emio_clk"}; static const char *const swdt_ext_clk_input_names[] __initconst = { "swdt_ext_clk"}; static void __init zynq_clk_register_fclk(enum zynq_clk fclk, const char *clk_name, void __iomem *fclk_ctrl_reg, const char **parents, int enable) { u32 enable_reg; char *mux_name; char *div0_name; char *div1_name; spinlock_t *fclk_lock; spinlock_t *fclk_gate_lock; void __iomem *fclk_gate_reg = fclk_ctrl_reg + 8; fclk_lock = kmalloc(sizeof(*fclk_lock), GFP_KERNEL); if (!fclk_lock) goto err; fclk_gate_lock = kmalloc(sizeof(*fclk_gate_lock), GFP_KERNEL); if (!fclk_gate_lock) goto err_fclk_gate_lock; spin_lock_init(fclk_lock); spin_lock_init(fclk_gate_lock); mux_name = kasprintf(GFP_KERNEL, "%s_mux", clk_name); if (!mux_name) goto err_mux_name; div0_name = kasprintf(GFP_KERNEL, "%s_div0", clk_name); if (!div0_name) goto err_div0_name; div1_name = kasprintf(GFP_KERNEL, "%s_div1", clk_name); if (!div1_name) goto err_div1_name; clk_register_mux(NULL, mux_name, parents, 4, CLK_SET_RATE_NO_REPARENT, fclk_ctrl_reg, 4, 2, 0, fclk_lock); clk_register_divider(NULL, div0_name, mux_name, 0, fclk_ctrl_reg, 8, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, fclk_lock); clk_register_divider(NULL, div1_name, div0_name, CLK_SET_RATE_PARENT, fclk_ctrl_reg, 20, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, fclk_lock); clks[fclk] = clk_register_gate(NULL, clk_name, div1_name, CLK_SET_RATE_PARENT, fclk_gate_reg, 0, CLK_GATE_SET_TO_DISABLE, fclk_gate_lock); enable_reg = readl(fclk_gate_reg) & 1; if (enable && !enable_reg) { if (clk_prepare_enable(clks[fclk])) pr_warn("%s: FCLK%u enable failed\n", __func__, fclk - fclk0); } kfree(mux_name); kfree(div0_name); kfree(div1_name); return; err_div1_name: kfree(div0_name); err_div0_name: kfree(mux_name); err_mux_name: kfree(fclk_gate_lock); err_fclk_gate_lock: kfree(fclk_lock); err: clks[fclk] = ERR_PTR(-ENOMEM); } static void __init zynq_clk_register_periph_clk(enum zynq_clk clk0, enum zynq_clk clk1, const char *clk_name0, const char *clk_name1, void __iomem *clk_ctrl, const char **parents, unsigned int two_gates) { char *mux_name; char *div_name; spinlock_t *lock; lock = kmalloc(sizeof(*lock), GFP_KERNEL); if (!lock) goto err; spin_lock_init(lock); mux_name = kasprintf(GFP_KERNEL, "%s_mux", clk_name0); div_name = kasprintf(GFP_KERNEL, "%s_div", clk_name0); clk_register_mux(NULL, mux_name, parents, 4, CLK_SET_RATE_NO_REPARENT, clk_ctrl, 4, 2, 0, lock); clk_register_divider(NULL, div_name, mux_name, 0, clk_ctrl, 8, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, lock); clks[clk0] = clk_register_gate(NULL, clk_name0, div_name, CLK_SET_RATE_PARENT, clk_ctrl, 0, 0, lock); if (two_gates) clks[clk1] = clk_register_gate(NULL, clk_name1, div_name, CLK_SET_RATE_PARENT, clk_ctrl, 1, 0, lock); kfree(mux_name); kfree(div_name); return; err: clks[clk0] = ERR_PTR(-ENOMEM); if (two_gates) clks[clk1] = ERR_PTR(-ENOMEM); } static void __init zynq_clk_setup(struct device_node *np) { int i; u32 tmp; int ret; char *clk_name; unsigned int fclk_enable = 0; const char *clk_output_name[clk_max]; const char *cpu_parents[4]; const char *periph_parents[4]; const char *swdt_ext_clk_mux_parents[2]; const char *can_mio_mux_parents[NUM_MIO_PINS]; const char *dummy_nm = "dummy_name"; pr_info("Zynq clock init\n"); /* get clock output names from DT */ for (i = 0; i < clk_max; i++) { if (of_property_read_string_index(np, "clock-output-names", i, &clk_output_name[i])) { pr_err("%s: clock output name not in DT\n", __func__); BUG(); } } cpu_parents[0] = clk_output_name[armpll]; cpu_parents[1] = clk_output_name[armpll]; cpu_parents[2] = clk_output_name[ddrpll]; cpu_parents[3] = clk_output_name[iopll]; periph_parents[0] = clk_output_name[iopll]; periph_parents[1] = clk_output_name[iopll]; periph_parents[2] = clk_output_name[armpll]; periph_parents[3] = clk_output_name[ddrpll]; of_property_read_u32(np, "fclk-enable", &fclk_enable); /* ps_clk */ ret = of_property_read_u32(np, "ps-clk-frequency", &tmp); if (ret) { pr_warn("ps_clk frequency not specified, using 33 MHz.\n"); tmp = 33333333; } ps_clk = clk_register_fixed_rate(NULL, "ps_clk", NULL, 0, tmp); /* PLLs */ clk_register_zynq_pll("armpll_int", "ps_clk", SLCR_ARMPLL_CTRL, SLCR_PLL_STATUS, 0, &armpll_lock); clks[armpll] = clk_register_mux(NULL, clk_output_name[armpll], armpll_parents, 2, CLK_SET_RATE_NO_REPARENT, SLCR_ARMPLL_CTRL, 4, 1, 0, &armpll_lock); clk_register_zynq_pll("ddrpll_int", "ps_clk", SLCR_DDRPLL_CTRL, SLCR_PLL_STATUS, 1, &ddrpll_lock); clks[ddrpll] = clk_register_mux(NULL, clk_output_name[ddrpll], ddrpll_parents, 2, CLK_SET_RATE_NO_REPARENT, SLCR_DDRPLL_CTRL, 4, 1, 0, &ddrpll_lock); clk_register_zynq_pll("iopll_int", "ps_clk", SLCR_IOPLL_CTRL, SLCR_PLL_STATUS, 2, &iopll_lock); clks[iopll] = clk_register_mux(NULL, clk_output_name[iopll], iopll_parents, 2, CLK_SET_RATE_NO_REPARENT, SLCR_IOPLL_CTRL, 4, 1, 0, &iopll_lock); /* CPU clocks */ tmp = readl(SLCR_621_TRUE) & 1; clk_register_mux(NULL, "cpu_mux", cpu_parents, 4, CLK_SET_RATE_NO_REPARENT, SLCR_ARM_CLK_CTRL, 4, 2, 0, &armclk_lock); clk_register_divider(NULL, "cpu_div", "cpu_mux", 0, SLCR_ARM_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &armclk_lock); clks[cpu_6or4x] = clk_register_gate(NULL, clk_output_name[cpu_6or4x], "cpu_div", CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, SLCR_ARM_CLK_CTRL, 24, 0, &armclk_lock); clk_register_fixed_factor(NULL, "cpu_3or2x_div", "cpu_div", 0, 1, 2); clks[cpu_3or2x] = clk_register_gate(NULL, clk_output_name[cpu_3or2x], "cpu_3or2x_div", CLK_IGNORE_UNUSED, SLCR_ARM_CLK_CTRL, 25, 0, &armclk_lock); clk_register_fixed_factor(NULL, "cpu_2x_div", "cpu_div", 0, 1, 2 + tmp); clks[cpu_2x] = clk_register_gate(NULL, clk_output_name[cpu_2x], "cpu_2x_div", CLK_IGNORE_UNUSED, SLCR_ARM_CLK_CTRL, 26, 0, &armclk_lock); clk_prepare_enable(clks[cpu_2x]); clk_register_fixed_factor(NULL, "cpu_1x_div", "cpu_div", 0, 1, 4 + 2 * tmp); clks[cpu_1x] = clk_register_gate(NULL, clk_output_name[cpu_1x], "cpu_1x_div", CLK_IGNORE_UNUSED, SLCR_ARM_CLK_CTRL, 27, 0, &armclk_lock); /* Timers */ swdt_ext_clk_mux_parents[0] = clk_output_name[cpu_1x]; for (i = 0; i < ARRAY_SIZE(swdt_ext_clk_input_names); i++) { int idx = of_property_match_string(np, "clock-names", swdt_ext_clk_input_names[i]); if (idx >= 0) swdt_ext_clk_mux_parents[i + 1] = of_clk_get_parent_name(np, idx); else swdt_ext_clk_mux_parents[i + 1] = dummy_nm; } clks[swdt] = clk_register_mux(NULL, clk_output_name[swdt], swdt_ext_clk_mux_parents, 2, CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, SLCR_SWDT_CLK_SEL, 0, 1, 0, &swdtclk_lock); /* DDR clocks */ clk_register_divider(NULL, "ddr2x_div", "ddrpll", 0, SLCR_DDR_CLK_CTRL, 26, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &ddrclk_lock); clks[ddr2x] = clk_register_gate(NULL, clk_output_name[ddr2x], "ddr2x_div", 0, SLCR_DDR_CLK_CTRL, 1, 0, &ddrclk_lock); clk_prepare_enable(clks[ddr2x]); clk_register_divider(NULL, "ddr3x_div", "ddrpll", 0, SLCR_DDR_CLK_CTRL, 20, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &ddrclk_lock); clks[ddr3x] = clk_register_gate(NULL, clk_output_name[ddr3x], "ddr3x_div", 0, SLCR_DDR_CLK_CTRL, 0, 0, &ddrclk_lock); clk_prepare_enable(clks[ddr3x]); clk_register_divider(NULL, "dci_div0", "ddrpll", 0, SLCR_DCI_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &dciclk_lock); clk_register_divider(NULL, "dci_div1", "dci_div0", CLK_SET_RATE_PARENT, SLCR_DCI_CLK_CTRL, 20, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &dciclk_lock); clks[dci] = clk_register_gate(NULL, clk_output_name[dci], "dci_div1", CLK_SET_RATE_PARENT, SLCR_DCI_CLK_CTRL, 0, 0, &dciclk_lock); clk_prepare_enable(clks[dci]); /* Peripheral clocks */ for (i = fclk0; i <= fclk3; i++) { int enable = !!(fclk_enable & BIT(i - fclk0)); zynq_clk_register_fclk(i, clk_output_name[i], SLCR_FPGA0_CLK_CTRL + 0x10 * (i - fclk0), periph_parents, enable); } zynq_clk_register_periph_clk(lqspi, clk_max, clk_output_name[lqspi], NULL, SLCR_LQSPI_CLK_CTRL, periph_parents, 0); zynq_clk_register_periph_clk(smc, clk_max, clk_output_name[smc], NULL, SLCR_SMC_CLK_CTRL, periph_parents, 0); zynq_clk_register_periph_clk(pcap, clk_max, clk_output_name[pcap], NULL, SLCR_PCAP_CLK_CTRL, periph_parents, 0); zynq_clk_register_periph_clk(sdio0, sdio1, clk_output_name[sdio0], clk_output_name[sdio1], SLCR_SDIO_CLK_CTRL, periph_parents, 1); zynq_clk_register_periph_clk(uart0, uart1, clk_output_name[uart0], clk_output_name[uart1], SLCR_UART_CLK_CTRL, periph_parents, 1); zynq_clk_register_periph_clk(spi0, spi1, clk_output_name[spi0], clk_output_name[spi1], SLCR_SPI_CLK_CTRL, periph_parents, 1); for (i = 0; i < ARRAY_SIZE(gem0_emio_input_names); i++) { int idx = of_property_match_string(np, "clock-names", gem0_emio_input_names[i]); if (idx >= 0) gem0_mux_parents[i + 1] = of_clk_get_parent_name(np, idx); } clk_register_mux(NULL, "gem0_mux", periph_parents, 4, CLK_SET_RATE_NO_REPARENT, SLCR_GEM0_CLK_CTRL, 4, 2, 0, &gem0clk_lock); clk_register_divider(NULL, "gem0_div0", "gem0_mux", 0, SLCR_GEM0_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &gem0clk_lock); clk_register_divider(NULL, "gem0_div1", "gem0_div0", CLK_SET_RATE_PARENT, SLCR_GEM0_CLK_CTRL, 20, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &gem0clk_lock); clk_register_mux(NULL, "gem0_emio_mux", gem0_mux_parents, 2, CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, SLCR_GEM0_CLK_CTRL, 6, 1, 0, &gem0clk_lock); clks[gem0] = clk_register_gate(NULL, clk_output_name[gem0], "gem0_emio_mux", CLK_SET_RATE_PARENT, SLCR_GEM0_CLK_CTRL, 0, 0, &gem0clk_lock); for (i = 0; i < ARRAY_SIZE(gem1_emio_input_names); i++) { int idx = of_property_match_string(np, "clock-names", gem1_emio_input_names[i]); if (idx >= 0) gem1_mux_parents[i + 1] = of_clk_get_parent_name(np, idx); } clk_register_mux(NULL, "gem1_mux", periph_parents, 4, CLK_SET_RATE_NO_REPARENT, SLCR_GEM1_CLK_CTRL, 4, 2, 0, &gem1clk_lock); clk_register_divider(NULL, "gem1_div0", "gem1_mux", 0, SLCR_GEM1_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &gem1clk_lock); clk_register_divider(NULL, "gem1_div1", "gem1_div0", CLK_SET_RATE_PARENT, SLCR_GEM1_CLK_CTRL, 20, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &gem1clk_lock); clk_register_mux(NULL, "gem1_emio_mux", gem1_mux_parents, 2, CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, SLCR_GEM1_CLK_CTRL, 6, 1, 0, &gem1clk_lock); clks[gem1] = clk_register_gate(NULL, clk_output_name[gem1], "gem1_emio_mux", CLK_SET_RATE_PARENT, SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock); tmp = strlen("mio_clk_00x"); clk_name = kmalloc(tmp, GFP_KERNEL); for (i = 0; i < NUM_MIO_PINS; i++) { int idx; snprintf(clk_name, tmp, "mio_clk_%2.2d", i); idx = of_property_match_string(np, "clock-names", clk_name); if (idx >= 0) can_mio_mux_parents[i] = of_clk_get_parent_name(np, idx); else can_mio_mux_parents[i] = dummy_nm; } kfree(clk_name); clk_register_mux(NULL, "can_mux", periph_parents, 4, CLK_SET_RATE_NO_REPARENT, SLCR_CAN_CLK_CTRL, 4, 2, 0, &canclk_lock); clk_register_divider(NULL, "can_div0", "can_mux", 0, SLCR_CAN_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &canclk_lock); clk_register_divider(NULL, "can_div1", "can_div0", CLK_SET_RATE_PARENT, SLCR_CAN_CLK_CTRL, 20, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &canclk_lock); clk_register_gate(NULL, "can0_gate", "can_div1", CLK_SET_RATE_PARENT, SLCR_CAN_CLK_CTRL, 0, 0, &canclk_lock); clk_register_gate(NULL, "can1_gate", "can_div1", CLK_SET_RATE_PARENT, SLCR_CAN_CLK_CTRL, 1, 0, &canclk_lock); clk_register_mux(NULL, "can0_mio_mux", can_mio_mux_parents, 54, CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, SLCR_CAN_MIOCLK_CTRL, 0, 6, 0, &canmioclk_lock); clk_register_mux(NULL, "can1_mio_mux", can_mio_mux_parents, 54, CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, SLCR_CAN_MIOCLK_CTRL, 16, 6, 0, &canmioclk_lock); clks[can0] = clk_register_mux(NULL, clk_output_name[can0], can0_mio_mux2_parents, 2, CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, SLCR_CAN_MIOCLK_CTRL, 6, 1, 0, &canmioclk_lock); clks[can1] = clk_register_mux(NULL, clk_output_name[can1], can1_mio_mux2_parents, 2, CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, SLCR_CAN_MIOCLK_CTRL, 22, 1, 0, &canmioclk_lock); for (i = 0; i < ARRAY_SIZE(dbgtrc_emio_input_names); i++) { int idx = of_property_match_string(np, "clock-names", dbgtrc_emio_input_names[i]); if (idx >= 0) dbg_emio_mux_parents[i + 1] = of_clk_get_parent_name(np, idx); } clk_register_mux(NULL, "dbg_mux", periph_parents, 4, CLK_SET_RATE_NO_REPARENT, SLCR_DBG_CLK_CTRL, 4, 2, 0, &dbgclk_lock); clk_register_divider(NULL, "dbg_div", "dbg_mux", 0, SLCR_DBG_CLK_CTRL, 8, 6, CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, &dbgclk_lock); clk_register_mux(NULL, "dbg_emio_mux", dbg_emio_mux_parents, 2, CLK_SET_RATE_NO_REPARENT, SLCR_DBG_CLK_CTRL, 6, 1, 0, &dbgclk_lock); clks[dbg_trc] = clk_register_gate(NULL, clk_output_name[dbg_trc], "dbg_emio_mux", CLK_SET_RATE_PARENT, SLCR_DBG_CLK_CTRL, 0, 0, &dbgclk_lock); clks[dbg_apb] = clk_register_gate(NULL, clk_output_name[dbg_apb], clk_output_name[cpu_1x], 0, SLCR_DBG_CLK_CTRL, 1, 0, &dbgclk_lock); /* leave debug clocks in the state the bootloader set them up to */ tmp = readl(SLCR_DBG_CLK_CTRL); if (tmp & DBG_CLK_CTRL_CLKACT_TRC) if (clk_prepare_enable(clks[dbg_trc])) pr_warn("%s: trace clk enable failed\n", __func__); if (tmp & DBG_CLK_CTRL_CPU_1XCLKACT) if (clk_prepare_enable(clks[dbg_apb])) pr_warn("%s: debug APB clk enable failed\n", __func__); /* One gated clock for all APER clocks. */ clks[dma] = clk_register_gate(NULL, clk_output_name[dma], clk_output_name[cpu_2x], 0, SLCR_APER_CLK_CTRL, 0, 0, &aperclk_lock); clks[usb0_aper] = clk_register_gate(NULL, clk_output_name[usb0_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 2, 0, &aperclk_lock); clks[usb1_aper] = clk_register_gate(NULL, clk_output_name[usb1_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 3, 0, &aperclk_lock); clks[gem0_aper] = clk_register_gate(NULL, clk_output_name[gem0_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 6, 0, &aperclk_lock); clks[gem1_aper] = clk_register_gate(NULL, clk_output_name[gem1_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 7, 0, &aperclk_lock); clks[sdio0_aper] = clk_register_gate(NULL, clk_output_name[sdio0_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 10, 0, &aperclk_lock); clks[sdio1_aper] = clk_register_gate(NULL, clk_output_name[sdio1_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 11, 0, &aperclk_lock); clks[spi0_aper] = clk_register_gate(NULL, clk_output_name[spi0_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 14, 0, &aperclk_lock); clks[spi1_aper] = clk_register_gate(NULL, clk_output_name[spi1_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 15, 0, &aperclk_lock); clks[can0_aper] = clk_register_gate(NULL, clk_output_name[can0_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 16, 0, &aperclk_lock); clks[can1_aper] = clk_register_gate(NULL, clk_output_name[can1_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 17, 0, &aperclk_lock); clks[i2c0_aper] = clk_register_gate(NULL, clk_output_name[i2c0_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 18, 0, &aperclk_lock); clks[i2c1_aper] = clk_register_gate(NULL, clk_output_name[i2c1_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 19, 0, &aperclk_lock); clks[uart0_aper] = clk_register_gate(NULL, clk_output_name[uart0_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 20, 0, &aperclk_lock); clks[uart1_aper] = clk_register_gate(NULL, clk_output_name[uart1_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 21, 0, &aperclk_lock); clks[gpio_aper] = clk_register_gate(NULL, clk_output_name[gpio_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 22, 0, &aperclk_lock); clks[lqspi_aper] = clk_register_gate(NULL, clk_output_name[lqspi_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 23, 0, &aperclk_lock); clks[smc_aper] = clk_register_gate(NULL, clk_output_name[smc_aper], clk_output_name[cpu_1x], 0, SLCR_APER_CLK_CTRL, 24, 0, &aperclk_lock); for (i = 0; i < ARRAY_SIZE(clks); i++) { if (IS_ERR(clks[i])) { pr_err("Zynq clk %d: register failed with %ld\n", i, PTR_ERR(clks[i])); BUG(); } } clk_data.clks = clks; clk_data.clk_num = ARRAY_SIZE(clks); of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data); } CLK_OF_DECLARE(zynq_clkc, "xlnx,ps7-clkc", zynq_clk_setup); void __init zynq_clock_init(void) { struct device_node *np; struct device_node *slcr; struct resource res; np = of_find_compatible_node(NULL, NULL, "xlnx,ps7-clkc"); if (!np) { pr_err("%s: clkc node not found\n", __func__); goto np_err; } if (of_address_to_resource(np, 0, &res)) { pr_err("%pOFn: failed to get resource\n", np); goto np_err; } slcr = of_get_parent(np); if (slcr->data) { zynq_clkc_base = (__force void __iomem *)slcr->data + res.start; } else { pr_err("%pOFn: Unable to get I/O memory\n", np); of_node_put(slcr); goto np_err; } pr_info("%s: clkc starts at %p\n", __func__, zynq_clkc_base); of_node_put(slcr); of_node_put(np); return; np_err: of_node_put(np); BUG(); }
linux-master
drivers/clk/zynq/clkc.c
// SPDX-License-Identifier: GPL-2.0-only /* * Zynq PLL driver * * Copyright (C) 2013 Xilinx * * Sören Brinkmann <[email protected]> */ #include <linux/clk/zynq.h> #include <linux/clk-provider.h> #include <linux/slab.h> #include <linux/io.h> /** * struct zynq_pll - pll clock * @hw: Handle between common and hardware-specific interfaces * @pll_ctrl: PLL control register * @pll_status: PLL status register * @lock: Register lock * @lockbit: Indicates the associated PLL_LOCKED bit in the PLL status * register. */ struct zynq_pll { struct clk_hw hw; void __iomem *pll_ctrl; void __iomem *pll_status; spinlock_t *lock; u8 lockbit; }; #define to_zynq_pll(_hw) container_of(_hw, struct zynq_pll, hw) /* Register bitfield defines */ #define PLLCTRL_FBDIV_MASK 0x7f000 #define PLLCTRL_FBDIV_SHIFT 12 #define PLLCTRL_BPQUAL_MASK (1 << 3) #define PLLCTRL_PWRDWN_MASK 2 #define PLLCTRL_PWRDWN_SHIFT 1 #define PLLCTRL_RESET_MASK 1 #define PLLCTRL_RESET_SHIFT 0 #define PLL_FBDIV_MIN 13 #define PLL_FBDIV_MAX 66 /** * zynq_pll_round_rate() - Round a clock frequency * @hw: Handle between common and hardware-specific interfaces * @rate: Desired clock frequency * @prate: Clock frequency of parent clock * Return: frequency closest to @rate the hardware can generate. */ static long zynq_pll_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { u32 fbdiv; fbdiv = DIV_ROUND_CLOSEST(rate, *prate); if (fbdiv < PLL_FBDIV_MIN) fbdiv = PLL_FBDIV_MIN; else if (fbdiv > PLL_FBDIV_MAX) fbdiv = PLL_FBDIV_MAX; return *prate * fbdiv; } /** * zynq_pll_recalc_rate() - Recalculate clock frequency * @hw: Handle between common and hardware-specific interfaces * @parent_rate: Clock frequency of parent clock * Return: current clock frequency. */ static unsigned long zynq_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct zynq_pll *clk = to_zynq_pll(hw); u32 fbdiv; /* * makes probably sense to redundantly save fbdiv in the struct * zynq_pll to save the IO access. */ fbdiv = (readl(clk->pll_ctrl) & PLLCTRL_FBDIV_MASK) >> PLLCTRL_FBDIV_SHIFT; return parent_rate * fbdiv; } /** * zynq_pll_is_enabled - Check if a clock is enabled * @hw: Handle between common and hardware-specific interfaces * Return: 1 if the clock is enabled, 0 otherwise. * * Not sure this is a good idea, but since disabled means bypassed for * this clock implementation we say we are always enabled. */ static int zynq_pll_is_enabled(struct clk_hw *hw) { unsigned long flags = 0; u32 reg; struct zynq_pll *clk = to_zynq_pll(hw); spin_lock_irqsave(clk->lock, flags); reg = readl(clk->pll_ctrl); spin_unlock_irqrestore(clk->lock, flags); return !(reg & (PLLCTRL_RESET_MASK | PLLCTRL_PWRDWN_MASK)); } /** * zynq_pll_enable - Enable clock * @hw: Handle between common and hardware-specific interfaces * Return: 0 on success */ static int zynq_pll_enable(struct clk_hw *hw) { unsigned long flags = 0; u32 reg; struct zynq_pll *clk = to_zynq_pll(hw); if (zynq_pll_is_enabled(hw)) return 0; pr_info("PLL: enable\n"); /* Power up PLL and wait for lock */ spin_lock_irqsave(clk->lock, flags); reg = readl(clk->pll_ctrl); reg &= ~(PLLCTRL_RESET_MASK | PLLCTRL_PWRDWN_MASK); writel(reg, clk->pll_ctrl); while (!(readl(clk->pll_status) & (1 << clk->lockbit))) ; spin_unlock_irqrestore(clk->lock, flags); return 0; } /** * zynq_pll_disable - Disable clock * @hw: Handle between common and hardware-specific interfaces * Returns 0 on success */ static void zynq_pll_disable(struct clk_hw *hw) { unsigned long flags = 0; u32 reg; struct zynq_pll *clk = to_zynq_pll(hw); if (!zynq_pll_is_enabled(hw)) return; pr_info("PLL: shutdown\n"); /* shut down PLL */ spin_lock_irqsave(clk->lock, flags); reg = readl(clk->pll_ctrl); reg |= PLLCTRL_RESET_MASK | PLLCTRL_PWRDWN_MASK; writel(reg, clk->pll_ctrl); spin_unlock_irqrestore(clk->lock, flags); } static const struct clk_ops zynq_pll_ops = { .enable = zynq_pll_enable, .disable = zynq_pll_disable, .is_enabled = zynq_pll_is_enabled, .round_rate = zynq_pll_round_rate, .recalc_rate = zynq_pll_recalc_rate }; /** * clk_register_zynq_pll() - Register PLL with the clock framework * @name: PLL name * @parent: Parent clock name * @pll_ctrl: Pointer to PLL control register * @pll_status: Pointer to PLL status register * @lock_index: Bit index to this PLL's lock status bit in @pll_status * @lock: Register lock * Return: handle to the registered clock. */ struct clk *clk_register_zynq_pll(const char *name, const char *parent, void __iomem *pll_ctrl, void __iomem *pll_status, u8 lock_index, spinlock_t *lock) { struct zynq_pll *pll; struct clk *clk; u32 reg; const char *parent_arr[1] = {parent}; unsigned long flags = 0; struct clk_init_data initd = { .name = name, .parent_names = parent_arr, .ops = &zynq_pll_ops, .num_parents = 1, .flags = 0 }; pll = kmalloc(sizeof(*pll), GFP_KERNEL); if (!pll) return ERR_PTR(-ENOMEM); /* Populate the struct */ pll->hw.init = &initd; pll->pll_ctrl = pll_ctrl; pll->pll_status = pll_status; pll->lockbit = lock_index; pll->lock = lock; spin_lock_irqsave(pll->lock, flags); reg = readl(pll->pll_ctrl); reg &= ~PLLCTRL_BPQUAL_MASK; writel(reg, pll->pll_ctrl); spin_unlock_irqrestore(pll->lock, flags); clk = clk_register(NULL, &pll->hw); if (WARN_ON(IS_ERR(clk))) goto free_pll; return clk; free_pll: kfree(pll); return clk; }
linux-master
drivers/clk/zynq/pll.c
// SPDX-License-Identifier: GPL-2.0-only /* * Utility functions for parsing Tegra CVB voltage tables * * Copyright (C) 2012-2019 NVIDIA Corporation. All rights reserved. */ #include <linux/err.h> #include <linux/kernel.h> #include <linux/pm_opp.h> #include "cvb.h" /* cvb_mv = ((c2 * speedo / s_scale + c1) * speedo / s_scale + c0) */ static inline int get_cvb_voltage(int speedo, int s_scale, const struct cvb_coefficients *cvb) { int mv; /* apply only speedo scale: output mv = cvb_mv * v_scale */ mv = DIV_ROUND_CLOSEST(cvb->c2 * speedo, s_scale); mv = DIV_ROUND_CLOSEST((mv + cvb->c1) * speedo, s_scale) + cvb->c0; return mv; } static int round_cvb_voltage(int mv, int v_scale, const struct rail_alignment *align) { /* combined: apply voltage scale and round to cvb alignment step */ int uv; int step = (align->step_uv ? : 1000) * v_scale; int offset = align->offset_uv * v_scale; uv = max(mv * 1000, offset) - offset; uv = DIV_ROUND_UP(uv, step) * align->step_uv + align->offset_uv; return uv / 1000; } enum { DOWN, UP }; static int round_voltage(int mv, const struct rail_alignment *align, int up) { if (align->step_uv) { int uv; uv = max(mv * 1000, align->offset_uv) - align->offset_uv; uv = (uv + (up ? align->step_uv - 1 : 0)) / align->step_uv; return (uv * align->step_uv + align->offset_uv) / 1000; } return mv; } static int build_opp_table(struct device *dev, const struct cvb_table *table, struct rail_alignment *align, int speedo_value, unsigned long max_freq) { int i, ret, dfll_mv, min_mv, max_mv; min_mv = round_voltage(table->min_millivolts, align, UP); max_mv = round_voltage(table->max_millivolts, align, DOWN); for (i = 0; i < MAX_DVFS_FREQS; i++) { const struct cvb_table_freq_entry *entry = &table->entries[i]; if (!entry->freq || (entry->freq > max_freq)) break; dfll_mv = get_cvb_voltage(speedo_value, table->speedo_scale, &entry->coefficients); dfll_mv = round_cvb_voltage(dfll_mv, table->voltage_scale, align); dfll_mv = clamp(dfll_mv, min_mv, max_mv); ret = dev_pm_opp_add(dev, entry->freq, dfll_mv * 1000); if (ret) return ret; } return 0; } /** * tegra_cvb_add_opp_table - build OPP table from Tegra CVB tables * @dev: the struct device * for which the OPP table is built * @tables: array of CVB tables * @count: size of the previously mentioned array * @align: parameters of the regulator step and offset * @process_id: process id of the HW module * @speedo_id: speedo id of the HW module * @speedo_value: speedo value of the HW module * @max_freq: highest safe clock rate * * On Tegra, a CVB table encodes the relationship between operating voltage * and safe maximal frequency for a given module (e.g. GPU or CPU). This * function calculates the optimal voltage-frequency operating points * for the given arguments and exports them via the OPP library for the * given @dev. Returns a pointer to the struct cvb_table that matched * or an ERR_PTR on failure. */ const struct cvb_table * tegra_cvb_add_opp_table(struct device *dev, const struct cvb_table *tables, size_t count, struct rail_alignment *align, int process_id, int speedo_id, int speedo_value, unsigned long max_freq) { size_t i; int ret; for (i = 0; i < count; i++) { const struct cvb_table *table = &tables[i]; if (table->speedo_id != -1 && table->speedo_id != speedo_id) continue; if (table->process_id != -1 && table->process_id != process_id) continue; ret = build_opp_table(dev, table, align, speedo_value, max_freq); return ret ? ERR_PTR(ret) : table; } return ERR_PTR(-EINVAL); } void tegra_cvb_remove_opp_table(struct device *dev, const struct cvb_table *table, unsigned long max_freq) { unsigned int i; for (i = 0; i < MAX_DVFS_FREQS; i++) { const struct cvb_table_freq_entry *entry = &table->entries[i]; if (!entry->freq || (entry->freq > max_freq)) break; dev_pm_opp_remove(dev, entry->freq); } }
linux-master
drivers/clk/tegra/cvb.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/clk-provider.h> #include <linux/clkdev.h> #include <linux/init.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/clk/tegra.h> #include <linux/delay.h> #include <dt-bindings/clock/tegra20-car.h> #include "clk.h" #include "clk-id.h" #define MISC_CLK_ENB 0x48 #define OSC_CTRL 0x50 #define OSC_CTRL_OSC_FREQ_MASK (3u<<30) #define OSC_CTRL_OSC_FREQ_13MHZ (0u<<30) #define OSC_CTRL_OSC_FREQ_19_2MHZ (1u<<30) #define OSC_CTRL_OSC_FREQ_12MHZ (2u<<30) #define OSC_CTRL_OSC_FREQ_26MHZ (3u<<30) #define OSC_CTRL_MASK (0x3f2u | OSC_CTRL_OSC_FREQ_MASK) #define OSC_CTRL_PLL_REF_DIV_MASK (3u<<28) #define OSC_CTRL_PLL_REF_DIV_1 (0u<<28) #define OSC_CTRL_PLL_REF_DIV_2 (1u<<28) #define OSC_CTRL_PLL_REF_DIV_4 (2u<<28) #define OSC_FREQ_DET 0x58 #define OSC_FREQ_DET_TRIG (1u<<31) #define OSC_FREQ_DET_STATUS 0x5c #define OSC_FREQ_DET_BUSYu (1<<31) #define OSC_FREQ_DET_CNT_MASK 0xFFFFu #define TEGRA20_CLK_PERIPH_BANKS 3 #define PLLS_BASE 0xf0 #define PLLS_MISC 0xf4 #define PLLC_BASE 0x80 #define PLLC_MISC 0x8c #define PLLM_BASE 0x90 #define PLLM_MISC 0x9c #define PLLP_BASE 0xa0 #define PLLP_MISC 0xac #define PLLA_BASE 0xb0 #define PLLA_MISC 0xbc #define PLLU_BASE 0xc0 #define PLLU_MISC 0xcc #define PLLD_BASE 0xd0 #define PLLD_MISC 0xdc #define PLLX_BASE 0xe0 #define PLLX_MISC 0xe4 #define PLLE_BASE 0xe8 #define PLLE_MISC 0xec #define PLL_BASE_LOCK BIT(27) #define PLLE_MISC_LOCK BIT(11) #define PLL_MISC_LOCK_ENABLE 18 #define PLLDU_MISC_LOCK_ENABLE 22 #define PLLE_MISC_LOCK_ENABLE 9 #define PLLC_OUT 0x84 #define PLLM_OUT 0x94 #define PLLP_OUTA 0xa4 #define PLLP_OUTB 0xa8 #define PLLA_OUT 0xb4 #define CCLK_BURST_POLICY 0x20 #define SUPER_CCLK_DIVIDER 0x24 #define SCLK_BURST_POLICY 0x28 #define SUPER_SCLK_DIVIDER 0x2c #define CLK_SYSTEM_RATE 0x30 #define CCLK_BURST_POLICY_SHIFT 28 #define CCLK_RUN_POLICY_SHIFT 4 #define CCLK_IDLE_POLICY_SHIFT 0 #define CCLK_IDLE_POLICY 1 #define CCLK_RUN_POLICY 2 #define CCLK_BURST_POLICY_PLLX 8 #define CLK_SOURCE_I2S1 0x100 #define CLK_SOURCE_I2S2 0x104 #define CLK_SOURCE_PWM 0x110 #define CLK_SOURCE_SPI 0x114 #define CLK_SOURCE_XIO 0x120 #define CLK_SOURCE_TWC 0x12c #define CLK_SOURCE_IDE 0x144 #define CLK_SOURCE_HDMI 0x18c #define CLK_SOURCE_DISP1 0x138 #define CLK_SOURCE_DISP2 0x13c #define CLK_SOURCE_CSITE 0x1d4 #define CLK_SOURCE_I2C1 0x124 #define CLK_SOURCE_I2C2 0x198 #define CLK_SOURCE_I2C3 0x1b8 #define CLK_SOURCE_DVC 0x128 #define CLK_SOURCE_UARTA 0x178 #define CLK_SOURCE_UARTB 0x17c #define CLK_SOURCE_UARTC 0x1a0 #define CLK_SOURCE_UARTD 0x1c0 #define CLK_SOURCE_UARTE 0x1c4 #define CLK_SOURCE_EMC 0x19c #define AUDIO_SYNC_CLK 0x38 /* Tegra CPU clock and reset control regs */ #define TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX 0x4c #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET 0x340 #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR 0x344 #define CPU_CLOCK(cpu) (0x1 << (8 + cpu)) #define CPU_RESET(cpu) (0x1111ul << (cpu)) #ifdef CONFIG_PM_SLEEP static struct cpu_clk_suspend_context { u32 pllx_misc; u32 pllx_base; u32 cpu_burst; u32 clk_csite_src; u32 cclk_divider; } tegra20_cpu_clk_sctx; #endif static void __iomem *clk_base; static void __iomem *pmc_base; #define TEGRA_INIT_DATA_MUX(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \ 30, 2, 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, \ _clk_num, \ _gate_flags, _clk_id) #define TEGRA_INIT_DATA_DIV16(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \ 30, 2, 0, 0, 16, 0, TEGRA_DIVIDER_ROUND_UP, \ _clk_num, _gate_flags, \ _clk_id) #define TEGRA_INIT_DATA_NODIV(_name, _parents, _offset, \ _mux_shift, _mux_width, _clk_num, \ _gate_flags, _clk_id) \ TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \ _mux_shift, _mux_width, 0, 0, 0, 0, 0, \ _clk_num, _gate_flags, \ _clk_id) static struct clk **clks; static struct tegra_clk_pll_freq_table pll_c_freq_table[] = { { 12000000, 600000000, 600, 12, 1, 8 }, { 13000000, 600000000, 600, 13, 1, 8 }, { 19200000, 600000000, 500, 16, 1, 6 }, { 26000000, 600000000, 600, 26, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_m_freq_table[] = { { 12000000, 666000000, 666, 12, 1, 8 }, { 13000000, 666000000, 666, 13, 1, 8 }, { 19200000, 666000000, 555, 16, 1, 8 }, { 26000000, 666000000, 666, 26, 1, 8 }, { 12000000, 600000000, 600, 12, 1, 8 }, { 13000000, 600000000, 600, 13, 1, 8 }, { 19200000, 600000000, 375, 12, 1, 6 }, { 26000000, 600000000, 600, 26, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { { 12000000, 216000000, 432, 12, 2, 8 }, { 13000000, 216000000, 432, 13, 2, 8 }, { 19200000, 216000000, 90, 4, 2, 1 }, { 26000000, 216000000, 432, 26, 2, 8 }, { 12000000, 432000000, 432, 12, 1, 8 }, { 13000000, 432000000, 432, 13, 1, 8 }, { 19200000, 432000000, 90, 4, 1, 1 }, { 26000000, 432000000, 432, 26, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_a_freq_table[] = { { 28800000, 56448000, 49, 25, 1, 1 }, { 28800000, 73728000, 64, 25, 1, 1 }, { 28800000, 24000000, 5, 6, 1, 1 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { { 12000000, 216000000, 216, 12, 1, 4 }, { 13000000, 216000000, 216, 13, 1, 4 }, { 19200000, 216000000, 135, 12, 1, 3 }, { 26000000, 216000000, 216, 26, 1, 4 }, { 12000000, 594000000, 594, 12, 1, 8 }, { 13000000, 594000000, 594, 13, 1, 8 }, { 19200000, 594000000, 495, 16, 1, 8 }, { 26000000, 594000000, 594, 26, 1, 8 }, { 12000000, 1000000000, 1000, 12, 1, 12 }, { 13000000, 1000000000, 1000, 13, 1, 12 }, { 19200000, 1000000000, 625, 12, 1, 8 }, { 26000000, 1000000000, 1000, 26, 1, 12 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_u_freq_table[] = { { 12000000, 480000000, 960, 12, 1, 0 }, { 13000000, 480000000, 960, 13, 1, 0 }, { 19200000, 480000000, 200, 4, 1, 0 }, { 26000000, 480000000, 960, 26, 1, 0 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_x_freq_table[] = { /* 1 GHz */ { 12000000, 1000000000, 1000, 12, 1, 12 }, { 13000000, 1000000000, 1000, 13, 1, 12 }, { 19200000, 1000000000, 625, 12, 1, 8 }, { 26000000, 1000000000, 1000, 26, 1, 12 }, /* 912 MHz */ { 12000000, 912000000, 912, 12, 1, 12 }, { 13000000, 912000000, 912, 13, 1, 12 }, { 19200000, 912000000, 760, 16, 1, 8 }, { 26000000, 912000000, 912, 26, 1, 12 }, /* 816 MHz */ { 12000000, 816000000, 816, 12, 1, 12 }, { 13000000, 816000000, 816, 13, 1, 12 }, { 19200000, 816000000, 680, 16, 1, 8 }, { 26000000, 816000000, 816, 26, 1, 12 }, /* 760 MHz */ { 12000000, 760000000, 760, 12, 1, 12 }, { 13000000, 760000000, 760, 13, 1, 12 }, { 19200000, 760000000, 950, 24, 1, 8 }, { 26000000, 760000000, 760, 26, 1, 12 }, /* 750 MHz */ { 12000000, 750000000, 750, 12, 1, 12 }, { 13000000, 750000000, 750, 13, 1, 12 }, { 19200000, 750000000, 625, 16, 1, 8 }, { 26000000, 750000000, 750, 26, 1, 12 }, /* 608 MHz */ { 12000000, 608000000, 608, 12, 1, 12 }, { 13000000, 608000000, 608, 13, 1, 12 }, { 19200000, 608000000, 380, 12, 1, 8 }, { 26000000, 608000000, 608, 26, 1, 12 }, /* 456 MHz */ { 12000000, 456000000, 456, 12, 1, 12 }, { 13000000, 456000000, 456, 13, 1, 12 }, { 19200000, 456000000, 380, 16, 1, 8 }, { 26000000, 456000000, 456, 26, 1, 12 }, /* 312 MHz */ { 12000000, 312000000, 312, 12, 1, 12 }, { 13000000, 312000000, 312, 13, 1, 12 }, { 19200000, 312000000, 260, 16, 1, 8 }, { 26000000, 312000000, 312, 26, 1, 12 }, { 0, 0, 0, 0, 0, 0 }, }; static const struct pdiv_map plle_p[] = { { .pdiv = 1, .hw_val = 1 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_e_freq_table[] = { { 12000000, 100000000, 200, 24, 1, 0 }, { 0, 0, 0, 0, 0, 0 }, }; /* PLL parameters */ static struct tegra_clk_pll_params pll_c_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1400000000, .base_reg = PLLC_BASE, .misc_reg = PLLC_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_c_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_m_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1200000000, .base_reg = PLLM_BASE, .misc_reg = PLLM_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_m_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_p_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1400000000, .base_reg = PLLP_BASE, .misc_reg = PLLP_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_p_freq_table, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_HAS_LOCK_ENABLE, .fixed_rate = 216000000, }; static struct tegra_clk_pll_params pll_a_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1400000000, .base_reg = PLLA_BASE, .misc_reg = PLLA_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_a_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_d_params = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 40000000, .vco_max = 1000000000, .base_reg = PLLD_BASE, .misc_reg = PLLD_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .freq_table = pll_d_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_HAS_LOCK_ENABLE, }; static const struct pdiv_map pllu_p[] = { { .pdiv = 1, .hw_val = 1 }, { .pdiv = 2, .hw_val = 0 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_params pll_u_params = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 48000000, .vco_max = 960000000, .base_reg = PLLU_BASE, .misc_reg = PLLU_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .pdiv_tohw = pllu_p, .freq_table = pll_u_freq_table, .flags = TEGRA_PLLU | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_x_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1200000000, .base_reg = PLLX_BASE, .misc_reg = PLLX_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_x_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_HAS_LOCK_ENABLE, .pre_rate_change = tegra_cclk_pre_pllx_rate_change, .post_rate_change = tegra_cclk_post_pllx_rate_change, }; static struct tegra_clk_pll_params pll_e_params = { .input_min = 12000000, .input_max = 12000000, .cf_min = 0, .cf_max = 0, .vco_min = 0, .vco_max = 0, .base_reg = PLLE_BASE, .misc_reg = PLLE_MISC, .lock_mask = PLLE_MISC_LOCK, .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE, .lock_delay = 0, .pdiv_tohw = plle_p, .freq_table = pll_e_freq_table, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_HAS_LOCK_ENABLE, .fixed_rate = 100000000, }; static struct tegra_devclk devclks[] = { { .con_id = "pll_c", .dt_id = TEGRA20_CLK_PLL_C }, { .con_id = "pll_c_out1", .dt_id = TEGRA20_CLK_PLL_C_OUT1 }, { .con_id = "pll_p", .dt_id = TEGRA20_CLK_PLL_P }, { .con_id = "pll_p_out1", .dt_id = TEGRA20_CLK_PLL_P_OUT1 }, { .con_id = "pll_p_out2", .dt_id = TEGRA20_CLK_PLL_P_OUT2 }, { .con_id = "pll_p_out3", .dt_id = TEGRA20_CLK_PLL_P_OUT3 }, { .con_id = "pll_p_out4", .dt_id = TEGRA20_CLK_PLL_P_OUT4 }, { .con_id = "pll_m", .dt_id = TEGRA20_CLK_PLL_M }, { .con_id = "pll_m_out1", .dt_id = TEGRA20_CLK_PLL_M_OUT1 }, { .con_id = "pll_x", .dt_id = TEGRA20_CLK_PLL_X }, { .con_id = "pll_u", .dt_id = TEGRA20_CLK_PLL_U }, { .con_id = "pll_d", .dt_id = TEGRA20_CLK_PLL_D }, { .con_id = "pll_d_out0", .dt_id = TEGRA20_CLK_PLL_D_OUT0 }, { .con_id = "pll_a", .dt_id = TEGRA20_CLK_PLL_A }, { .con_id = "pll_a_out0", .dt_id = TEGRA20_CLK_PLL_A_OUT0 }, { .con_id = "pll_e", .dt_id = TEGRA20_CLK_PLL_E }, { .con_id = "cclk", .dt_id = TEGRA20_CLK_CCLK }, { .con_id = "sclk", .dt_id = TEGRA20_CLK_SCLK }, { .con_id = "hclk", .dt_id = TEGRA20_CLK_HCLK }, { .con_id = "pclk", .dt_id = TEGRA20_CLK_PCLK }, { .con_id = "fuse", .dt_id = TEGRA20_CLK_FUSE }, { .con_id = "twd", .dt_id = TEGRA20_CLK_TWD }, { .con_id = "audio", .dt_id = TEGRA20_CLK_AUDIO }, { .con_id = "audio_2x", .dt_id = TEGRA20_CLK_AUDIO_2X }, { .dev_id = "tegra20-ac97", .dt_id = TEGRA20_CLK_AC97 }, { .dev_id = "tegra-apbdma", .dt_id = TEGRA20_CLK_APBDMA }, { .dev_id = "rtc-tegra", .dt_id = TEGRA20_CLK_RTC }, { .dev_id = "timer", .dt_id = TEGRA20_CLK_TIMER }, { .dev_id = "tegra-kbc", .dt_id = TEGRA20_CLK_KBC }, { .con_id = "csus", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_CSUS }, { .con_id = "vcp", .dev_id = "tegra-avp", .dt_id = TEGRA20_CLK_VCP }, { .con_id = "bsea", .dev_id = "tegra-avp", .dt_id = TEGRA20_CLK_BSEA }, { .con_id = "bsev", .dev_id = "tegra-aes", .dt_id = TEGRA20_CLK_BSEV }, { .con_id = "emc", .dt_id = TEGRA20_CLK_EMC }, { .dev_id = "fsl-tegra-udc", .dt_id = TEGRA20_CLK_USBD }, { .dev_id = "tegra-ehci.1", .dt_id = TEGRA20_CLK_USB2 }, { .dev_id = "tegra-ehci.2", .dt_id = TEGRA20_CLK_USB3 }, { .dev_id = "dsi", .dt_id = TEGRA20_CLK_DSI }, { .con_id = "csi", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_CSI }, { .con_id = "isp", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_ISP }, { .con_id = "pex", .dt_id = TEGRA20_CLK_PEX }, { .con_id = "afi", .dt_id = TEGRA20_CLK_AFI }, { .con_id = "cdev1", .dt_id = TEGRA20_CLK_CDEV1 }, { .con_id = "cdev2", .dt_id = TEGRA20_CLK_CDEV2 }, { .con_id = "clk_32k", .dt_id = TEGRA20_CLK_CLK_32K }, { .con_id = "clk_m", .dt_id = TEGRA20_CLK_CLK_M }, { .con_id = "pll_ref", .dt_id = TEGRA20_CLK_PLL_REF }, { .dev_id = "tegra20-i2s.0", .dt_id = TEGRA20_CLK_I2S1 }, { .dev_id = "tegra20-i2s.1", .dt_id = TEGRA20_CLK_I2S2 }, { .con_id = "spdif_out", .dev_id = "tegra20-spdif", .dt_id = TEGRA20_CLK_SPDIF_OUT }, { .con_id = "spdif_in", .dev_id = "tegra20-spdif", .dt_id = TEGRA20_CLK_SPDIF_IN }, { .dev_id = "spi_tegra.0", .dt_id = TEGRA20_CLK_SBC1 }, { .dev_id = "spi_tegra.1", .dt_id = TEGRA20_CLK_SBC2 }, { .dev_id = "spi_tegra.2", .dt_id = TEGRA20_CLK_SBC3 }, { .dev_id = "spi_tegra.3", .dt_id = TEGRA20_CLK_SBC4 }, { .dev_id = "spi", .dt_id = TEGRA20_CLK_SPI }, { .dev_id = "xio", .dt_id = TEGRA20_CLK_XIO }, { .dev_id = "twc", .dt_id = TEGRA20_CLK_TWC }, { .dev_id = "ide", .dt_id = TEGRA20_CLK_IDE }, { .dev_id = "tegra_nand", .dt_id = TEGRA20_CLK_NDFLASH }, { .dev_id = "vfir", .dt_id = TEGRA20_CLK_VFIR }, { .dev_id = "csite", .dt_id = TEGRA20_CLK_CSITE }, { .dev_id = "la", .dt_id = TEGRA20_CLK_LA }, { .dev_id = "tegra_w1", .dt_id = TEGRA20_CLK_OWR }, { .dev_id = "mipi", .dt_id = TEGRA20_CLK_MIPI }, { .dev_id = "vde", .dt_id = TEGRA20_CLK_VDE }, { .con_id = "vi", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_VI }, { .dev_id = "epp", .dt_id = TEGRA20_CLK_EPP }, { .dev_id = "mpe", .dt_id = TEGRA20_CLK_MPE }, { .dev_id = "host1x", .dt_id = TEGRA20_CLK_HOST1X }, { .dev_id = "3d", .dt_id = TEGRA20_CLK_GR3D }, { .dev_id = "2d", .dt_id = TEGRA20_CLK_GR2D }, { .dev_id = "tegra-nor", .dt_id = TEGRA20_CLK_NOR }, { .dev_id = "sdhci-tegra.0", .dt_id = TEGRA20_CLK_SDMMC1 }, { .dev_id = "sdhci-tegra.1", .dt_id = TEGRA20_CLK_SDMMC2 }, { .dev_id = "sdhci-tegra.2", .dt_id = TEGRA20_CLK_SDMMC3 }, { .dev_id = "sdhci-tegra.3", .dt_id = TEGRA20_CLK_SDMMC4 }, { .dev_id = "cve", .dt_id = TEGRA20_CLK_CVE }, { .dev_id = "tvo", .dt_id = TEGRA20_CLK_TVO }, { .dev_id = "tvdac", .dt_id = TEGRA20_CLK_TVDAC }, { .con_id = "vi_sensor", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_VI_SENSOR }, { .dev_id = "hdmi", .dt_id = TEGRA20_CLK_HDMI }, { .con_id = "div-clk", .dev_id = "tegra-i2c.0", .dt_id = TEGRA20_CLK_I2C1 }, { .con_id = "div-clk", .dev_id = "tegra-i2c.1", .dt_id = TEGRA20_CLK_I2C2 }, { .con_id = "div-clk", .dev_id = "tegra-i2c.2", .dt_id = TEGRA20_CLK_I2C3 }, { .con_id = "div-clk", .dev_id = "tegra-i2c.3", .dt_id = TEGRA20_CLK_DVC }, { .dev_id = "tegra-pwm", .dt_id = TEGRA20_CLK_PWM }, { .dev_id = "tegra_uart.0", .dt_id = TEGRA20_CLK_UARTA }, { .dev_id = "tegra_uart.1", .dt_id = TEGRA20_CLK_UARTB }, { .dev_id = "tegra_uart.2", .dt_id = TEGRA20_CLK_UARTC }, { .dev_id = "tegra_uart.3", .dt_id = TEGRA20_CLK_UARTD }, { .dev_id = "tegra_uart.4", .dt_id = TEGRA20_CLK_UARTE }, { .dev_id = "tegradc.0", .dt_id = TEGRA20_CLK_DISP1 }, { .dev_id = "tegradc.1", .dt_id = TEGRA20_CLK_DISP2 }, }; static struct tegra_clk tegra20_clks[tegra_clk_max] __initdata = { [tegra_clk_ahbdma] = { .dt_id = TEGRA20_CLK_AHBDMA, .present = true }, [tegra_clk_apbdma] = { .dt_id = TEGRA20_CLK_APBDMA, .present = true }, [tegra_clk_spdif_out] = { .dt_id = TEGRA20_CLK_SPDIF_OUT, .present = true }, [tegra_clk_spdif_in] = { .dt_id = TEGRA20_CLK_SPDIF_IN, .present = true }, [tegra_clk_sdmmc1] = { .dt_id = TEGRA20_CLK_SDMMC1, .present = true }, [tegra_clk_sdmmc2] = { .dt_id = TEGRA20_CLK_SDMMC2, .present = true }, [tegra_clk_sdmmc3] = { .dt_id = TEGRA20_CLK_SDMMC3, .present = true }, [tegra_clk_sdmmc4] = { .dt_id = TEGRA20_CLK_SDMMC4, .present = true }, [tegra_clk_la] = { .dt_id = TEGRA20_CLK_LA, .present = true }, [tegra_clk_csite] = { .dt_id = TEGRA20_CLK_CSITE, .present = true }, [tegra_clk_vfir] = { .dt_id = TEGRA20_CLK_VFIR, .present = true }, [tegra_clk_mipi] = { .dt_id = TEGRA20_CLK_MIPI, .present = true }, [tegra_clk_nor] = { .dt_id = TEGRA20_CLK_NOR, .present = true }, [tegra_clk_rtc] = { .dt_id = TEGRA20_CLK_RTC, .present = true }, [tegra_clk_timer] = { .dt_id = TEGRA20_CLK_TIMER, .present = true }, [tegra_clk_kbc] = { .dt_id = TEGRA20_CLK_KBC, .present = true }, [tegra_clk_csus] = { .dt_id = TEGRA20_CLK_CSUS, .present = true }, [tegra_clk_vcp] = { .dt_id = TEGRA20_CLK_VCP, .present = true }, [tegra_clk_bsea] = { .dt_id = TEGRA20_CLK_BSEA, .present = true }, [tegra_clk_bsev] = { .dt_id = TEGRA20_CLK_BSEV, .present = true }, [tegra_clk_usbd] = { .dt_id = TEGRA20_CLK_USBD, .present = true }, [tegra_clk_usb2] = { .dt_id = TEGRA20_CLK_USB2, .present = true }, [tegra_clk_usb3] = { .dt_id = TEGRA20_CLK_USB3, .present = true }, [tegra_clk_csi] = { .dt_id = TEGRA20_CLK_CSI, .present = true }, [tegra_clk_isp] = { .dt_id = TEGRA20_CLK_ISP, .present = true }, [tegra_clk_clk_32k] = { .dt_id = TEGRA20_CLK_CLK_32K, .present = true }, [tegra_clk_hclk] = { .dt_id = TEGRA20_CLK_HCLK, .present = true }, [tegra_clk_pclk] = { .dt_id = TEGRA20_CLK_PCLK, .present = true }, [tegra_clk_pll_p_out1] = { .dt_id = TEGRA20_CLK_PLL_P_OUT1, .present = true }, [tegra_clk_pll_p_out2] = { .dt_id = TEGRA20_CLK_PLL_P_OUT2, .present = true }, [tegra_clk_pll_p_out3] = { .dt_id = TEGRA20_CLK_PLL_P_OUT3, .present = true }, [tegra_clk_pll_p_out4] = { .dt_id = TEGRA20_CLK_PLL_P_OUT4, .present = true }, [tegra_clk_pll_p] = { .dt_id = TEGRA20_CLK_PLL_P, .present = true }, [tegra_clk_owr] = { .dt_id = TEGRA20_CLK_OWR, .present = true }, [tegra_clk_sbc1] = { .dt_id = TEGRA20_CLK_SBC1, .present = true }, [tegra_clk_sbc2] = { .dt_id = TEGRA20_CLK_SBC2, .present = true }, [tegra_clk_sbc3] = { .dt_id = TEGRA20_CLK_SBC3, .present = true }, [tegra_clk_sbc4] = { .dt_id = TEGRA20_CLK_SBC4, .present = true }, [tegra_clk_vde] = { .dt_id = TEGRA20_CLK_VDE, .present = true }, [tegra_clk_vi] = { .dt_id = TEGRA20_CLK_VI, .present = true }, [tegra_clk_epp] = { .dt_id = TEGRA20_CLK_EPP, .present = true }, [tegra_clk_mpe] = { .dt_id = TEGRA20_CLK_MPE, .present = true }, [tegra_clk_host1x] = { .dt_id = TEGRA20_CLK_HOST1X, .present = true }, [tegra_clk_gr2d] = { .dt_id = TEGRA20_CLK_GR2D, .present = true }, [tegra_clk_gr3d] = { .dt_id = TEGRA20_CLK_GR3D, .present = true }, [tegra_clk_ndflash] = { .dt_id = TEGRA20_CLK_NDFLASH, .present = true }, [tegra_clk_cve] = { .dt_id = TEGRA20_CLK_CVE, .present = true }, [tegra_clk_tvo] = { .dt_id = TEGRA20_CLK_TVO, .present = true }, [tegra_clk_tvdac] = { .dt_id = TEGRA20_CLK_TVDAC, .present = true }, [tegra_clk_vi_sensor] = { .dt_id = TEGRA20_CLK_VI_SENSOR, .present = true }, [tegra_clk_afi] = { .dt_id = TEGRA20_CLK_AFI, .present = true }, [tegra_clk_fuse] = { .dt_id = TEGRA20_CLK_FUSE, .present = true }, [tegra_clk_kfuse] = { .dt_id = TEGRA20_CLK_KFUSE, .present = true }, }; static unsigned long tegra20_clk_measure_input_freq(void) { u32 osc_ctrl = readl_relaxed(clk_base + OSC_CTRL); u32 auto_clk_control = osc_ctrl & OSC_CTRL_OSC_FREQ_MASK; u32 pll_ref_div = osc_ctrl & OSC_CTRL_PLL_REF_DIV_MASK; unsigned long input_freq; switch (auto_clk_control) { case OSC_CTRL_OSC_FREQ_12MHZ: BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); input_freq = 12000000; break; case OSC_CTRL_OSC_FREQ_13MHZ: BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); input_freq = 13000000; break; case OSC_CTRL_OSC_FREQ_19_2MHZ: BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); input_freq = 19200000; break; case OSC_CTRL_OSC_FREQ_26MHZ: BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); input_freq = 26000000; break; default: pr_err("Unexpected clock autodetect value %d", auto_clk_control); BUG(); return 0; } return input_freq; } static unsigned int tegra20_get_pll_ref_div(void) { u32 pll_ref_div = readl_relaxed(clk_base + OSC_CTRL) & OSC_CTRL_PLL_REF_DIV_MASK; switch (pll_ref_div) { case OSC_CTRL_PLL_REF_DIV_1: return 1; case OSC_CTRL_PLL_REF_DIV_2: return 2; case OSC_CTRL_PLL_REF_DIV_4: return 4; default: pr_err("Invalid pll ref divider %d\n", pll_ref_div); BUG(); } return 0; } static void tegra20_pll_init(void) { struct clk *clk; /* PLLC */ clk = tegra_clk_register_pll("pll_c", "pll_ref", clk_base, NULL, 0, &pll_c_params, NULL); clks[TEGRA20_CLK_PLL_C] = clk; /* PLLC_OUT1 */ clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c", clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div", clk_base + PLLC_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clks[TEGRA20_CLK_PLL_C_OUT1] = clk; /* PLLM */ clk = tegra_clk_register_pll("pll_m", "pll_ref", clk_base, NULL, CLK_SET_RATE_GATE, &pll_m_params, NULL); clks[TEGRA20_CLK_PLL_M] = clk; /* PLLM_OUT1 */ clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m", clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div", clk_base + PLLM_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clks[TEGRA20_CLK_PLL_M_OUT1] = clk; /* PLLX */ clk = tegra_clk_register_pll("pll_x", "pll_ref", clk_base, NULL, 0, &pll_x_params, NULL); clks[TEGRA20_CLK_PLL_X] = clk; /* PLLU */ clk = tegra_clk_register_pll("pll_u", "pll_ref", clk_base, NULL, 0, &pll_u_params, NULL); clks[TEGRA20_CLK_PLL_U] = clk; /* PLLD */ clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, NULL, 0, &pll_d_params, NULL); clks[TEGRA20_CLK_PLL_D] = clk; /* PLLD_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d", CLK_SET_RATE_PARENT, 1, 2); clks[TEGRA20_CLK_PLL_D_OUT0] = clk; /* PLLA */ clk = tegra_clk_register_pll("pll_a", "pll_p_out1", clk_base, NULL, 0, &pll_a_params, NULL); clks[TEGRA20_CLK_PLL_A] = clk; /* PLLA_OUT0 */ clk = tegra_clk_register_divider("pll_a_out0_div", "pll_a", clk_base + PLLA_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_a_out0", "pll_a_out0_div", clk_base + PLLA_OUT, 1, 0, CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0, NULL); clks[TEGRA20_CLK_PLL_A_OUT0] = clk; /* PLLE */ clk = tegra_clk_register_plle("pll_e", "pll_ref", clk_base, pmc_base, 0, &pll_e_params, NULL); clks[TEGRA20_CLK_PLL_E] = clk; } static const char *cclk_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m", "pll_p", "pll_p_out4", "pll_p_out3", "clk_d", "pll_x" }; static const char *sclk_parents[] = { "clk_m", "pll_c_out1", "pll_p_out4", "pll_p_out3", "pll_p_out2", "clk_d", "clk_32k", "pll_m_out1" }; static void tegra20_super_clk_init(void) { struct clk *clk; /* CCLK */ clk = tegra_clk_register_super_cclk("cclk", cclk_parents, ARRAY_SIZE(cclk_parents), CLK_SET_RATE_PARENT, clk_base + CCLK_BURST_POLICY, TEGRA20_SUPER_CLK, NULL); clks[TEGRA20_CLK_CCLK] = clk; /* twd */ clk = clk_register_fixed_factor(NULL, "twd", "cclk", 0, 1, 4); clks[TEGRA20_CLK_TWD] = clk; } static const char *audio_parents[] = { "spdif_in", "i2s1", "i2s2", "unused", "pll_a_out0", "unused", "unused", "unused" }; static void __init tegra20_audio_clk_init(void) { struct clk *clk; /* audio */ clk = clk_register_mux(NULL, "audio_mux", audio_parents, ARRAY_SIZE(audio_parents), CLK_SET_RATE_NO_REPARENT, clk_base + AUDIO_SYNC_CLK, 0, 3, 0, NULL); clk = clk_register_gate(NULL, "audio", "audio_mux", 0, clk_base + AUDIO_SYNC_CLK, 4, CLK_GATE_SET_TO_DISABLE, NULL); clks[TEGRA20_CLK_AUDIO] = clk; /* audio_2x */ clk = clk_register_fixed_factor(NULL, "audio_doubler", "audio", CLK_SET_RATE_PARENT, 2, 1); clk = tegra_clk_register_periph_gate("audio_2x", "audio_doubler", TEGRA_PERIPH_NO_RESET, clk_base, CLK_SET_RATE_PARENT, 89, periph_clk_enb_refcnt); clks[TEGRA20_CLK_AUDIO_2X] = clk; } static const char *i2s1_parents[] = { "pll_a_out0", "audio_2x", "pll_p", "clk_m" }; static const char *i2s2_parents[] = { "pll_a_out0", "audio_2x", "pll_p", "clk_m" }; static const char *pwm_parents[] = { "pll_p", "pll_c", "audio", "clk_m", "clk_32k" }; static const char *mux_pllpcm_clkm[] = { "pll_p", "pll_c", "pll_m", "clk_m" }; static const char *mux_pllpdc_clkm[] = { "pll_p", "pll_d_out0", "pll_c", "clk_m" }; static struct tegra_periph_init_data tegra_periph_clk_list[] = { TEGRA_INIT_DATA_MUX("i2s1", i2s1_parents, CLK_SOURCE_I2S1, 11, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2S1), TEGRA_INIT_DATA_MUX("i2s2", i2s2_parents, CLK_SOURCE_I2S2, 18, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2S2), TEGRA_INIT_DATA_MUX("spi", mux_pllpcm_clkm, CLK_SOURCE_SPI, 43, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_SPI), TEGRA_INIT_DATA_MUX("xio", mux_pllpcm_clkm, CLK_SOURCE_XIO, 45, 0, TEGRA20_CLK_XIO), TEGRA_INIT_DATA_MUX("twc", mux_pllpcm_clkm, CLK_SOURCE_TWC, 16, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_TWC), TEGRA_INIT_DATA_MUX("ide", mux_pllpcm_clkm, CLK_SOURCE_XIO, 25, 0, TEGRA20_CLK_IDE), TEGRA_INIT_DATA_DIV16("dvc", mux_pllpcm_clkm, CLK_SOURCE_DVC, 47, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_DVC), TEGRA_INIT_DATA_DIV16("i2c1", mux_pllpcm_clkm, CLK_SOURCE_I2C1, 12, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2C1), TEGRA_INIT_DATA_DIV16("i2c2", mux_pllpcm_clkm, CLK_SOURCE_I2C2, 54, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2C2), TEGRA_INIT_DATA_DIV16("i2c3", mux_pllpcm_clkm, CLK_SOURCE_I2C3, 67, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2C3), TEGRA_INIT_DATA_MUX("hdmi", mux_pllpdc_clkm, CLK_SOURCE_HDMI, 51, 0, TEGRA20_CLK_HDMI), TEGRA_INIT_DATA("pwm", NULL, NULL, pwm_parents, CLK_SOURCE_PWM, 28, 3, 0, 0, 8, 1, 0, 17, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_PWM), }; static struct tegra_periph_init_data tegra_periph_nodiv_clk_list[] = { TEGRA_INIT_DATA_NODIV("uarta", mux_pllpcm_clkm, CLK_SOURCE_UARTA, 30, 2, 6, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTA), TEGRA_INIT_DATA_NODIV("uartb", mux_pllpcm_clkm, CLK_SOURCE_UARTB, 30, 2, 7, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTB), TEGRA_INIT_DATA_NODIV("uartc", mux_pllpcm_clkm, CLK_SOURCE_UARTC, 30, 2, 55, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTC), TEGRA_INIT_DATA_NODIV("uartd", mux_pllpcm_clkm, CLK_SOURCE_UARTD, 30, 2, 65, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTD), TEGRA_INIT_DATA_NODIV("uarte", mux_pllpcm_clkm, CLK_SOURCE_UARTE, 30, 2, 66, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTE), TEGRA_INIT_DATA_NODIV("disp1", mux_pllpdc_clkm, CLK_SOURCE_DISP1, 30, 2, 27, 0, TEGRA20_CLK_DISP1), TEGRA_INIT_DATA_NODIV("disp2", mux_pllpdc_clkm, CLK_SOURCE_DISP2, 30, 2, 26, 0, TEGRA20_CLK_DISP2), }; static void __init tegra20_periph_clk_init(void) { struct tegra_periph_init_data *data; struct clk *clk; unsigned int i; /* ac97 */ clk = tegra_clk_register_periph_gate("ac97", "pll_a_out0", TEGRA_PERIPH_ON_APB, clk_base, 0, 3, periph_clk_enb_refcnt); clks[TEGRA20_CLK_AC97] = clk; /* emc */ clk = tegra20_clk_register_emc(clk_base + CLK_SOURCE_EMC, false); clks[TEGRA20_CLK_EMC] = clk; clk = tegra_clk_register_mc("mc", "emc", clk_base + CLK_SOURCE_EMC, NULL); clks[TEGRA20_CLK_MC] = clk; /* dsi */ clk = tegra_clk_register_periph_gate("dsi", "pll_d", 0, clk_base, 0, 48, periph_clk_enb_refcnt); clk_register_clkdev(clk, NULL, "dsi"); clks[TEGRA20_CLK_DSI] = clk; /* pex */ clk = tegra_clk_register_periph_gate("pex", "clk_m", 0, clk_base, 0, 70, periph_clk_enb_refcnt); clks[TEGRA20_CLK_PEX] = clk; /* dev1 OSC divider */ clk_register_divider(NULL, "dev1_osc_div", "clk_m", 0, clk_base + MISC_CLK_ENB, 22, 2, CLK_DIVIDER_POWER_OF_TWO | CLK_DIVIDER_READ_ONLY, NULL); /* dev2 OSC divider */ clk_register_divider(NULL, "dev2_osc_div", "clk_m", 0, clk_base + MISC_CLK_ENB, 20, 2, CLK_DIVIDER_POWER_OF_TWO | CLK_DIVIDER_READ_ONLY, NULL); /* cdev1 */ clk = tegra_clk_register_periph_gate("cdev1", "cdev1_mux", 0, clk_base, 0, 94, periph_clk_enb_refcnt); clks[TEGRA20_CLK_CDEV1] = clk; /* cdev2 */ clk = tegra_clk_register_periph_gate("cdev2", "cdev2_mux", 0, clk_base, 0, 93, periph_clk_enb_refcnt); clks[TEGRA20_CLK_CDEV2] = clk; for (i = 0; i < ARRAY_SIZE(tegra_periph_clk_list); i++) { data = &tegra_periph_clk_list[i]; clk = tegra_clk_register_periph_data(clk_base, data); clks[data->clk_id] = clk; } for (i = 0; i < ARRAY_SIZE(tegra_periph_nodiv_clk_list); i++) { data = &tegra_periph_nodiv_clk_list[i]; clk = tegra_clk_register_periph_nodiv(data->name, data->p.parent_names, data->num_parents, &data->periph, clk_base, data->offset); clks[data->clk_id] = clk; } tegra_periph_clk_init(clk_base, pmc_base, tegra20_clks, &pll_p_params); } static void __init tegra20_osc_clk_init(void) { struct clk *clk; unsigned long input_freq; unsigned int pll_ref_div; input_freq = tegra20_clk_measure_input_freq(); /* clk_m */ clk = clk_register_fixed_rate(NULL, "clk_m", NULL, CLK_IGNORE_UNUSED, input_freq); clks[TEGRA20_CLK_CLK_M] = clk; /* pll_ref */ pll_ref_div = tegra20_get_pll_ref_div(); clk = clk_register_fixed_factor(NULL, "pll_ref", "clk_m", CLK_SET_RATE_PARENT, 1, pll_ref_div); clks[TEGRA20_CLK_PLL_REF] = clk; } /* Tegra20 CPU clock and reset control functions */ static void tegra20_wait_cpu_in_reset(u32 cpu) { unsigned int reg; do { reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); cpu_relax(); } while (!(reg & (1 << cpu))); /* check CPU been reset or not */ return; } static void tegra20_put_cpu_in_reset(u32 cpu) { writel(CPU_RESET(cpu), clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); dmb(); } static void tegra20_cpu_out_of_reset(u32 cpu) { writel(CPU_RESET(cpu), clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR); wmb(); } static void tegra20_enable_cpu_clock(u32 cpu) { unsigned int reg; reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); writel(reg & ~CPU_CLOCK(cpu), clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); barrier(); reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); } static void tegra20_disable_cpu_clock(u32 cpu) { unsigned int reg; reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); writel(reg | CPU_CLOCK(cpu), clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); } #ifdef CONFIG_PM_SLEEP static bool tegra20_cpu_rail_off_ready(void) { unsigned int cpu_rst_status; cpu_rst_status = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); return !!(cpu_rst_status & 0x2); } static void tegra20_cpu_clock_suspend(void) { /* switch coresite to clk_m, save off original source */ tegra20_cpu_clk_sctx.clk_csite_src = readl(clk_base + CLK_SOURCE_CSITE); writel(3<<30, clk_base + CLK_SOURCE_CSITE); tegra20_cpu_clk_sctx.cpu_burst = readl(clk_base + CCLK_BURST_POLICY); tegra20_cpu_clk_sctx.pllx_base = readl(clk_base + PLLX_BASE); tegra20_cpu_clk_sctx.pllx_misc = readl(clk_base + PLLX_MISC); tegra20_cpu_clk_sctx.cclk_divider = readl(clk_base + SUPER_CCLK_DIVIDER); } static void tegra20_cpu_clock_resume(void) { unsigned int reg, policy; u32 misc, base; /* Is CPU complex already running on PLLX? */ reg = readl(clk_base + CCLK_BURST_POLICY); policy = (reg >> CCLK_BURST_POLICY_SHIFT) & 0xF; if (policy == CCLK_IDLE_POLICY) reg = (reg >> CCLK_IDLE_POLICY_SHIFT) & 0xF; else if (policy == CCLK_RUN_POLICY) reg = (reg >> CCLK_RUN_POLICY_SHIFT) & 0xF; else BUG(); if (reg != CCLK_BURST_POLICY_PLLX) { misc = readl_relaxed(clk_base + PLLX_MISC); base = readl_relaxed(clk_base + PLLX_BASE); if (misc != tegra20_cpu_clk_sctx.pllx_misc || base != tegra20_cpu_clk_sctx.pllx_base) { /* restore PLLX settings if CPU is on different PLL */ writel(tegra20_cpu_clk_sctx.pllx_misc, clk_base + PLLX_MISC); writel(tegra20_cpu_clk_sctx.pllx_base, clk_base + PLLX_BASE); /* wait for PLL stabilization if PLLX was enabled */ if (tegra20_cpu_clk_sctx.pllx_base & (1 << 30)) udelay(300); } } /* * Restore original burst policy setting for calls resulting from CPU * LP2 in idle or system suspend. */ writel(tegra20_cpu_clk_sctx.cclk_divider, clk_base + SUPER_CCLK_DIVIDER); writel(tegra20_cpu_clk_sctx.cpu_burst, clk_base + CCLK_BURST_POLICY); writel(tegra20_cpu_clk_sctx.clk_csite_src, clk_base + CLK_SOURCE_CSITE); } #endif static struct tegra_cpu_car_ops tegra20_cpu_car_ops = { .wait_for_reset = tegra20_wait_cpu_in_reset, .put_in_reset = tegra20_put_cpu_in_reset, .out_of_reset = tegra20_cpu_out_of_reset, .enable_clock = tegra20_enable_cpu_clock, .disable_clock = tegra20_disable_cpu_clock, #ifdef CONFIG_PM_SLEEP .rail_off_ready = tegra20_cpu_rail_off_ready, .suspend = tegra20_cpu_clock_suspend, .resume = tegra20_cpu_clock_resume, #endif }; static struct tegra_clk_init_table init_table[] = { { TEGRA20_CLK_PLL_P, TEGRA20_CLK_CLK_MAX, 216000000, 1 }, { TEGRA20_CLK_PLL_P_OUT1, TEGRA20_CLK_CLK_MAX, 28800000, 1 }, { TEGRA20_CLK_PLL_P_OUT2, TEGRA20_CLK_CLK_MAX, 48000000, 1 }, { TEGRA20_CLK_PLL_P_OUT3, TEGRA20_CLK_CLK_MAX, 72000000, 1 }, { TEGRA20_CLK_PLL_P_OUT4, TEGRA20_CLK_CLK_MAX, 24000000, 1 }, { TEGRA20_CLK_PLL_C, TEGRA20_CLK_CLK_MAX, 600000000, 0 }, { TEGRA20_CLK_PLL_C_OUT1, TEGRA20_CLK_CLK_MAX, 120000000, 0 }, { TEGRA20_CLK_SCLK, TEGRA20_CLK_PLL_C_OUT1, 120000000, 0 }, { TEGRA20_CLK_HCLK, TEGRA20_CLK_CLK_MAX, 120000000, 0 }, { TEGRA20_CLK_PCLK, TEGRA20_CLK_CLK_MAX, 60000000, 0 }, { TEGRA20_CLK_CSITE, TEGRA20_CLK_CLK_MAX, 0, 1 }, { TEGRA20_CLK_CCLK, TEGRA20_CLK_CLK_MAX, 0, 1 }, { TEGRA20_CLK_UARTA, TEGRA20_CLK_PLL_P, 0, 0 }, { TEGRA20_CLK_UARTB, TEGRA20_CLK_PLL_P, 0, 0 }, { TEGRA20_CLK_UARTC, TEGRA20_CLK_PLL_P, 0, 0 }, { TEGRA20_CLK_UARTD, TEGRA20_CLK_PLL_P, 0, 0 }, { TEGRA20_CLK_UARTE, TEGRA20_CLK_PLL_P, 0, 0 }, { TEGRA20_CLK_PLL_A, TEGRA20_CLK_CLK_MAX, 56448000, 0 }, { TEGRA20_CLK_PLL_A_OUT0, TEGRA20_CLK_CLK_MAX, 11289600, 0 }, { TEGRA20_CLK_I2S1, TEGRA20_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA20_CLK_I2S2, TEGRA20_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA20_CLK_SDMMC1, TEGRA20_CLK_PLL_P, 48000000, 0 }, { TEGRA20_CLK_SDMMC3, TEGRA20_CLK_PLL_P, 48000000, 0 }, { TEGRA20_CLK_SDMMC4, TEGRA20_CLK_PLL_P, 48000000, 0 }, { TEGRA20_CLK_SPI, TEGRA20_CLK_PLL_P, 20000000, 0 }, { TEGRA20_CLK_SBC1, TEGRA20_CLK_PLL_P, 100000000, 0 }, { TEGRA20_CLK_SBC2, TEGRA20_CLK_PLL_P, 100000000, 0 }, { TEGRA20_CLK_SBC3, TEGRA20_CLK_PLL_P, 100000000, 0 }, { TEGRA20_CLK_SBC4, TEGRA20_CLK_PLL_P, 100000000, 0 }, { TEGRA20_CLK_HOST1X, TEGRA20_CLK_PLL_C, 150000000, 0 }, { TEGRA20_CLK_GR2D, TEGRA20_CLK_PLL_C, 300000000, 0 }, { TEGRA20_CLK_GR3D, TEGRA20_CLK_PLL_C, 300000000, 0 }, { TEGRA20_CLK_VDE, TEGRA20_CLK_PLL_C, 300000000, 0 }, { TEGRA20_CLK_PWM, TEGRA20_CLK_PLL_P, 48000000, 0 }, /* must be the last entry */ { TEGRA20_CLK_CLK_MAX, TEGRA20_CLK_CLK_MAX, 0, 0 }, }; /* * Some clocks may be used by different drivers depending on the board * configuration. List those here to register them twice in the clock lookup * table under two names. */ static struct tegra_clk_duplicate tegra_clk_duplicates[] = { TEGRA_CLK_DUPLICATE(TEGRA20_CLK_USBD, "utmip-pad", NULL), TEGRA_CLK_DUPLICATE(TEGRA20_CLK_USBD, "tegra-ehci.0", NULL), TEGRA_CLK_DUPLICATE(TEGRA20_CLK_USBD, "tegra-otg", NULL), TEGRA_CLK_DUPLICATE(TEGRA20_CLK_CCLK, NULL, "cpu"), /* must be the last entry */ TEGRA_CLK_DUPLICATE(TEGRA20_CLK_CLK_MAX, NULL, NULL), }; static const struct of_device_id pmc_match[] __initconst = { { .compatible = "nvidia,tegra20-pmc" }, { }, }; static bool tegra20_car_initialized; static struct clk *tegra20_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) { struct clk_hw *parent_hw; struct clk_hw *hw; struct clk *clk; /* * Timer clocks are needed early, the rest of the clocks shouldn't be * available to device drivers until clock tree is fully initialized. */ if (clkspec->args[0] != TEGRA20_CLK_RTC && clkspec->args[0] != TEGRA20_CLK_TWD && clkspec->args[0] != TEGRA20_CLK_TIMER && !tegra20_car_initialized) return ERR_PTR(-EPROBE_DEFER); clk = of_clk_src_onecell_get(clkspec, data); if (IS_ERR(clk)) return clk; hw = __clk_get_hw(clk); /* * Tegra20 CDEV1 and CDEV2 clocks are a bit special case, their parent * clock is created by the pinctrl driver. It is possible for clk user * to request these clocks before pinctrl driver got probed and hence * user will get an orphaned clock. That might be undesirable because * user may expect parent clock to be enabled by the child. */ if (clkspec->args[0] == TEGRA20_CLK_CDEV1 || clkspec->args[0] == TEGRA20_CLK_CDEV2) { parent_hw = clk_hw_get_parent(hw); if (!parent_hw) return ERR_PTR(-EPROBE_DEFER); } if (clkspec->args[0] == TEGRA20_CLK_EMC) { if (!tegra20_clk_emc_driver_available(hw)) return ERR_PTR(-EPROBE_DEFER); } return clk; } static void __init tegra20_clock_init(struct device_node *np) { struct device_node *node; clk_base = of_iomap(np, 0); if (!clk_base) { pr_err("Can't map CAR registers\n"); BUG(); } node = of_find_matching_node(NULL, pmc_match); if (!node) { pr_err("Failed to find pmc node\n"); BUG(); } pmc_base = of_iomap(node, 0); of_node_put(node); if (!pmc_base) { pr_err("Can't map pmc registers\n"); BUG(); } clks = tegra_clk_init(clk_base, TEGRA20_CLK_CLK_MAX, TEGRA20_CLK_PERIPH_BANKS); if (!clks) return; tegra20_osc_clk_init(); tegra_fixed_clk_init(tegra20_clks); tegra20_pll_init(); tegra20_super_clk_init(); tegra_super_clk_gen4_init(clk_base, pmc_base, tegra20_clks, NULL); tegra20_periph_clk_init(); tegra20_audio_clk_init(); tegra_init_dup_clks(tegra_clk_duplicates, clks, TEGRA20_CLK_CLK_MAX); tegra_add_of_provider(np, tegra20_clk_src_onecell_get); tegra_cpu_car_ops = &tegra20_cpu_car_ops; } CLK_OF_DECLARE_DRIVER(tegra20, "nvidia,tegra20-car", tegra20_clock_init); /* * Clocks that use runtime PM can't be created at the tegra20_clock_init * time because drivers' base isn't initialized yet, and thus platform * devices can't be created for the clocks. Hence we need to split the * registration of the clocks into two phases. The first phase registers * essential clocks which don't require RPM and are actually used during * early boot. The second phase registers clocks which use RPM and this * is done when device drivers' core API is ready. */ static int tegra20_car_probe(struct platform_device *pdev) { struct clk *clk; clk = tegra_clk_register_super_mux("sclk", sclk_parents, ARRAY_SIZE(sclk_parents), CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, clk_base + SCLK_BURST_POLICY, 0, 4, 0, 0, NULL); clks[TEGRA20_CLK_SCLK] = clk; tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); tegra_init_from_table(init_table, clks, TEGRA20_CLK_CLK_MAX); tegra20_car_initialized = true; return 0; } static const struct of_device_id tegra20_car_match[] = { { .compatible = "nvidia,tegra20-car" }, { } }; static struct platform_driver tegra20_car_driver = { .driver = { .name = "tegra20-car", .of_match_table = tegra20_car_match, .suppress_bind_attrs = true, }, .probe = tegra20_car_probe, }; builtin_platform_driver(tegra20_car_driver);
linux-master
drivers/clk/tegra/clk-tegra20.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/clk/tegra.h> #include "clk.h" #include "clk-id.h" #define PLLX_BASE 0xe0 #define PLLX_MISC 0xe4 #define PLLX_MISC2 0x514 #define PLLX_MISC3 0x518 #define CCLKG_BURST_POLICY 0x368 #define CCLKLP_BURST_POLICY 0x370 #define SCLK_BURST_POLICY 0x028 #define SYSTEM_CLK_RATE 0x030 #define SCLK_DIVIDER 0x2c static DEFINE_SPINLOCK(sysrate_lock); enum tegra_super_gen { gen4 = 4, gen5, }; struct tegra_super_gen_info { enum tegra_super_gen gen; const char **sclk_parents; const char **cclk_g_parents; const char **cclk_lp_parents; int num_sclk_parents; int num_cclk_g_parents; int num_cclk_lp_parents; }; static const char *sclk_parents[] = { "clk_m", "pll_c_out1", "pll_p_out4", "pll_p", "pll_p_out2", "unused", "clk_32k", "pll_m_out1" }; static const char *cclk_g_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m", "pll_p", "pll_p_out4", "unused", "unused", "pll_x", "unused", "unused", "unused", "unused", "unused", "unused", "dfllCPU_out" }; static const char *cclk_lp_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m", "pll_p", "pll_p_out4", "unused", "unused", "pll_x", "pll_x_out0" }; static const struct tegra_super_gen_info tegra_super_gen_info_gen4 = { .gen = gen4, .sclk_parents = sclk_parents, .cclk_g_parents = cclk_g_parents, .cclk_lp_parents = cclk_lp_parents, .num_sclk_parents = ARRAY_SIZE(sclk_parents), .num_cclk_g_parents = ARRAY_SIZE(cclk_g_parents), .num_cclk_lp_parents = ARRAY_SIZE(cclk_lp_parents), }; static const char *sclk_parents_gen5[] = { "clk_m", "pll_c_out1", "pll_c4_out3", "pll_p", "pll_p_out2", "pll_c4_out1", "clk_32k", "pll_c4_out2" }; static const char *cclk_g_parents_gen5[] = { "clk_m", "unused", "clk_32k", "unused", "pll_p", "pll_p_out4", "unused", "unused", "pll_x", "unused", "unused", "unused", "unused", "unused", "unused", "dfllCPU_out" }; static const char *cclk_lp_parents_gen5[] = { "clk_m", "unused", "clk_32k", "unused", "pll_p", "pll_p_out4", "unused", "unused", "pll_x", "unused", "unused", "unused", "unused", "unused", "unused", "dfllCPU_out" }; static const struct tegra_super_gen_info tegra_super_gen_info_gen5 = { .gen = gen5, .sclk_parents = sclk_parents_gen5, .cclk_g_parents = cclk_g_parents_gen5, .cclk_lp_parents = cclk_lp_parents_gen5, .num_sclk_parents = ARRAY_SIZE(sclk_parents_gen5), .num_cclk_g_parents = ARRAY_SIZE(cclk_g_parents_gen5), .num_cclk_lp_parents = ARRAY_SIZE(cclk_lp_parents_gen5), }; static void __init tegra_sclk_init(void __iomem *clk_base, struct tegra_clk *tegra_clks, const struct tegra_super_gen_info *gen_info) { struct clk *clk; struct clk **dt_clk; /* SCLK_MUX */ dt_clk = tegra_lookup_dt_id(tegra_clk_sclk_mux, tegra_clks); if (dt_clk) { clk = tegra_clk_register_super_mux("sclk_mux", gen_info->sclk_parents, gen_info->num_sclk_parents, CLK_SET_RATE_PARENT, clk_base + SCLK_BURST_POLICY, 0, 4, 0, 0, NULL); *dt_clk = clk; /* SCLK */ dt_clk = tegra_lookup_dt_id(tegra_clk_sclk, tegra_clks); if (dt_clk) { clk = clk_register_divider(NULL, "sclk", "sclk_mux", CLK_IS_CRITICAL, clk_base + SCLK_DIVIDER, 0, 8, 0, &sysrate_lock); *dt_clk = clk; } } else { /* SCLK */ dt_clk = tegra_lookup_dt_id(tegra_clk_sclk, tegra_clks); if (dt_clk) { clk = tegra_clk_register_super_mux("sclk", gen_info->sclk_parents, gen_info->num_sclk_parents, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, clk_base + SCLK_BURST_POLICY, 0, 4, 0, 0, NULL); *dt_clk = clk; } } /* HCLK */ dt_clk = tegra_lookup_dt_id(tegra_clk_hclk, tegra_clks); if (dt_clk) { clk = clk_register_divider(NULL, "hclk_div", "sclk", 0, clk_base + SYSTEM_CLK_RATE, 4, 2, 0, &sysrate_lock); clk = clk_register_gate(NULL, "hclk", "hclk_div", CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, clk_base + SYSTEM_CLK_RATE, 7, CLK_GATE_SET_TO_DISABLE, &sysrate_lock); *dt_clk = clk; } /* PCLK */ dt_clk = tegra_lookup_dt_id(tegra_clk_pclk, tegra_clks); if (!dt_clk) return; clk = clk_register_divider(NULL, "pclk_div", "hclk", 0, clk_base + SYSTEM_CLK_RATE, 0, 2, 0, &sysrate_lock); clk = clk_register_gate(NULL, "pclk", "pclk_div", CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, clk_base + SYSTEM_CLK_RATE, 3, CLK_GATE_SET_TO_DISABLE, &sysrate_lock); *dt_clk = clk; } static void __init tegra_super_clk_init(void __iomem *clk_base, void __iomem *pmc_base, struct tegra_clk *tegra_clks, struct tegra_clk_pll_params *params, const struct tegra_super_gen_info *gen_info) { struct clk *clk; struct clk **dt_clk; /* CCLKG */ dt_clk = tegra_lookup_dt_id(tegra_clk_cclk_g, tegra_clks); if (dt_clk) { if (gen_info->gen == gen5) { clk = tegra_clk_register_super_mux("cclk_g", gen_info->cclk_g_parents, gen_info->num_cclk_g_parents, CLK_SET_RATE_PARENT, clk_base + CCLKG_BURST_POLICY, TEGRA210_CPU_CLK, 4, 8, 0, NULL); } else { clk = tegra_clk_register_super_mux("cclk_g", gen_info->cclk_g_parents, gen_info->num_cclk_g_parents, CLK_SET_RATE_PARENT, clk_base + CCLKG_BURST_POLICY, 0, 4, 0, 0, NULL); } *dt_clk = clk; } /* CCLKLP */ dt_clk = tegra_lookup_dt_id(tegra_clk_cclk_lp, tegra_clks); if (dt_clk) { if (gen_info->gen == gen5) { /* * TEGRA210_CPU_CLK flag is not needed for cclk_lp as * cluster switching is not currently supported on * Tegra210 and also cpu_lp is not used. */ clk = tegra_clk_register_super_mux("cclk_lp", gen_info->cclk_lp_parents, gen_info->num_cclk_lp_parents, CLK_SET_RATE_PARENT, clk_base + CCLKLP_BURST_POLICY, 0, 4, 8, 0, NULL); } else { clk = tegra_clk_register_super_mux("cclk_lp", gen_info->cclk_lp_parents, gen_info->num_cclk_lp_parents, CLK_SET_RATE_PARENT, clk_base + CCLKLP_BURST_POLICY, TEGRA_DIVIDER_2, 4, 8, 9, NULL); } *dt_clk = clk; } tegra_sclk_init(clk_base, tegra_clks, gen_info); #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \ defined(CONFIG_ARCH_TEGRA_124_SOC) || \ defined(CONFIG_ARCH_TEGRA_210_SOC) /* PLLX */ dt_clk = tegra_lookup_dt_id(tegra_clk_pll_x, tegra_clks); if (!dt_clk) return; #if defined(CONFIG_ARCH_TEGRA_210_SOC) if (gen_info->gen == gen5) clk = tegra_clk_register_pllc_tegra210("pll_x", "pll_ref", clk_base, pmc_base, CLK_IGNORE_UNUSED, params, NULL); else #endif clk = tegra_clk_register_pllxc("pll_x", "pll_ref", clk_base, pmc_base, CLK_IGNORE_UNUSED, params, NULL); *dt_clk = clk; /* PLLX_OUT0 */ dt_clk = tegra_lookup_dt_id(tegra_clk_pll_x_out0, tegra_clks); if (!dt_clk) return; clk = clk_register_fixed_factor(NULL, "pll_x_out0", "pll_x", CLK_SET_RATE_PARENT, 1, 2); *dt_clk = clk; #endif } void __init tegra_super_clk_gen4_init(void __iomem *clk_base, void __iomem *pmc_base, struct tegra_clk *tegra_clks, struct tegra_clk_pll_params *params) { tegra_super_clk_init(clk_base, pmc_base, tegra_clks, params, &tegra_super_gen_info_gen4); } void __init tegra_super_clk_gen5_init(void __iomem *clk_base, void __iomem *pmc_base, struct tegra_clk *tegra_clks, struct tegra_clk_pll_params *params) { tegra_super_clk_init(clk_base, pmc_base, tegra_clks, params, &tegra_super_gen_info_gen5); }
linux-master
drivers/clk/tegra/clk-tegra-super-gen4.c
// SPDX-License-Identifier: GPL-2.0-only #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/mod_devicetable.h> #include <linux/mutex.h> #include <linux/platform_device.h> #include <linux/pm_domain.h> #include <linux/pm_opp.h> #include <linux/pm_runtime.h> #include <linux/slab.h> #include <soc/tegra/common.h> #include "clk.h" /* * This driver manages performance state of the core power domain for the * independent PLLs and system clocks. We created a virtual clock device * for such clocks, see tegra_clk_dev_register(). */ struct tegra_clk_device { struct notifier_block clk_nb; struct device *dev; struct clk_hw *hw; struct mutex lock; }; static int tegra_clock_set_pd_state(struct tegra_clk_device *clk_dev, unsigned long rate) { struct device *dev = clk_dev->dev; struct dev_pm_opp *opp; unsigned int pstate; opp = dev_pm_opp_find_freq_ceil(dev, &rate); if (opp == ERR_PTR(-ERANGE)) { /* * Some clocks may be unused by a particular board and they * may have uninitiated clock rate that is overly high. In * this case clock is expected to be disabled, but still we * need to set up performance state of the power domain and * not error out clk initialization. A typical example is * a PCIe clock on Android tablets. */ dev_dbg(dev, "failed to find ceil OPP for %luHz\n", rate); opp = dev_pm_opp_find_freq_floor(dev, &rate); } if (IS_ERR(opp)) { dev_err(dev, "failed to find OPP for %luHz: %pe\n", rate, opp); return PTR_ERR(opp); } pstate = dev_pm_opp_get_required_pstate(opp, 0); dev_pm_opp_put(opp); return dev_pm_genpd_set_performance_state(dev, pstate); } static int tegra_clock_change_notify(struct notifier_block *nb, unsigned long msg, void *data) { struct clk_notifier_data *cnd = data; struct tegra_clk_device *clk_dev; int err = 0; clk_dev = container_of(nb, struct tegra_clk_device, clk_nb); mutex_lock(&clk_dev->lock); switch (msg) { case PRE_RATE_CHANGE: if (cnd->new_rate > cnd->old_rate) err = tegra_clock_set_pd_state(clk_dev, cnd->new_rate); break; case ABORT_RATE_CHANGE: err = tegra_clock_set_pd_state(clk_dev, cnd->old_rate); break; case POST_RATE_CHANGE: if (cnd->new_rate < cnd->old_rate) err = tegra_clock_set_pd_state(clk_dev, cnd->new_rate); break; default: break; } mutex_unlock(&clk_dev->lock); return notifier_from_errno(err); } static int tegra_clock_sync_pd_state(struct tegra_clk_device *clk_dev) { unsigned long rate; int ret; mutex_lock(&clk_dev->lock); rate = clk_hw_get_rate(clk_dev->hw); ret = tegra_clock_set_pd_state(clk_dev, rate); mutex_unlock(&clk_dev->lock); return ret; } static int tegra_clock_probe(struct platform_device *pdev) { struct tegra_core_opp_params opp_params = {}; struct tegra_clk_device *clk_dev; struct device *dev = &pdev->dev; struct clk *clk; int err; if (!dev->pm_domain) return -EINVAL; clk_dev = devm_kzalloc(dev, sizeof(*clk_dev), GFP_KERNEL); if (!clk_dev) return -ENOMEM; clk = devm_clk_get(dev, NULL); if (IS_ERR(clk)) return PTR_ERR(clk); clk_dev->dev = dev; clk_dev->hw = __clk_get_hw(clk); clk_dev->clk_nb.notifier_call = tegra_clock_change_notify; mutex_init(&clk_dev->lock); platform_set_drvdata(pdev, clk_dev); /* * Runtime PM was already enabled for this device by the parent clk * driver and power domain state should be synced under clk_dev lock, * hence we don't use the common OPP helper that initializes OPP * state. For some clocks common OPP helper may fail to find ceil * rate, it's handled by this driver. */ err = devm_tegra_core_dev_init_opp_table(dev, &opp_params); if (err) return err; err = clk_notifier_register(clk, &clk_dev->clk_nb); if (err) { dev_err(dev, "failed to register clk notifier: %d\n", err); return err; } /* * The driver is attaching to a potentially active/resumed clock, hence * we need to sync the power domain performance state in a accordance to * the clock rate if clock is resumed. */ err = tegra_clock_sync_pd_state(clk_dev); if (err) goto unreg_clk; return 0; unreg_clk: clk_notifier_unregister(clk, &clk_dev->clk_nb); return err; } /* * Tegra GENPD driver enables clocks during NOIRQ phase. It can't be done * for clocks served by this driver because runtime PM is unavailable in * NOIRQ phase. We will keep clocks resumed during suspend to mitigate this * problem. In practice this makes no difference from a power management * perspective since voltage is kept at a nominal level during suspend anyways. */ static const struct dev_pm_ops tegra_clock_pm = { SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_resume_and_get, pm_runtime_put) }; static const struct of_device_id tegra_clock_match[] = { { .compatible = "nvidia,tegra20-sclk" }, { .compatible = "nvidia,tegra30-sclk" }, { .compatible = "nvidia,tegra30-pllc" }, { .compatible = "nvidia,tegra30-plle" }, { .compatible = "nvidia,tegra30-pllm" }, { } }; static struct platform_driver tegra_clock_driver = { .driver = { .name = "tegra-clock", .of_match_table = tegra_clock_match, .pm = &tegra_clock_pm, .suppress_bind_attrs = true, }, .probe = tegra_clock_probe, }; builtin_platform_driver(tegra_clock_driver);
linux-master
drivers/clk/tegra/clk-device.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2016-2022 NVIDIA Corporation */ #include <linux/clk-provider.h> #include <linux/device.h> #include <linux/seq_buf.h> #include <linux/slab.h> #include <soc/tegra/bpmp.h> #include <soc/tegra/bpmp-abi.h> #define TEGRA_BPMP_DUMP_CLOCK_INFO 0 #define TEGRA_BPMP_CLK_HAS_MUX BIT(0) #define TEGRA_BPMP_CLK_HAS_SET_RATE BIT(1) #define TEGRA_BPMP_CLK_IS_ROOT BIT(2) struct tegra_bpmp_clk_info { unsigned int id; char name[MRQ_CLK_NAME_MAXLEN]; unsigned int parents[MRQ_CLK_MAX_PARENTS]; unsigned int num_parents; unsigned long flags; }; struct tegra_bpmp_clk { struct clk_hw hw; struct tegra_bpmp *bpmp; unsigned int id; unsigned int num_parents; unsigned int *parents; }; static inline struct tegra_bpmp_clk *to_tegra_bpmp_clk(struct clk_hw *hw) { return container_of(hw, struct tegra_bpmp_clk, hw); } struct tegra_bpmp_clk_message { unsigned int cmd; unsigned int id; struct { const void *data; size_t size; } tx; struct { void *data; size_t size; int ret; } rx; }; static int tegra_bpmp_clk_transfer(struct tegra_bpmp *bpmp, const struct tegra_bpmp_clk_message *clk) { struct mrq_clk_request request; struct tegra_bpmp_message msg; void *req = &request; int err; memset(&request, 0, sizeof(request)); request.cmd_and_id = (clk->cmd << 24) | clk->id; /* * The mrq_clk_request structure has an anonymous union at offset 4 * that contains all possible sub-command structures. Copy the data * to that union. Ideally we'd be able to refer to it by name, but * doing so would require changing the ABI header and increase the * maintenance burden. */ memcpy(req + 4, clk->tx.data, clk->tx.size); memset(&msg, 0, sizeof(msg)); msg.mrq = MRQ_CLK; msg.tx.data = &request; msg.tx.size = sizeof(request); msg.rx.data = clk->rx.data; msg.rx.size = clk->rx.size; err = tegra_bpmp_transfer(bpmp, &msg); if (err < 0) return err; else if (msg.rx.ret < 0) return -EINVAL; return 0; } static int tegra_bpmp_clk_prepare(struct clk_hw *hw) { struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw); struct tegra_bpmp_clk_message msg; memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_ENABLE; msg.id = clk->id; return tegra_bpmp_clk_transfer(clk->bpmp, &msg); } static void tegra_bpmp_clk_unprepare(struct clk_hw *hw) { struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw); struct tegra_bpmp_clk_message msg; int err; memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_DISABLE; msg.id = clk->id; err = tegra_bpmp_clk_transfer(clk->bpmp, &msg); if (err < 0) dev_err(clk->bpmp->dev, "failed to disable clock %s: %d\n", clk_hw_get_name(hw), err); } static int tegra_bpmp_clk_is_prepared(struct clk_hw *hw) { struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw); struct cmd_clk_is_enabled_response response; struct tegra_bpmp_clk_message msg; int err; memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_IS_ENABLED; msg.id = clk->id; msg.rx.data = &response; msg.rx.size = sizeof(response); err = tegra_bpmp_clk_transfer(clk->bpmp, &msg); if (err < 0) return err; return response.state; } static unsigned long tegra_bpmp_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw); struct cmd_clk_get_rate_response response; struct cmd_clk_get_rate_request request; struct tegra_bpmp_clk_message msg; int err; memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_GET_RATE; msg.id = clk->id; msg.tx.data = &request; msg.tx.size = sizeof(request); msg.rx.data = &response; msg.rx.size = sizeof(response); err = tegra_bpmp_clk_transfer(clk->bpmp, &msg); if (err < 0) return err; return response.rate; } static int tegra_bpmp_clk_determine_rate(struct clk_hw *hw, struct clk_rate_request *rate_req) { struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw); struct cmd_clk_round_rate_response response; struct cmd_clk_round_rate_request request; struct tegra_bpmp_clk_message msg; unsigned long rate; int err; rate = min(max(rate_req->rate, rate_req->min_rate), rate_req->max_rate); memset(&request, 0, sizeof(request)); request.rate = min_t(u64, rate, S64_MAX); memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_ROUND_RATE; msg.id = clk->id; msg.tx.data = &request; msg.tx.size = sizeof(request); msg.rx.data = &response; msg.rx.size = sizeof(response); err = tegra_bpmp_clk_transfer(clk->bpmp, &msg); if (err < 0) return err; rate_req->rate = (unsigned long)response.rate; return 0; } static int tegra_bpmp_clk_set_parent(struct clk_hw *hw, u8 index) { struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw); struct cmd_clk_set_parent_response response; struct cmd_clk_set_parent_request request; struct tegra_bpmp_clk_message msg; int err; memset(&request, 0, sizeof(request)); request.parent_id = clk->parents[index]; memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_SET_PARENT; msg.id = clk->id; msg.tx.data = &request; msg.tx.size = sizeof(request); msg.rx.data = &response; msg.rx.size = sizeof(response); err = tegra_bpmp_clk_transfer(clk->bpmp, &msg); if (err < 0) return err; /* XXX check parent ID in response */ return 0; } static u8 tegra_bpmp_clk_get_parent(struct clk_hw *hw) { struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw); struct cmd_clk_get_parent_response response; struct tegra_bpmp_clk_message msg; unsigned int i; int err; memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_GET_PARENT; msg.id = clk->id; msg.rx.data = &response; msg.rx.size = sizeof(response); err = tegra_bpmp_clk_transfer(clk->bpmp, &msg); if (err < 0) { dev_err(clk->bpmp->dev, "failed to get parent for %s: %d\n", clk_hw_get_name(hw), err); return U8_MAX; } for (i = 0; i < clk->num_parents; i++) if (clk->parents[i] == response.parent_id) return i; return U8_MAX; } static int tegra_bpmp_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_bpmp_clk *clk = to_tegra_bpmp_clk(hw); struct cmd_clk_set_rate_response response; struct cmd_clk_set_rate_request request; struct tegra_bpmp_clk_message msg; memset(&request, 0, sizeof(request)); request.rate = min_t(u64, rate, S64_MAX); memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_SET_RATE; msg.id = clk->id; msg.tx.data = &request; msg.tx.size = sizeof(request); msg.rx.data = &response; msg.rx.size = sizeof(response); return tegra_bpmp_clk_transfer(clk->bpmp, &msg); } static const struct clk_ops tegra_bpmp_clk_gate_ops = { .prepare = tegra_bpmp_clk_prepare, .unprepare = tegra_bpmp_clk_unprepare, .is_prepared = tegra_bpmp_clk_is_prepared, .recalc_rate = tegra_bpmp_clk_recalc_rate, }; static const struct clk_ops tegra_bpmp_clk_mux_ops = { .prepare = tegra_bpmp_clk_prepare, .unprepare = tegra_bpmp_clk_unprepare, .is_prepared = tegra_bpmp_clk_is_prepared, .recalc_rate = tegra_bpmp_clk_recalc_rate, .determine_rate = clk_hw_determine_rate_no_reparent, .set_parent = tegra_bpmp_clk_set_parent, .get_parent = tegra_bpmp_clk_get_parent, }; static const struct clk_ops tegra_bpmp_clk_rate_ops = { .prepare = tegra_bpmp_clk_prepare, .unprepare = tegra_bpmp_clk_unprepare, .is_prepared = tegra_bpmp_clk_is_prepared, .recalc_rate = tegra_bpmp_clk_recalc_rate, .determine_rate = tegra_bpmp_clk_determine_rate, .set_rate = tegra_bpmp_clk_set_rate, }; static const struct clk_ops tegra_bpmp_clk_mux_rate_ops = { .prepare = tegra_bpmp_clk_prepare, .unprepare = tegra_bpmp_clk_unprepare, .is_prepared = tegra_bpmp_clk_is_prepared, .recalc_rate = tegra_bpmp_clk_recalc_rate, .determine_rate = tegra_bpmp_clk_determine_rate, .set_parent = tegra_bpmp_clk_set_parent, .get_parent = tegra_bpmp_clk_get_parent, .set_rate = tegra_bpmp_clk_set_rate, }; static const struct clk_ops tegra_bpmp_clk_mux_read_only_ops = { .get_parent = tegra_bpmp_clk_get_parent, .recalc_rate = tegra_bpmp_clk_recalc_rate, }; static const struct clk_ops tegra_bpmp_clk_read_only_ops = { .recalc_rate = tegra_bpmp_clk_recalc_rate, }; static const struct clk_ops tegra_bpmp_clk_gate_mux_read_only_ops = { .prepare = tegra_bpmp_clk_prepare, .unprepare = tegra_bpmp_clk_unprepare, .is_prepared = tegra_bpmp_clk_is_prepared, .recalc_rate = tegra_bpmp_clk_recalc_rate, .get_parent = tegra_bpmp_clk_get_parent, }; static int tegra_bpmp_clk_get_max_id(struct tegra_bpmp *bpmp) { struct cmd_clk_get_max_clk_id_response response; struct tegra_bpmp_clk_message msg; int err; memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_GET_MAX_CLK_ID; msg.rx.data = &response; msg.rx.size = sizeof(response); err = tegra_bpmp_clk_transfer(bpmp, &msg); if (err < 0) return err; if (response.max_id > INT_MAX) return -E2BIG; return response.max_id; } static int tegra_bpmp_clk_get_info(struct tegra_bpmp *bpmp, unsigned int id, struct tegra_bpmp_clk_info *info) { struct cmd_clk_get_all_info_response response; struct tegra_bpmp_clk_message msg; unsigned int i; int err; memset(&msg, 0, sizeof(msg)); msg.cmd = CMD_CLK_GET_ALL_INFO; msg.id = id; msg.rx.data = &response; msg.rx.size = sizeof(response); err = tegra_bpmp_clk_transfer(bpmp, &msg); if (err < 0) return err; strscpy(info->name, response.name, MRQ_CLK_NAME_MAXLEN); info->num_parents = response.num_parents; for (i = 0; i < info->num_parents; i++) info->parents[i] = response.parents[i]; info->flags = response.flags; return 0; } static void tegra_bpmp_clk_info_dump(struct tegra_bpmp *bpmp, const char *level, const struct tegra_bpmp_clk_info *info) { const char *prefix = ""; struct seq_buf buf; unsigned int i; char flags[64]; seq_buf_init(&buf, flags, sizeof(flags)); if (info->flags) seq_buf_printf(&buf, "("); if (info->flags & TEGRA_BPMP_CLK_HAS_MUX) { seq_buf_printf(&buf, "%smux", prefix); prefix = ", "; } if ((info->flags & TEGRA_BPMP_CLK_HAS_SET_RATE) == 0) { seq_buf_printf(&buf, "%sfixed", prefix); prefix = ", "; } if (info->flags & TEGRA_BPMP_CLK_IS_ROOT) { seq_buf_printf(&buf, "%sroot", prefix); prefix = ", "; } if (info->flags) seq_buf_printf(&buf, ")"); dev_printk(level, bpmp->dev, "%03u: %s\n", info->id, info->name); dev_printk(level, bpmp->dev, " flags: %lx %s\n", info->flags, flags); dev_printk(level, bpmp->dev, " parents: %u\n", info->num_parents); for (i = 0; i < info->num_parents; i++) dev_printk(level, bpmp->dev, " %03u\n", info->parents[i]); } static int tegra_bpmp_probe_clocks(struct tegra_bpmp *bpmp, struct tegra_bpmp_clk_info **clocksp) { struct tegra_bpmp_clk_info *clocks; unsigned int max_id, id, count = 0; unsigned int holes = 0; int err; err = tegra_bpmp_clk_get_max_id(bpmp); if (err < 0) return err; max_id = err; dev_dbg(bpmp->dev, "maximum clock ID: %u\n", max_id); clocks = kcalloc(max_id + 1, sizeof(*clocks), GFP_KERNEL); if (!clocks) return -ENOMEM; for (id = 0; id <= max_id; id++) { struct tegra_bpmp_clk_info *info = &clocks[count]; err = tegra_bpmp_clk_get_info(bpmp, id, info); if (err < 0) continue; if (info->num_parents >= U8_MAX) { dev_err(bpmp->dev, "clock %u has too many parents (%u, max: %u)\n", id, info->num_parents, U8_MAX); continue; } /* clock not exposed by BPMP */ if (info->name[0] == '\0') { holes++; continue; } info->id = id; count++; if (TEGRA_BPMP_DUMP_CLOCK_INFO) tegra_bpmp_clk_info_dump(bpmp, KERN_DEBUG, info); } dev_dbg(bpmp->dev, "holes: %u\n", holes); *clocksp = clocks; return count; } static unsigned int tegra_bpmp_clk_id_to_index(const struct tegra_bpmp_clk_info *clocks, unsigned int num_clocks, unsigned int id) { unsigned int i; for (i = 0; i < num_clocks; i++) if (clocks[i].id == id) return i; return UINT_MAX; } static const struct tegra_bpmp_clk_info * tegra_bpmp_clk_find(const struct tegra_bpmp_clk_info *clocks, unsigned int num_clocks, unsigned int id) { unsigned int i; i = tegra_bpmp_clk_id_to_index(clocks, num_clocks, id); if (i < num_clocks) return &clocks[i]; return NULL; } static struct tegra_bpmp_clk * tegra_bpmp_clk_register(struct tegra_bpmp *bpmp, const struct tegra_bpmp_clk_info *info, const struct tegra_bpmp_clk_info *clocks, unsigned int num_clocks) { struct tegra_bpmp_clk *clk; struct clk_init_data init; const char **parents; unsigned int i; int err; clk = devm_kzalloc(bpmp->dev, sizeof(*clk), GFP_KERNEL); if (!clk) return ERR_PTR(-ENOMEM); clk->id = info->id; clk->bpmp = bpmp; clk->parents = devm_kcalloc(bpmp->dev, info->num_parents, sizeof(*clk->parents), GFP_KERNEL); if (!clk->parents) return ERR_PTR(-ENOMEM); clk->num_parents = info->num_parents; /* hardware clock initialization */ memset(&init, 0, sizeof(init)); init.name = info->name; clk->hw.init = &init; if (info->flags & BPMP_CLK_STATE_CHANGE_DENIED) { if ((info->flags & BPMP_CLK_RATE_PARENT_CHANGE_DENIED) == 0) { dev_WARN(bpmp->dev, "Firmware bug! Inconsistent permission bits for clock %s. State and parent/rate changes disabled.", init.name); } if (info->flags & TEGRA_BPMP_CLK_HAS_MUX) init.ops = &tegra_bpmp_clk_mux_read_only_ops; else init.ops = &tegra_bpmp_clk_read_only_ops; } else if (info->flags & BPMP_CLK_RATE_PARENT_CHANGE_DENIED) { if (info->flags & TEGRA_BPMP_CLK_HAS_MUX) init.ops = &tegra_bpmp_clk_gate_mux_read_only_ops; else init.ops = &tegra_bpmp_clk_gate_ops; } else if (info->flags & TEGRA_BPMP_CLK_HAS_MUX) { if (info->flags & TEGRA_BPMP_CLK_HAS_SET_RATE) init.ops = &tegra_bpmp_clk_mux_rate_ops; else init.ops = &tegra_bpmp_clk_mux_ops; } else { if (info->flags & TEGRA_BPMP_CLK_HAS_SET_RATE) init.ops = &tegra_bpmp_clk_rate_ops; else init.ops = &tegra_bpmp_clk_gate_ops; } init.num_parents = info->num_parents; parents = kcalloc(info->num_parents, sizeof(*parents), GFP_KERNEL); if (!parents) return ERR_PTR(-ENOMEM); for (i = 0; i < info->num_parents; i++) { const struct tegra_bpmp_clk_info *parent; /* keep a private copy of the ID to parent index map */ clk->parents[i] = info->parents[i]; parent = tegra_bpmp_clk_find(clocks, num_clocks, info->parents[i]); if (!parent) { dev_err(bpmp->dev, "no parent %u found for %u\n", info->parents[i], info->id); continue; } parents[i] = parent->name; } init.parent_names = parents; err = devm_clk_hw_register(bpmp->dev, &clk->hw); kfree(parents); if (err < 0) return ERR_PTR(err); return clk; } static void tegra_bpmp_register_clocks_one(struct tegra_bpmp *bpmp, struct tegra_bpmp_clk_info *infos, unsigned int i, unsigned int count) { unsigned int j; struct tegra_bpmp_clk_info *info; struct tegra_bpmp_clk *clk; if (bpmp->clocks[i]) { /* already registered */ return; } info = &infos[i]; for (j = 0; j < info->num_parents; ++j) { unsigned int p_id = info->parents[j]; unsigned int p_i = tegra_bpmp_clk_id_to_index(infos, count, p_id); if (p_i < count) tegra_bpmp_register_clocks_one(bpmp, infos, p_i, count); } clk = tegra_bpmp_clk_register(bpmp, info, infos, count); if (IS_ERR(clk)) { dev_err(bpmp->dev, "failed to register clock %u (%s): %ld\n", info->id, info->name, PTR_ERR(clk)); /* intentionally store the error pointer to * bpmp->clocks[i] to avoid re-attempting the * registration later */ } bpmp->clocks[i] = clk; } static int tegra_bpmp_register_clocks(struct tegra_bpmp *bpmp, struct tegra_bpmp_clk_info *infos, unsigned int count) { unsigned int i; bpmp->num_clocks = count; bpmp->clocks = devm_kcalloc(bpmp->dev, count, sizeof(struct tegra_bpmp_clk), GFP_KERNEL); if (!bpmp->clocks) return -ENOMEM; for (i = 0; i < count; i++) { tegra_bpmp_register_clocks_one(bpmp, infos, i, count); } return 0; } static void tegra_bpmp_unregister_clocks(struct tegra_bpmp *bpmp) { unsigned int i; for (i = 0; i < bpmp->num_clocks; i++) clk_hw_unregister(&bpmp->clocks[i]->hw); } static struct clk_hw *tegra_bpmp_clk_of_xlate(struct of_phandle_args *clkspec, void *data) { unsigned int id = clkspec->args[0], i; struct tegra_bpmp *bpmp = data; for (i = 0; i < bpmp->num_clocks; i++) { struct tegra_bpmp_clk *clk = bpmp->clocks[i]; if (!clk) continue; if (clk->id == id) return &clk->hw; } return NULL; } int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp) { struct tegra_bpmp_clk_info *clocks; unsigned int count; int err; err = tegra_bpmp_probe_clocks(bpmp, &clocks); if (err < 0) return err; count = err; dev_dbg(bpmp->dev, "%u clocks probed\n", count); err = tegra_bpmp_register_clocks(bpmp, clocks, count); if (err < 0) goto free; err = of_clk_add_hw_provider(bpmp->dev->of_node, tegra_bpmp_clk_of_xlate, bpmp); if (err < 0) { tegra_bpmp_unregister_clocks(bpmp); goto free; } free: kfree(clocks); return err; }
linux-master
drivers/clk/tegra/clk-bpmp.c
// SPDX-License-Identifier: GPL-2.0-only /* * drivers/clk/tegra/clk-emc.c * * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. * * Author: * Mikko Perttunen <[email protected]> */ #include <linux/clk-provider.h> #include <linux/clk.h> #include <linux/clkdev.h> #include <linux/clk/tegra.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/io.h> #include <linux/module.h> #include <linux/of_address.h> #include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/sort.h> #include <linux/string.h> #include <soc/tegra/fuse.h> #include "clk.h" #define CLK_SOURCE_EMC 0x19c #define CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR_SHIFT 0 #define CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR_MASK 0xff #define CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR(x) (((x) & CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR_MASK) << \ CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR_SHIFT) #define CLK_SOURCE_EMC_EMC_2X_CLK_SRC_SHIFT 29 #define CLK_SOURCE_EMC_EMC_2X_CLK_SRC_MASK 0x7 #define CLK_SOURCE_EMC_EMC_2X_CLK_SRC(x) (((x) & CLK_SOURCE_EMC_EMC_2X_CLK_SRC_MASK) << \ CLK_SOURCE_EMC_EMC_2X_CLK_SRC_SHIFT) static const char * const emc_parent_clk_names[] = { "pll_m", "pll_c", "pll_p", "clk_m", "pll_m_ud", "pll_c2", "pll_c3", "pll_c_ud" }; /* * List of clock sources for various parents the EMC clock can have. * When we change the timing to a timing with a parent that has the same * clock source as the current parent, we must first change to a backup * timing that has a different clock source. */ #define EMC_SRC_PLL_M 0 #define EMC_SRC_PLL_C 1 #define EMC_SRC_PLL_P 2 #define EMC_SRC_CLK_M 3 #define EMC_SRC_PLL_C2 4 #define EMC_SRC_PLL_C3 5 static const char emc_parent_clk_sources[] = { EMC_SRC_PLL_M, EMC_SRC_PLL_C, EMC_SRC_PLL_P, EMC_SRC_CLK_M, EMC_SRC_PLL_M, EMC_SRC_PLL_C2, EMC_SRC_PLL_C3, EMC_SRC_PLL_C }; struct emc_timing { unsigned long rate, parent_rate; u8 parent_index; struct clk *parent; u32 ram_code; }; struct tegra_clk_emc { struct clk_hw hw; void __iomem *clk_regs; struct clk *prev_parent; bool changing_timing; struct device_node *emc_node; struct tegra_emc *emc; int num_timings; struct emc_timing *timings; spinlock_t *lock; tegra124_emc_prepare_timing_change_cb *prepare_timing_change; tegra124_emc_complete_timing_change_cb *complete_timing_change; }; /* Common clock framework callback implementations */ static unsigned long emc_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_emc *tegra; u32 val, div; tegra = container_of(hw, struct tegra_clk_emc, hw); /* * CCF wrongly assumes that the parent won't change during set_rate, * so get the parent rate explicitly. */ parent_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); val = readl(tegra->clk_regs + CLK_SOURCE_EMC); div = val & CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR_MASK; return parent_rate / (div + 2) * 2; } /* * Rounds up unless no higher rate exists, in which case down. This way is * safer since things have EMC rate floors. Also don't touch parent_rate * since we don't want the CCF to play with our parent clocks. */ static int emc_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct tegra_clk_emc *tegra; u8 ram_code = tegra_read_ram_code(); struct emc_timing *timing = NULL; int i, k, t; tegra = container_of(hw, struct tegra_clk_emc, hw); for (k = 0; k < tegra->num_timings; k++) { if (tegra->timings[k].ram_code == ram_code) break; } for (t = k; t < tegra->num_timings; t++) { if (tegra->timings[t].ram_code != ram_code) break; } for (i = k; i < t; i++) { timing = tegra->timings + i; if (timing->rate < req->rate && i != t - 1) continue; if (timing->rate > req->max_rate) { i = max(i, k + 1); req->rate = tegra->timings[i - 1].rate; return 0; } if (timing->rate < req->min_rate) continue; req->rate = timing->rate; return 0; } if (timing) { req->rate = timing->rate; return 0; } req->rate = clk_hw_get_rate(hw); return 0; } static u8 emc_get_parent(struct clk_hw *hw) { struct tegra_clk_emc *tegra; u32 val; tegra = container_of(hw, struct tegra_clk_emc, hw); val = readl(tegra->clk_regs + CLK_SOURCE_EMC); return (val >> CLK_SOURCE_EMC_EMC_2X_CLK_SRC_SHIFT) & CLK_SOURCE_EMC_EMC_2X_CLK_SRC_MASK; } static struct tegra_emc *emc_ensure_emc_driver(struct tegra_clk_emc *tegra) { struct platform_device *pdev; if (tegra->emc) return tegra->emc; if (!tegra->prepare_timing_change || !tegra->complete_timing_change) return NULL; if (!tegra->emc_node) return NULL; pdev = of_find_device_by_node(tegra->emc_node); if (!pdev) { pr_err("%s: could not get external memory controller\n", __func__); return NULL; } of_node_put(tegra->emc_node); tegra->emc_node = NULL; tegra->emc = platform_get_drvdata(pdev); if (!tegra->emc) { put_device(&pdev->dev); pr_err("%s: cannot find EMC driver\n", __func__); return NULL; } return tegra->emc; } static int emc_set_timing(struct tegra_clk_emc *tegra, struct emc_timing *timing) { int err; u8 div; u32 car_value; unsigned long flags = 0; struct tegra_emc *emc = emc_ensure_emc_driver(tegra); if (!emc) return -ENOENT; pr_debug("going to rate %ld prate %ld p %s\n", timing->rate, timing->parent_rate, __clk_get_name(timing->parent)); if (emc_get_parent(&tegra->hw) == timing->parent_index && clk_get_rate(timing->parent) != timing->parent_rate) { WARN_ONCE(1, "parent %s rate mismatch %lu %lu\n", __clk_get_name(timing->parent), clk_get_rate(timing->parent), timing->parent_rate); return -EINVAL; } tegra->changing_timing = true; err = clk_set_rate(timing->parent, timing->parent_rate); if (err) { pr_err("cannot change parent %s rate to %ld: %d\n", __clk_get_name(timing->parent), timing->parent_rate, err); return err; } err = clk_prepare_enable(timing->parent); if (err) { pr_err("cannot enable parent clock: %d\n", err); return err; } div = timing->parent_rate / (timing->rate / 2) - 2; err = tegra->prepare_timing_change(emc, timing->rate); if (err) { clk_disable_unprepare(timing->parent); return err; } spin_lock_irqsave(tegra->lock, flags); car_value = readl(tegra->clk_regs + CLK_SOURCE_EMC); car_value &= ~CLK_SOURCE_EMC_EMC_2X_CLK_SRC(~0); car_value |= CLK_SOURCE_EMC_EMC_2X_CLK_SRC(timing->parent_index); car_value &= ~CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR(~0); car_value |= CLK_SOURCE_EMC_EMC_2X_CLK_DIVISOR(div); writel(car_value, tegra->clk_regs + CLK_SOURCE_EMC); spin_unlock_irqrestore(tegra->lock, flags); tegra->complete_timing_change(emc, timing->rate); clk_hw_reparent(&tegra->hw, __clk_get_hw(timing->parent)); clk_disable_unprepare(tegra->prev_parent); tegra->prev_parent = timing->parent; tegra->changing_timing = false; return 0; } /* * Get backup timing to use as an intermediate step when a change between * two timings with the same clock source has been requested. First try to * find a timing with a higher clock rate to avoid a rate below any set rate * floors. If that is not possible, find a lower rate. */ static struct emc_timing *get_backup_timing(struct tegra_clk_emc *tegra, int timing_index) { int i; u32 ram_code = tegra_read_ram_code(); struct emc_timing *timing; for (i = timing_index+1; i < tegra->num_timings; i++) { timing = tegra->timings + i; if (timing->ram_code != ram_code) break; if (emc_parent_clk_sources[timing->parent_index] != emc_parent_clk_sources[ tegra->timings[timing_index].parent_index]) return timing; } for (i = timing_index-1; i >= 0; --i) { timing = tegra->timings + i; if (timing->ram_code != ram_code) break; if (emc_parent_clk_sources[timing->parent_index] != emc_parent_clk_sources[ tegra->timings[timing_index].parent_index]) return timing; } return NULL; } static int emc_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_emc *tegra; struct emc_timing *timing = NULL; int i, err; u32 ram_code = tegra_read_ram_code(); tegra = container_of(hw, struct tegra_clk_emc, hw); if (clk_hw_get_rate(hw) == rate) return 0; /* * When emc_set_timing changes the parent rate, CCF will propagate * that downward to us, so ignore any set_rate calls while a rate * change is already going on. */ if (tegra->changing_timing) return 0; for (i = 0; i < tegra->num_timings; i++) { if (tegra->timings[i].rate == rate && tegra->timings[i].ram_code == ram_code) { timing = tegra->timings + i; break; } } if (!timing) { pr_err("cannot switch to rate %ld without emc table\n", rate); return -EINVAL; } if (emc_parent_clk_sources[emc_get_parent(hw)] == emc_parent_clk_sources[timing->parent_index] && clk_get_rate(timing->parent) != timing->parent_rate) { /* * Parent clock source not changed but parent rate has changed, * need to temporarily switch to another parent */ struct emc_timing *backup_timing; backup_timing = get_backup_timing(tegra, i); if (!backup_timing) { pr_err("cannot find backup timing\n"); return -EINVAL; } pr_debug("using %ld as backup rate when going to %ld\n", backup_timing->rate, rate); err = emc_set_timing(tegra, backup_timing); if (err) { pr_err("cannot set backup timing: %d\n", err); return err; } } return emc_set_timing(tegra, timing); } /* Initialization and deinitialization */ static int load_one_timing_from_dt(struct tegra_clk_emc *tegra, struct emc_timing *timing, struct device_node *node) { int err, i; u32 tmp; err = of_property_read_u32(node, "clock-frequency", &tmp); if (err) { pr_err("timing %pOF: failed to read rate\n", node); return err; } timing->rate = tmp; err = of_property_read_u32(node, "nvidia,parent-clock-frequency", &tmp); if (err) { pr_err("timing %pOF: failed to read parent rate\n", node); return err; } timing->parent_rate = tmp; timing->parent = of_clk_get_by_name(node, "emc-parent"); if (IS_ERR(timing->parent)) { pr_err("timing %pOF: failed to get parent clock\n", node); return PTR_ERR(timing->parent); } timing->parent_index = 0xff; i = match_string(emc_parent_clk_names, ARRAY_SIZE(emc_parent_clk_names), __clk_get_name(timing->parent)); if (i < 0) { pr_err("timing %pOF: %s is not a valid parent\n", node, __clk_get_name(timing->parent)); clk_put(timing->parent); return -EINVAL; } timing->parent_index = i; return 0; } static int cmp_timings(const void *_a, const void *_b) { const struct emc_timing *a = _a; const struct emc_timing *b = _b; if (a->rate < b->rate) return -1; else if (a->rate == b->rate) return 0; else return 1; } static int load_timings_from_dt(struct tegra_clk_emc *tegra, struct device_node *node, u32 ram_code) { struct emc_timing *timings_ptr; struct device_node *child; int child_count = of_get_child_count(node); int i = 0, err; size_t size; size = (tegra->num_timings + child_count) * sizeof(struct emc_timing); tegra->timings = krealloc(tegra->timings, size, GFP_KERNEL); if (!tegra->timings) return -ENOMEM; timings_ptr = tegra->timings + tegra->num_timings; tegra->num_timings += child_count; for_each_child_of_node(node, child) { struct emc_timing *timing = timings_ptr + (i++); err = load_one_timing_from_dt(tegra, timing, child); if (err) { of_node_put(child); kfree(tegra->timings); return err; } timing->ram_code = ram_code; } sort(timings_ptr, child_count, sizeof(struct emc_timing), cmp_timings, NULL); return 0; } static const struct clk_ops tegra_clk_emc_ops = { .recalc_rate = emc_recalc_rate, .determine_rate = emc_determine_rate, .set_rate = emc_set_rate, .get_parent = emc_get_parent, }; struct clk *tegra124_clk_register_emc(void __iomem *base, struct device_node *np, spinlock_t *lock) { struct tegra_clk_emc *tegra; struct clk_init_data init; struct device_node *node; u32 node_ram_code; struct clk *clk; int err; tegra = kcalloc(1, sizeof(*tegra), GFP_KERNEL); if (!tegra) return ERR_PTR(-ENOMEM); tegra->clk_regs = base; tegra->lock = lock; tegra->num_timings = 0; for_each_child_of_node(np, node) { err = of_property_read_u32(node, "nvidia,ram-code", &node_ram_code); if (err) continue; /* * Store timings for all ram codes as we cannot read the * fuses until the apbmisc driver is loaded. */ err = load_timings_from_dt(tegra, node, node_ram_code); if (err) { of_node_put(node); kfree(tegra); return ERR_PTR(err); } } if (tegra->num_timings == 0) pr_warn("%s: no memory timings registered\n", __func__); tegra->emc_node = of_parse_phandle(np, "nvidia,external-memory-controller", 0); if (!tegra->emc_node) pr_warn("%s: couldn't find node for EMC driver\n", __func__); init.name = "emc"; init.ops = &tegra_clk_emc_ops; init.flags = CLK_IS_CRITICAL; init.parent_names = emc_parent_clk_names; init.num_parents = ARRAY_SIZE(emc_parent_clk_names); tegra->hw.init = &init; clk = clk_register(NULL, &tegra->hw); if (IS_ERR(clk)) return clk; tegra->prev_parent = clk_hw_get_parent_by_index( &tegra->hw, emc_get_parent(&tegra->hw))->clk; tegra->changing_timing = false; /* Allow debugging tools to see the EMC clock */ clk_register_clkdev(clk, "emc", "tegra-clk-debug"); return clk; }; void tegra124_clk_set_emc_callbacks(tegra124_emc_prepare_timing_change_cb *prep_cb, tegra124_emc_complete_timing_change_cb *complete_cb) { struct clk *clk = __clk_lookup("emc"); struct tegra_clk_emc *tegra; struct clk_hw *hw; if (clk) { hw = __clk_get_hw(clk); tegra = container_of(hw, struct tegra_clk_emc, hw); tegra->prepare_timing_change = prep_cb; tegra->complete_timing_change = complete_cb; } } EXPORT_SYMBOL_GPL(tegra124_clk_set_emc_callbacks); bool tegra124_clk_emc_driver_available(struct clk_hw *hw) { struct tegra_clk_emc *tegra = container_of(hw, struct tegra_clk_emc, hw); return tegra->prepare_timing_change && tegra->complete_timing_change; }
linux-master
drivers/clk/tegra/clk-tegra124-emc.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. */ #include <linux/clk-provider.h> #include <linux/io.h> #include "clk.h" static inline struct tegra_clk_periph_fixed * to_tegra_clk_periph_fixed(struct clk_hw *hw) { return container_of(hw, struct tegra_clk_periph_fixed, hw); } static int tegra_clk_periph_fixed_is_enabled(struct clk_hw *hw) { struct tegra_clk_periph_fixed *fixed = to_tegra_clk_periph_fixed(hw); u32 mask = 1 << (fixed->num % 32), value; value = readl(fixed->base + fixed->regs->enb_reg); if (value & mask) { value = readl(fixed->base + fixed->regs->rst_reg); if ((value & mask) == 0) return 1; } return 0; } static int tegra_clk_periph_fixed_enable(struct clk_hw *hw) { struct tegra_clk_periph_fixed *fixed = to_tegra_clk_periph_fixed(hw); u32 mask = 1 << (fixed->num % 32); writel(mask, fixed->base + fixed->regs->enb_set_reg); return 0; } static void tegra_clk_periph_fixed_disable(struct clk_hw *hw) { struct tegra_clk_periph_fixed *fixed = to_tegra_clk_periph_fixed(hw); u32 mask = 1 << (fixed->num % 32); writel(mask, fixed->base + fixed->regs->enb_clr_reg); } static unsigned long tegra_clk_periph_fixed_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_periph_fixed *fixed = to_tegra_clk_periph_fixed(hw); unsigned long long rate; rate = (unsigned long long)parent_rate * fixed->mul; do_div(rate, fixed->div); return (unsigned long)rate; } static const struct clk_ops tegra_clk_periph_fixed_ops = { .is_enabled = tegra_clk_periph_fixed_is_enabled, .enable = tegra_clk_periph_fixed_enable, .disable = tegra_clk_periph_fixed_disable, .recalc_rate = tegra_clk_periph_fixed_recalc_rate, }; struct clk *tegra_clk_register_periph_fixed(const char *name, const char *parent, unsigned long flags, void __iomem *base, unsigned int mul, unsigned int div, unsigned int num) { const struct tegra_clk_periph_regs *regs; struct tegra_clk_periph_fixed *fixed; struct clk_init_data init; struct clk *clk; regs = get_reg_bank(num); if (!regs) return ERR_PTR(-EINVAL); fixed = kzalloc(sizeof(*fixed), GFP_KERNEL); if (!fixed) return ERR_PTR(-ENOMEM); init.name = name; init.flags = flags; init.parent_names = parent ? &parent : NULL; init.num_parents = parent ? 1 : 0; init.ops = &tegra_clk_periph_fixed_ops; fixed->base = base; fixed->regs = regs; fixed->mul = mul; fixed->div = div; fixed->num = num; fixed->hw.init = &init; clk = clk_register(NULL, &fixed->hw); if (IS_ERR(clk)) kfree(fixed); return clk; }
linux-master
drivers/clk/tegra/clk-periph-fixed.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/delay.h> #include <linux/clk-provider.h> #include <linux/clkdev.h> #include <linux/init.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/clk/tegra.h> #include <soc/tegra/pmc.h> #include <dt-bindings/clock/tegra30-car.h> #include "clk.h" #include "clk-id.h" #define OSC_CTRL 0x50 #define OSC_CTRL_OSC_FREQ_MASK (0xF<<28) #define OSC_CTRL_OSC_FREQ_13MHZ (0X0<<28) #define OSC_CTRL_OSC_FREQ_19_2MHZ (0X4<<28) #define OSC_CTRL_OSC_FREQ_12MHZ (0X8<<28) #define OSC_CTRL_OSC_FREQ_26MHZ (0XC<<28) #define OSC_CTRL_OSC_FREQ_16_8MHZ (0X1<<28) #define OSC_CTRL_OSC_FREQ_38_4MHZ (0X5<<28) #define OSC_CTRL_OSC_FREQ_48MHZ (0X9<<28) #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK) #define OSC_CTRL_PLL_REF_DIV_MASK (3<<26) #define OSC_CTRL_PLL_REF_DIV_1 (0<<26) #define OSC_CTRL_PLL_REF_DIV_2 (1<<26) #define OSC_CTRL_PLL_REF_DIV_4 (2<<26) #define OSC_FREQ_DET 0x58 #define OSC_FREQ_DET_TRIG BIT(31) #define OSC_FREQ_DET_STATUS 0x5c #define OSC_FREQ_DET_BUSY BIT(31) #define OSC_FREQ_DET_CNT_MASK 0xffff #define CCLKG_BURST_POLICY 0x368 #define SUPER_CCLKG_DIVIDER 0x36c #define CCLKLP_BURST_POLICY 0x370 #define SUPER_CCLKLP_DIVIDER 0x374 #define SCLK_BURST_POLICY 0x028 #define SUPER_SCLK_DIVIDER 0x02c #define SYSTEM_CLK_RATE 0x030 #define TEGRA30_CLK_PERIPH_BANKS 5 #define PLLC_BASE 0x80 #define PLLC_MISC 0x8c #define PLLM_BASE 0x90 #define PLLM_MISC 0x9c #define PLLP_BASE 0xa0 #define PLLP_MISC 0xac #define PLLX_BASE 0xe0 #define PLLX_MISC 0xe4 #define PLLD_BASE 0xd0 #define PLLD_MISC 0xdc #define PLLD2_BASE 0x4b8 #define PLLD2_MISC 0x4bc #define PLLE_BASE 0xe8 #define PLLE_MISC 0xec #define PLLA_BASE 0xb0 #define PLLA_MISC 0xbc #define PLLU_BASE 0xc0 #define PLLU_MISC 0xcc #define PLL_MISC_LOCK_ENABLE 18 #define PLLDU_MISC_LOCK_ENABLE 22 #define PLLE_MISC_LOCK_ENABLE 9 #define PLL_BASE_LOCK BIT(27) #define PLLE_MISC_LOCK BIT(11) #define PLLE_AUX 0x48c #define PLLC_OUT 0x84 #define PLLM_OUT 0x94 #define PLLP_OUTA 0xa4 #define PLLP_OUTB 0xa8 #define PLLA_OUT 0xb4 #define AUDIO_SYNC_CLK_I2S0 0x4a0 #define AUDIO_SYNC_CLK_I2S1 0x4a4 #define AUDIO_SYNC_CLK_I2S2 0x4a8 #define AUDIO_SYNC_CLK_I2S3 0x4ac #define AUDIO_SYNC_CLK_I2S4 0x4b0 #define AUDIO_SYNC_CLK_SPDIF 0x4b4 #define CLK_SOURCE_SPDIF_OUT 0x108 #define CLK_SOURCE_PWM 0x110 #define CLK_SOURCE_D_AUDIO 0x3d0 #define CLK_SOURCE_DAM0 0x3d8 #define CLK_SOURCE_DAM1 0x3dc #define CLK_SOURCE_DAM2 0x3e0 #define CLK_SOURCE_3D2 0x3b0 #define CLK_SOURCE_2D 0x15c #define CLK_SOURCE_HDMI 0x18c #define CLK_SOURCE_DSIB 0xd0 #define CLK_SOURCE_SE 0x42c #define CLK_SOURCE_EMC 0x19c #define AUDIO_SYNC_DOUBLER 0x49c /* Tegra CPU clock and reset control regs */ #define TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX 0x4c #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET 0x340 #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR 0x344 #define TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR 0x34c #define TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470 #define CPU_CLOCK(cpu) (0x1 << (8 + cpu)) #define CPU_RESET(cpu) (0x1111ul << (cpu)) #define CLK_RESET_CCLK_BURST 0x20 #define CLK_RESET_CCLK_DIVIDER 0x24 #define CLK_RESET_PLLX_BASE 0xe0 #define CLK_RESET_PLLX_MISC 0xe4 #define CLK_RESET_SOURCE_CSITE 0x1d4 #define CLK_RESET_CCLK_BURST_POLICY_SHIFT 28 #define CLK_RESET_CCLK_RUN_POLICY_SHIFT 4 #define CLK_RESET_CCLK_IDLE_POLICY_SHIFT 0 #define CLK_RESET_CCLK_IDLE_POLICY 1 #define CLK_RESET_CCLK_RUN_POLICY 2 #define CLK_RESET_CCLK_BURST_POLICY_PLLX 8 /* PLLM override registers */ #define PMC_PLLM_WB0_OVERRIDE 0x1dc #ifdef CONFIG_PM_SLEEP static struct cpu_clk_suspend_context { u32 pllx_misc; u32 pllx_base; u32 cpu_burst; u32 clk_csite_src; u32 cclk_divider; } tegra30_cpu_clk_sctx; #endif static void __iomem *clk_base; static void __iomem *pmc_base; static unsigned long input_freq; static DEFINE_SPINLOCK(cml_lock); static DEFINE_SPINLOCK(pll_d_lock); #define TEGRA_INIT_DATA_MUX(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \ 30, 2, 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, \ _clk_num, _gate_flags, _clk_id) #define TEGRA_INIT_DATA_MUX8(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \ 29, 3, 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, \ _clk_num, _gate_flags, _clk_id) #define TEGRA_INIT_DATA_INT(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \ 30, 2, 0, 0, 8, 1, TEGRA_DIVIDER_INT | \ TEGRA_DIVIDER_ROUND_UP, _clk_num, \ _gate_flags, _clk_id) #define TEGRA_INIT_DATA_NODIV(_name, _parents, _offset, \ _mux_shift, _mux_width, _clk_num, \ _gate_flags, _clk_id) \ TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \ _mux_shift, _mux_width, 0, 0, 0, 0, 0,\ _clk_num, _gate_flags, \ _clk_id) static struct clk **clks; static struct tegra_clk_pll_freq_table pll_c_freq_table[] = { { 12000000, 1040000000, 520, 6, 1, 8 }, { 13000000, 1040000000, 480, 6, 1, 8 }, { 16800000, 1040000000, 495, 8, 1, 8 }, /* actual: 1039.5 MHz */ { 19200000, 1040000000, 325, 6, 1, 6 }, { 26000000, 1040000000, 520, 13, 1, 8 }, { 12000000, 832000000, 416, 6, 1, 8 }, { 13000000, 832000000, 832, 13, 1, 8 }, { 16800000, 832000000, 396, 8, 1, 8 }, /* actual: 831.6 MHz */ { 19200000, 832000000, 260, 6, 1, 8 }, { 26000000, 832000000, 416, 13, 1, 8 }, { 12000000, 624000000, 624, 12, 1, 8 }, { 13000000, 624000000, 624, 13, 1, 8 }, { 16800000, 600000000, 520, 14, 1, 8 }, { 19200000, 624000000, 520, 16, 1, 8 }, { 26000000, 624000000, 624, 26, 1, 8 }, { 12000000, 600000000, 600, 12, 1, 8 }, { 13000000, 600000000, 600, 13, 1, 8 }, { 16800000, 600000000, 500, 14, 1, 8 }, { 19200000, 600000000, 375, 12, 1, 6 }, { 26000000, 600000000, 600, 26, 1, 8 }, { 12000000, 520000000, 520, 12, 1, 8 }, { 13000000, 520000000, 520, 13, 1, 8 }, { 16800000, 520000000, 495, 16, 1, 8 }, /* actual: 519.75 MHz */ { 19200000, 520000000, 325, 12, 1, 6 }, { 26000000, 520000000, 520, 26, 1, 8 }, { 12000000, 416000000, 416, 12, 1, 8 }, { 13000000, 416000000, 416, 13, 1, 8 }, { 16800000, 416000000, 396, 16, 1, 8 }, /* actual: 415.8 MHz */ { 19200000, 416000000, 260, 12, 1, 6 }, { 26000000, 416000000, 416, 26, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_m_freq_table[] = { { 12000000, 666000000, 666, 12, 1, 8 }, { 13000000, 666000000, 666, 13, 1, 8 }, { 16800000, 666000000, 555, 14, 1, 8 }, { 19200000, 666000000, 555, 16, 1, 8 }, { 26000000, 666000000, 666, 26, 1, 8 }, { 12000000, 600000000, 600, 12, 1, 8 }, { 13000000, 600000000, 600, 13, 1, 8 }, { 16800000, 600000000, 500, 14, 1, 8 }, { 19200000, 600000000, 375, 12, 1, 6 }, { 26000000, 600000000, 600, 26, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { { 12000000, 216000000, 432, 12, 2, 8 }, { 13000000, 216000000, 432, 13, 2, 8 }, { 16800000, 216000000, 360, 14, 2, 8 }, { 19200000, 216000000, 360, 16, 2, 8 }, { 26000000, 216000000, 432, 26, 2, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_a_freq_table[] = { { 9600000, 564480000, 294, 5, 1, 4 }, { 9600000, 552960000, 288, 5, 1, 4 }, { 9600000, 24000000, 5, 2, 1, 1 }, { 28800000, 56448000, 49, 25, 1, 1 }, { 28800000, 73728000, 64, 25, 1, 1 }, { 28800000, 24000000, 5, 6, 1, 1 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { { 12000000, 216000000, 216, 12, 1, 4 }, { 13000000, 216000000, 216, 13, 1, 4 }, { 16800000, 216000000, 180, 14, 1, 4 }, { 19200000, 216000000, 180, 16, 1, 4 }, { 26000000, 216000000, 216, 26, 1, 4 }, { 12000000, 594000000, 594, 12, 1, 8 }, { 13000000, 594000000, 594, 13, 1, 8 }, { 16800000, 594000000, 495, 14, 1, 8 }, { 19200000, 594000000, 495, 16, 1, 8 }, { 26000000, 594000000, 594, 26, 1, 8 }, { 12000000, 1000000000, 1000, 12, 1, 12 }, { 13000000, 1000000000, 1000, 13, 1, 12 }, { 19200000, 1000000000, 625, 12, 1, 8 }, { 26000000, 1000000000, 1000, 26, 1, 12 }, { 0, 0, 0, 0, 0, 0 }, }; static const struct pdiv_map pllu_p[] = { { .pdiv = 1, .hw_val = 1 }, { .pdiv = 2, .hw_val = 0 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_u_freq_table[] = { { 12000000, 480000000, 960, 12, 2, 12 }, { 13000000, 480000000, 960, 13, 2, 12 }, { 16800000, 480000000, 400, 7, 2, 5 }, { 19200000, 480000000, 200, 4, 2, 3 }, { 26000000, 480000000, 960, 26, 2, 12 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_freq_table pll_x_freq_table[] = { /* 1.7 GHz */ { 12000000, 1700000000, 850, 6, 1, 8 }, { 13000000, 1700000000, 915, 7, 1, 8 }, /* actual: 1699.2 MHz */ { 16800000, 1700000000, 708, 7, 1, 8 }, /* actual: 1699.2 MHz */ { 19200000, 1700000000, 885, 10, 1, 8 }, /* actual: 1699.2 MHz */ { 26000000, 1700000000, 850, 13, 1, 8 }, /* 1.6 GHz */ { 12000000, 1600000000, 800, 6, 1, 8 }, { 13000000, 1600000000, 738, 6, 1, 8 }, /* actual: 1599.0 MHz */ { 16800000, 1600000000, 857, 9, 1, 8 }, /* actual: 1599.7 MHz */ { 19200000, 1600000000, 500, 6, 1, 8 }, { 26000000, 1600000000, 800, 13, 1, 8 }, /* 1.5 GHz */ { 12000000, 1500000000, 750, 6, 1, 8 }, { 13000000, 1500000000, 923, 8, 1, 8 }, /* actual: 1499.8 MHz */ { 16800000, 1500000000, 625, 7, 1, 8 }, { 19200000, 1500000000, 625, 8, 1, 8 }, { 26000000, 1500000000, 750, 13, 1, 8 }, /* 1.4 GHz */ { 12000000, 1400000000, 700, 6, 1, 8 }, { 13000000, 1400000000, 969, 9, 1, 8 }, /* actual: 1399.7 MHz */ { 16800000, 1400000000, 1000, 12, 1, 8 }, { 19200000, 1400000000, 875, 12, 1, 8 }, { 26000000, 1400000000, 700, 13, 1, 8 }, /* 1.3 GHz */ { 12000000, 1300000000, 975, 9, 1, 8 }, { 13000000, 1300000000, 1000, 10, 1, 8 }, { 16800000, 1300000000, 928, 12, 1, 8 }, /* actual: 1299.2 MHz */ { 19200000, 1300000000, 812, 12, 1, 8 }, /* actual: 1299.2 MHz */ { 26000000, 1300000000, 650, 13, 1, 8 }, /* 1.2 GHz */ { 12000000, 1200000000, 1000, 10, 1, 8 }, { 13000000, 1200000000, 923, 10, 1, 8 }, /* actual: 1199.9 MHz */ { 16800000, 1200000000, 1000, 14, 1, 8 }, { 19200000, 1200000000, 1000, 16, 1, 8 }, { 26000000, 1200000000, 600, 13, 1, 8 }, /* 1.1 GHz */ { 12000000, 1100000000, 825, 9, 1, 8 }, { 13000000, 1100000000, 846, 10, 1, 8 }, /* actual: 1099.8 MHz */ { 16800000, 1100000000, 982, 15, 1, 8 }, /* actual: 1099.8 MHz */ { 19200000, 1100000000, 859, 15, 1, 8 }, /* actual: 1099.5 MHz */ { 26000000, 1100000000, 550, 13, 1, 8 }, /* 1 GHz */ { 12000000, 1000000000, 1000, 12, 1, 8 }, { 13000000, 1000000000, 1000, 13, 1, 8 }, { 16800000, 1000000000, 833, 14, 1, 8 }, /* actual: 999.6 MHz */ { 19200000, 1000000000, 625, 12, 1, 8 }, { 26000000, 1000000000, 1000, 26, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static const struct pdiv_map plle_p[] = { { .pdiv = 18, .hw_val = 18 }, { .pdiv = 24, .hw_val = 24 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_e_freq_table[] = { /* PLLE special case: use cpcon field to store cml divider value */ { 12000000, 100000000, 150, 1, 18, 11 }, { 216000000, 100000000, 200, 18, 24, 13 }, { 0, 0, 0, 0, 0, 0 }, }; /* PLL parameters */ static struct tegra_clk_pll_params pll_c_params __ro_after_init = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1400000000, .base_reg = PLLC_BASE, .misc_reg = PLLC_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_c_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct div_nmp pllm_nmp = { .divn_shift = 8, .divn_width = 10, .override_divn_shift = 5, .divm_shift = 0, .divm_width = 5, .override_divm_shift = 0, .divp_shift = 20, .divp_width = 3, .override_divp_shift = 15, }; static struct tegra_clk_pll_params pll_m_params __ro_after_init = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1200000000, .base_reg = PLLM_BASE, .misc_reg = PLLM_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .div_nmp = &pllm_nmp, .pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE, .pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE, .freq_table = pll_m_freq_table, .flags = TEGRA_PLLM | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_DCCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE | TEGRA_PLL_FIXED, }; static struct tegra_clk_pll_params pll_p_params __ro_after_init = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1400000000, .base_reg = PLLP_BASE, .misc_reg = PLLP_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_p_freq_table, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, .fixed_rate = 408000000, }; static struct tegra_clk_pll_params pll_a_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1400000000, .base_reg = PLLA_BASE, .misc_reg = PLLA_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_a_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_d_params __ro_after_init = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 40000000, .vco_max = 1000000000, .base_reg = PLLD_BASE, .misc_reg = PLLD_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .freq_table = pll_d_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_d2_params __ro_after_init = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 40000000, .vco_max = 1000000000, .base_reg = PLLD2_BASE, .misc_reg = PLLD2_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .freq_table = pll_d_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_u_params __ro_after_init = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 48000000, .vco_max = 960000000, .base_reg = PLLU_BASE, .misc_reg = PLLU_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .pdiv_tohw = pllu_p, .freq_table = pll_u_freq_table, .flags = TEGRA_PLLU | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_x_params __ro_after_init = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 20000000, .vco_max = 1700000000, .base_reg = PLLX_BASE, .misc_reg = PLLX_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .freq_table = pll_x_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_DCCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, .pre_rate_change = tegra_cclk_pre_pllx_rate_change, .post_rate_change = tegra_cclk_post_pllx_rate_change, }; static struct tegra_clk_pll_params pll_e_params __ro_after_init = { .input_min = 12000000, .input_max = 216000000, .cf_min = 12000000, .cf_max = 12000000, .vco_min = 1200000000, .vco_max = 2400000000U, .base_reg = PLLE_BASE, .misc_reg = PLLE_MISC, .lock_mask = PLLE_MISC_LOCK, .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE, .lock_delay = 300, .pdiv_tohw = plle_p, .freq_table = pll_e_freq_table, .flags = TEGRA_PLLE_CONFIGURE | TEGRA_PLL_FIXED | TEGRA_PLL_HAS_LOCK_ENABLE | TEGRA_PLL_LOCK_MISC, .fixed_rate = 100000000, }; static unsigned long tegra30_input_freq[] = { [ 0] = 13000000, [ 1] = 16800000, [ 4] = 19200000, [ 5] = 38400000, [ 8] = 12000000, [ 9] = 48000000, [12] = 26000000, }; static struct tegra_devclk devclks[] = { { .con_id = "pll_c", .dt_id = TEGRA30_CLK_PLL_C }, { .con_id = "pll_c_out1", .dt_id = TEGRA30_CLK_PLL_C_OUT1 }, { .con_id = "pll_p", .dt_id = TEGRA30_CLK_PLL_P }, { .con_id = "pll_p_out1", .dt_id = TEGRA30_CLK_PLL_P_OUT1 }, { .con_id = "pll_p_out2", .dt_id = TEGRA30_CLK_PLL_P_OUT2 }, { .con_id = "pll_p_out3", .dt_id = TEGRA30_CLK_PLL_P_OUT3 }, { .con_id = "pll_p_out4", .dt_id = TEGRA30_CLK_PLL_P_OUT4 }, { .con_id = "pll_m", .dt_id = TEGRA30_CLK_PLL_M }, { .con_id = "pll_m_out1", .dt_id = TEGRA30_CLK_PLL_M_OUT1 }, { .con_id = "pll_x", .dt_id = TEGRA30_CLK_PLL_X }, { .con_id = "pll_x_out0", .dt_id = TEGRA30_CLK_PLL_X_OUT0 }, { .con_id = "pll_u", .dt_id = TEGRA30_CLK_PLL_U }, { .con_id = "pll_d", .dt_id = TEGRA30_CLK_PLL_D }, { .con_id = "pll_d_out0", .dt_id = TEGRA30_CLK_PLL_D_OUT0 }, { .con_id = "pll_d2", .dt_id = TEGRA30_CLK_PLL_D2 }, { .con_id = "pll_d2_out0", .dt_id = TEGRA30_CLK_PLL_D2_OUT0 }, { .con_id = "pll_a", .dt_id = TEGRA30_CLK_PLL_A }, { .con_id = "pll_a_out0", .dt_id = TEGRA30_CLK_PLL_A_OUT0 }, { .con_id = "pll_e", .dt_id = TEGRA30_CLK_PLL_E }, { .con_id = "spdif_in_sync", .dt_id = TEGRA30_CLK_SPDIF_IN_SYNC }, { .con_id = "i2s0_sync", .dt_id = TEGRA30_CLK_I2S0_SYNC }, { .con_id = "i2s1_sync", .dt_id = TEGRA30_CLK_I2S1_SYNC }, { .con_id = "i2s2_sync", .dt_id = TEGRA30_CLK_I2S2_SYNC }, { .con_id = "i2s3_sync", .dt_id = TEGRA30_CLK_I2S3_SYNC }, { .con_id = "i2s4_sync", .dt_id = TEGRA30_CLK_I2S4_SYNC }, { .con_id = "vimclk_sync", .dt_id = TEGRA30_CLK_VIMCLK_SYNC }, { .con_id = "audio0", .dt_id = TEGRA30_CLK_AUDIO0 }, { .con_id = "audio1", .dt_id = TEGRA30_CLK_AUDIO1 }, { .con_id = "audio2", .dt_id = TEGRA30_CLK_AUDIO2 }, { .con_id = "audio3", .dt_id = TEGRA30_CLK_AUDIO3 }, { .con_id = "audio4", .dt_id = TEGRA30_CLK_AUDIO4 }, { .con_id = "spdif", .dt_id = TEGRA30_CLK_SPDIF }, { .con_id = "audio0_2x", .dt_id = TEGRA30_CLK_AUDIO0_2X }, { .con_id = "audio1_2x", .dt_id = TEGRA30_CLK_AUDIO1_2X }, { .con_id = "audio2_2x", .dt_id = TEGRA30_CLK_AUDIO2_2X }, { .con_id = "audio3_2x", .dt_id = TEGRA30_CLK_AUDIO3_2X }, { .con_id = "audio4_2x", .dt_id = TEGRA30_CLK_AUDIO4_2X }, { .con_id = "spdif_2x", .dt_id = TEGRA30_CLK_SPDIF_2X }, { .con_id = "extern1", .dt_id = TEGRA30_CLK_EXTERN1 }, { .con_id = "extern2", .dt_id = TEGRA30_CLK_EXTERN2 }, { .con_id = "extern3", .dt_id = TEGRA30_CLK_EXTERN3 }, { .con_id = "cclk_g", .dt_id = TEGRA30_CLK_CCLK_G }, { .con_id = "cclk_lp", .dt_id = TEGRA30_CLK_CCLK_LP }, { .con_id = "sclk", .dt_id = TEGRA30_CLK_SCLK }, { .con_id = "hclk", .dt_id = TEGRA30_CLK_HCLK }, { .con_id = "pclk", .dt_id = TEGRA30_CLK_PCLK }, { .con_id = "twd", .dt_id = TEGRA30_CLK_TWD }, { .con_id = "emc", .dt_id = TEGRA30_CLK_EMC }, { .con_id = "clk_32k", .dt_id = TEGRA30_CLK_CLK_32K }, { .con_id = "osc", .dt_id = TEGRA30_CLK_OSC }, { .con_id = "osc_div2", .dt_id = TEGRA30_CLK_OSC_DIV2 }, { .con_id = "osc_div4", .dt_id = TEGRA30_CLK_OSC_DIV4 }, { .con_id = "cml0", .dt_id = TEGRA30_CLK_CML0 }, { .con_id = "cml1", .dt_id = TEGRA30_CLK_CML1 }, { .con_id = "clk_m", .dt_id = TEGRA30_CLK_CLK_M }, { .con_id = "pll_ref", .dt_id = TEGRA30_CLK_PLL_REF }, { .con_id = "csus", .dev_id = "tengra_camera", .dt_id = TEGRA30_CLK_CSUS }, { .con_id = "vcp", .dev_id = "tegra-avp", .dt_id = TEGRA30_CLK_VCP }, { .con_id = "bsea", .dev_id = "tegra-avp", .dt_id = TEGRA30_CLK_BSEA }, { .con_id = "bsev", .dev_id = "tegra-aes", .dt_id = TEGRA30_CLK_BSEV }, { .con_id = "dsia", .dev_id = "tegradc.0", .dt_id = TEGRA30_CLK_DSIA }, { .con_id = "csi", .dev_id = "tegra_camera", .dt_id = TEGRA30_CLK_CSI }, { .con_id = "isp", .dev_id = "tegra_camera", .dt_id = TEGRA30_CLK_ISP }, { .con_id = "pcie", .dev_id = "tegra-pcie", .dt_id = TEGRA30_CLK_PCIE }, { .con_id = "afi", .dev_id = "tegra-pcie", .dt_id = TEGRA30_CLK_AFI }, { .con_id = "fuse", .dt_id = TEGRA30_CLK_FUSE }, { .con_id = "fuse_burn", .dev_id = "fuse-tegra", .dt_id = TEGRA30_CLK_FUSE_BURN }, { .con_id = "apbif", .dev_id = "tegra30-ahub", .dt_id = TEGRA30_CLK_APBIF }, { .con_id = "hda2hdmi", .dev_id = "tegra30-hda", .dt_id = TEGRA30_CLK_HDA2HDMI }, { .dev_id = "tegra-apbdma", .dt_id = TEGRA30_CLK_APBDMA }, { .dev_id = "rtc-tegra", .dt_id = TEGRA30_CLK_RTC }, { .dev_id = "timer", .dt_id = TEGRA30_CLK_TIMER }, { .dev_id = "tegra-kbc", .dt_id = TEGRA30_CLK_KBC }, { .dev_id = "fsl-tegra-udc", .dt_id = TEGRA30_CLK_USBD }, { .dev_id = "tegra-ehci.1", .dt_id = TEGRA30_CLK_USB2 }, { .dev_id = "tegra-ehci.2", .dt_id = TEGRA30_CLK_USB2 }, { .dev_id = "kfuse-tegra", .dt_id = TEGRA30_CLK_KFUSE }, { .dev_id = "tegra_sata_cold", .dt_id = TEGRA30_CLK_SATA_COLD }, { .dev_id = "dtv", .dt_id = TEGRA30_CLK_DTV }, { .dev_id = "tegra30-i2s.0", .dt_id = TEGRA30_CLK_I2S0 }, { .dev_id = "tegra30-i2s.1", .dt_id = TEGRA30_CLK_I2S1 }, { .dev_id = "tegra30-i2s.2", .dt_id = TEGRA30_CLK_I2S2 }, { .dev_id = "tegra30-i2s.3", .dt_id = TEGRA30_CLK_I2S3 }, { .dev_id = "tegra30-i2s.4", .dt_id = TEGRA30_CLK_I2S4 }, { .con_id = "spdif_out", .dev_id = "tegra30-spdif", .dt_id = TEGRA30_CLK_SPDIF_OUT }, { .con_id = "spdif_in", .dev_id = "tegra30-spdif", .dt_id = TEGRA30_CLK_SPDIF_IN }, { .con_id = "d_audio", .dev_id = "tegra30-ahub", .dt_id = TEGRA30_CLK_D_AUDIO }, { .dev_id = "tegra30-dam.0", .dt_id = TEGRA30_CLK_DAM0 }, { .dev_id = "tegra30-dam.1", .dt_id = TEGRA30_CLK_DAM1 }, { .dev_id = "tegra30-dam.2", .dt_id = TEGRA30_CLK_DAM2 }, { .con_id = "hda", .dev_id = "tegra30-hda", .dt_id = TEGRA30_CLK_HDA }, { .con_id = "hda2codec_2x", .dev_id = "tegra30-hda", .dt_id = TEGRA30_CLK_HDA2CODEC_2X }, { .dev_id = "spi_tegra.0", .dt_id = TEGRA30_CLK_SBC1 }, { .dev_id = "spi_tegra.1", .dt_id = TEGRA30_CLK_SBC2 }, { .dev_id = "spi_tegra.2", .dt_id = TEGRA30_CLK_SBC3 }, { .dev_id = "spi_tegra.3", .dt_id = TEGRA30_CLK_SBC4 }, { .dev_id = "spi_tegra.4", .dt_id = TEGRA30_CLK_SBC5 }, { .dev_id = "spi_tegra.5", .dt_id = TEGRA30_CLK_SBC6 }, { .dev_id = "tegra_sata_oob", .dt_id = TEGRA30_CLK_SATA_OOB }, { .dev_id = "tegra_sata", .dt_id = TEGRA30_CLK_SATA }, { .dev_id = "tegra_nand", .dt_id = TEGRA30_CLK_NDFLASH }, { .dev_id = "tegra_nand_speed", .dt_id = TEGRA30_CLK_NDSPEED }, { .dev_id = "vfir", .dt_id = TEGRA30_CLK_VFIR }, { .dev_id = "csite", .dt_id = TEGRA30_CLK_CSITE }, { .dev_id = "la", .dt_id = TEGRA30_CLK_LA }, { .dev_id = "tegra_w1", .dt_id = TEGRA30_CLK_OWR }, { .dev_id = "mipi", .dt_id = TEGRA30_CLK_MIPI }, { .dev_id = "tegra-tsensor", .dt_id = TEGRA30_CLK_TSENSOR }, { .dev_id = "i2cslow", .dt_id = TEGRA30_CLK_I2CSLOW }, { .dev_id = "vde", .dt_id = TEGRA30_CLK_VDE }, { .con_id = "vi", .dev_id = "tegra_camera", .dt_id = TEGRA30_CLK_VI }, { .dev_id = "epp", .dt_id = TEGRA30_CLK_EPP }, { .dev_id = "mpe", .dt_id = TEGRA30_CLK_MPE }, { .dev_id = "host1x", .dt_id = TEGRA30_CLK_HOST1X }, { .dev_id = "3d", .dt_id = TEGRA30_CLK_GR3D }, { .dev_id = "3d2", .dt_id = TEGRA30_CLK_GR3D2 }, { .dev_id = "2d", .dt_id = TEGRA30_CLK_GR2D }, { .dev_id = "se", .dt_id = TEGRA30_CLK_SE }, { .dev_id = "mselect", .dt_id = TEGRA30_CLK_MSELECT }, { .dev_id = "tegra-nor", .dt_id = TEGRA30_CLK_NOR }, { .dev_id = "sdhci-tegra.0", .dt_id = TEGRA30_CLK_SDMMC1 }, { .dev_id = "sdhci-tegra.1", .dt_id = TEGRA30_CLK_SDMMC2 }, { .dev_id = "sdhci-tegra.2", .dt_id = TEGRA30_CLK_SDMMC3 }, { .dev_id = "sdhci-tegra.3", .dt_id = TEGRA30_CLK_SDMMC4 }, { .dev_id = "cve", .dt_id = TEGRA30_CLK_CVE }, { .dev_id = "tvo", .dt_id = TEGRA30_CLK_TVO }, { .dev_id = "tvdac", .dt_id = TEGRA30_CLK_TVDAC }, { .dev_id = "actmon", .dt_id = TEGRA30_CLK_ACTMON }, { .con_id = "vi_sensor", .dev_id = "tegra_camera", .dt_id = TEGRA30_CLK_VI_SENSOR }, { .con_id = "div-clk", .dev_id = "tegra-i2c.0", .dt_id = TEGRA30_CLK_I2C1 }, { .con_id = "div-clk", .dev_id = "tegra-i2c.1", .dt_id = TEGRA30_CLK_I2C2 }, { .con_id = "div-clk", .dev_id = "tegra-i2c.2", .dt_id = TEGRA30_CLK_I2C3 }, { .con_id = "div-clk", .dev_id = "tegra-i2c.3", .dt_id = TEGRA30_CLK_I2C4 }, { .con_id = "div-clk", .dev_id = "tegra-i2c.4", .dt_id = TEGRA30_CLK_I2C5 }, { .dev_id = "tegra_uart.0", .dt_id = TEGRA30_CLK_UARTA }, { .dev_id = "tegra_uart.1", .dt_id = TEGRA30_CLK_UARTB }, { .dev_id = "tegra_uart.2", .dt_id = TEGRA30_CLK_UARTC }, { .dev_id = "tegra_uart.3", .dt_id = TEGRA30_CLK_UARTD }, { .dev_id = "tegra_uart.4", .dt_id = TEGRA30_CLK_UARTE }, { .dev_id = "hdmi", .dt_id = TEGRA30_CLK_HDMI }, { .dev_id = "extern1", .dt_id = TEGRA30_CLK_EXTERN1 }, { .dev_id = "extern2", .dt_id = TEGRA30_CLK_EXTERN2 }, { .dev_id = "extern3", .dt_id = TEGRA30_CLK_EXTERN3 }, { .dev_id = "pwm", .dt_id = TEGRA30_CLK_PWM }, { .dev_id = "tegradc.0", .dt_id = TEGRA30_CLK_DISP1 }, { .dev_id = "tegradc.1", .dt_id = TEGRA30_CLK_DISP2 }, { .dev_id = "tegradc.1", .dt_id = TEGRA30_CLK_DSIB }, }; static struct tegra_clk tegra30_clks[tegra_clk_max] __initdata = { [tegra_clk_clk_32k] = { .dt_id = TEGRA30_CLK_CLK_32K, .present = true }, [tegra_clk_clk_m] = { .dt_id = TEGRA30_CLK_CLK_M, .present = true }, [tegra_clk_osc] = { .dt_id = TEGRA30_CLK_OSC, .present = true }, [tegra_clk_osc_div2] = { .dt_id = TEGRA30_CLK_OSC_DIV2, .present = true }, [tegra_clk_osc_div4] = { .dt_id = TEGRA30_CLK_OSC_DIV4, .present = true }, [tegra_clk_pll_ref] = { .dt_id = TEGRA30_CLK_PLL_REF, .present = true }, [tegra_clk_spdif_in_sync] = { .dt_id = TEGRA30_CLK_SPDIF_IN_SYNC, .present = true }, [tegra_clk_i2s0_sync] = { .dt_id = TEGRA30_CLK_I2S0_SYNC, .present = true }, [tegra_clk_i2s1_sync] = { .dt_id = TEGRA30_CLK_I2S1_SYNC, .present = true }, [tegra_clk_i2s2_sync] = { .dt_id = TEGRA30_CLK_I2S2_SYNC, .present = true }, [tegra_clk_i2s3_sync] = { .dt_id = TEGRA30_CLK_I2S3_SYNC, .present = true }, [tegra_clk_i2s4_sync] = { .dt_id = TEGRA30_CLK_I2S4_SYNC, .present = true }, [tegra_clk_vimclk_sync] = { .dt_id = TEGRA30_CLK_VIMCLK_SYNC, .present = true }, [tegra_clk_audio0] = { .dt_id = TEGRA30_CLK_AUDIO0, .present = true }, [tegra_clk_audio1] = { .dt_id = TEGRA30_CLK_AUDIO1, .present = true }, [tegra_clk_audio2] = { .dt_id = TEGRA30_CLK_AUDIO2, .present = true }, [tegra_clk_audio3] = { .dt_id = TEGRA30_CLK_AUDIO3, .present = true }, [tegra_clk_audio4] = { .dt_id = TEGRA30_CLK_AUDIO4, .present = true }, [tegra_clk_spdif] = { .dt_id = TEGRA30_CLK_SPDIF, .present = true }, [tegra_clk_audio0_mux] = { .dt_id = TEGRA30_CLK_AUDIO0_MUX, .present = true }, [tegra_clk_audio1_mux] = { .dt_id = TEGRA30_CLK_AUDIO1_MUX, .present = true }, [tegra_clk_audio2_mux] = { .dt_id = TEGRA30_CLK_AUDIO2_MUX, .present = true }, [tegra_clk_audio3_mux] = { .dt_id = TEGRA30_CLK_AUDIO3_MUX, .present = true }, [tegra_clk_audio4_mux] = { .dt_id = TEGRA30_CLK_AUDIO4_MUX, .present = true }, [tegra_clk_spdif_mux] = { .dt_id = TEGRA30_CLK_SPDIF_MUX, .present = true }, [tegra_clk_audio0_2x] = { .dt_id = TEGRA30_CLK_AUDIO0_2X, .present = true }, [tegra_clk_audio1_2x] = { .dt_id = TEGRA30_CLK_AUDIO1_2X, .present = true }, [tegra_clk_audio2_2x] = { .dt_id = TEGRA30_CLK_AUDIO2_2X, .present = true }, [tegra_clk_audio3_2x] = { .dt_id = TEGRA30_CLK_AUDIO3_2X, .present = true }, [tegra_clk_audio4_2x] = { .dt_id = TEGRA30_CLK_AUDIO4_2X, .present = true }, [tegra_clk_spdif_2x] = { .dt_id = TEGRA30_CLK_SPDIF_2X, .present = true }, [tegra_clk_hclk] = { .dt_id = TEGRA30_CLK_HCLK, .present = true }, [tegra_clk_pclk] = { .dt_id = TEGRA30_CLK_PCLK, .present = true }, [tegra_clk_i2s0] = { .dt_id = TEGRA30_CLK_I2S0, .present = true }, [tegra_clk_i2s1] = { .dt_id = TEGRA30_CLK_I2S1, .present = true }, [tegra_clk_i2s2] = { .dt_id = TEGRA30_CLK_I2S2, .present = true }, [tegra_clk_i2s3] = { .dt_id = TEGRA30_CLK_I2S3, .present = true }, [tegra_clk_i2s4] = { .dt_id = TEGRA30_CLK_I2S4, .present = true }, [tegra_clk_spdif_in] = { .dt_id = TEGRA30_CLK_SPDIF_IN, .present = true }, [tegra_clk_hda] = { .dt_id = TEGRA30_CLK_HDA, .present = true }, [tegra_clk_hda2codec_2x] = { .dt_id = TEGRA30_CLK_HDA2CODEC_2X, .present = true }, [tegra_clk_sbc1] = { .dt_id = TEGRA30_CLK_SBC1, .present = true }, [tegra_clk_sbc2] = { .dt_id = TEGRA30_CLK_SBC2, .present = true }, [tegra_clk_sbc3] = { .dt_id = TEGRA30_CLK_SBC3, .present = true }, [tegra_clk_sbc4] = { .dt_id = TEGRA30_CLK_SBC4, .present = true }, [tegra_clk_sbc5] = { .dt_id = TEGRA30_CLK_SBC5, .present = true }, [tegra_clk_sbc6] = { .dt_id = TEGRA30_CLK_SBC6, .present = true }, [tegra_clk_ndflash] = { .dt_id = TEGRA30_CLK_NDFLASH, .present = true }, [tegra_clk_ndspeed] = { .dt_id = TEGRA30_CLK_NDSPEED, .present = true }, [tegra_clk_vfir] = { .dt_id = TEGRA30_CLK_VFIR, .present = true }, [tegra_clk_la] = { .dt_id = TEGRA30_CLK_LA, .present = true }, [tegra_clk_csite] = { .dt_id = TEGRA30_CLK_CSITE, .present = true }, [tegra_clk_owr] = { .dt_id = TEGRA30_CLK_OWR, .present = true }, [tegra_clk_mipi] = { .dt_id = TEGRA30_CLK_MIPI, .present = true }, [tegra_clk_tsensor] = { .dt_id = TEGRA30_CLK_TSENSOR, .present = true }, [tegra_clk_i2cslow] = { .dt_id = TEGRA30_CLK_I2CSLOW, .present = true }, [tegra_clk_vde] = { .dt_id = TEGRA30_CLK_VDE, .present = true }, [tegra_clk_vi] = { .dt_id = TEGRA30_CLK_VI, .present = true }, [tegra_clk_epp] = { .dt_id = TEGRA30_CLK_EPP, .present = true }, [tegra_clk_mpe] = { .dt_id = TEGRA30_CLK_MPE, .present = true }, [tegra_clk_host1x] = { .dt_id = TEGRA30_CLK_HOST1X, .present = true }, [tegra_clk_gr2d] = { .dt_id = TEGRA30_CLK_GR2D, .present = true }, [tegra_clk_gr3d] = { .dt_id = TEGRA30_CLK_GR3D, .present = true }, [tegra_clk_mselect] = { .dt_id = TEGRA30_CLK_MSELECT, .present = true }, [tegra_clk_nor] = { .dt_id = TEGRA30_CLK_NOR, .present = true }, [tegra_clk_sdmmc1] = { .dt_id = TEGRA30_CLK_SDMMC1, .present = true }, [tegra_clk_sdmmc2] = { .dt_id = TEGRA30_CLK_SDMMC2, .present = true }, [tegra_clk_sdmmc3] = { .dt_id = TEGRA30_CLK_SDMMC3, .present = true }, [tegra_clk_sdmmc4] = { .dt_id = TEGRA30_CLK_SDMMC4, .present = true }, [tegra_clk_cve] = { .dt_id = TEGRA30_CLK_CVE, .present = true }, [tegra_clk_tvo] = { .dt_id = TEGRA30_CLK_TVO, .present = true }, [tegra_clk_tvdac] = { .dt_id = TEGRA30_CLK_TVDAC, .present = true }, [tegra_clk_actmon] = { .dt_id = TEGRA30_CLK_ACTMON, .present = true }, [tegra_clk_vi_sensor] = { .dt_id = TEGRA30_CLK_VI_SENSOR, .present = true }, [tegra_clk_i2c1] = { .dt_id = TEGRA30_CLK_I2C1, .present = true }, [tegra_clk_i2c2] = { .dt_id = TEGRA30_CLK_I2C2, .present = true }, [tegra_clk_i2c3] = { .dt_id = TEGRA30_CLK_I2C3, .present = true }, [tegra_clk_i2c4] = { .dt_id = TEGRA30_CLK_I2C4, .present = true }, [tegra_clk_i2c5] = { .dt_id = TEGRA30_CLK_I2C5, .present = true }, [tegra_clk_uarta] = { .dt_id = TEGRA30_CLK_UARTA, .present = true }, [tegra_clk_uartb] = { .dt_id = TEGRA30_CLK_UARTB, .present = true }, [tegra_clk_uartc] = { .dt_id = TEGRA30_CLK_UARTC, .present = true }, [tegra_clk_uartd] = { .dt_id = TEGRA30_CLK_UARTD, .present = true }, [tegra_clk_uarte] = { .dt_id = TEGRA30_CLK_UARTE, .present = true }, [tegra_clk_extern1] = { .dt_id = TEGRA30_CLK_EXTERN1, .present = true }, [tegra_clk_extern2] = { .dt_id = TEGRA30_CLK_EXTERN2, .present = true }, [tegra_clk_extern3] = { .dt_id = TEGRA30_CLK_EXTERN3, .present = true }, [tegra_clk_disp1] = { .dt_id = TEGRA30_CLK_DISP1, .present = true }, [tegra_clk_disp2] = { .dt_id = TEGRA30_CLK_DISP2, .present = true }, [tegra_clk_ahbdma] = { .dt_id = TEGRA30_CLK_AHBDMA, .present = true }, [tegra_clk_apbdma] = { .dt_id = TEGRA30_CLK_APBDMA, .present = true }, [tegra_clk_rtc] = { .dt_id = TEGRA30_CLK_RTC, .present = true }, [tegra_clk_timer] = { .dt_id = TEGRA30_CLK_TIMER, .present = true }, [tegra_clk_kbc] = { .dt_id = TEGRA30_CLK_KBC, .present = true }, [tegra_clk_csus] = { .dt_id = TEGRA30_CLK_CSUS, .present = true }, [tegra_clk_vcp] = { .dt_id = TEGRA30_CLK_VCP, .present = true }, [tegra_clk_bsea] = { .dt_id = TEGRA30_CLK_BSEA, .present = true }, [tegra_clk_bsev] = { .dt_id = TEGRA30_CLK_BSEV, .present = true }, [tegra_clk_usbd] = { .dt_id = TEGRA30_CLK_USBD, .present = true }, [tegra_clk_usb2] = { .dt_id = TEGRA30_CLK_USB2, .present = true }, [tegra_clk_usb3] = { .dt_id = TEGRA30_CLK_USB3, .present = true }, [tegra_clk_csi] = { .dt_id = TEGRA30_CLK_CSI, .present = true }, [tegra_clk_isp] = { .dt_id = TEGRA30_CLK_ISP, .present = true }, [tegra_clk_kfuse] = { .dt_id = TEGRA30_CLK_KFUSE, .present = true }, [tegra_clk_fuse] = { .dt_id = TEGRA30_CLK_FUSE, .present = true }, [tegra_clk_fuse_burn] = { .dt_id = TEGRA30_CLK_FUSE_BURN, .present = true }, [tegra_clk_apbif] = { .dt_id = TEGRA30_CLK_APBIF, .present = true }, [tegra_clk_hda2hdmi] = { .dt_id = TEGRA30_CLK_HDA2HDMI, .present = true }, [tegra_clk_sata_cold] = { .dt_id = TEGRA30_CLK_SATA_COLD, .present = true }, [tegra_clk_sata_oob] = { .dt_id = TEGRA30_CLK_SATA_OOB, .present = true }, [tegra_clk_sata] = { .dt_id = TEGRA30_CLK_SATA, .present = true }, [tegra_clk_dtv] = { .dt_id = TEGRA30_CLK_DTV, .present = true }, [tegra_clk_pll_p] = { .dt_id = TEGRA30_CLK_PLL_P, .present = true }, [tegra_clk_pll_p_out1] = { .dt_id = TEGRA30_CLK_PLL_P_OUT1, .present = true }, [tegra_clk_pll_p_out2] = { .dt_id = TEGRA30_CLK_PLL_P_OUT2, .present = true }, [tegra_clk_pll_p_out3] = { .dt_id = TEGRA30_CLK_PLL_P_OUT3, .present = true }, [tegra_clk_pll_p_out4] = { .dt_id = TEGRA30_CLK_PLL_P_OUT4, .present = true }, [tegra_clk_pll_a] = { .dt_id = TEGRA30_CLK_PLL_A, .present = true }, [tegra_clk_pll_a_out0] = { .dt_id = TEGRA30_CLK_PLL_A_OUT0, .present = true }, [tegra_clk_cec] = { .dt_id = TEGRA30_CLK_CEC, .present = true }, [tegra_clk_emc] = { .dt_id = TEGRA30_CLK_EMC, .present = false }, }; static const char *pll_e_parents[] = { "pll_ref", "pll_p" }; static void __init tegra30_pll_init(void) { struct clk *clk; /* PLLC_OUT1 */ clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c", clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div", clk_base + PLLC_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clks[TEGRA30_CLK_PLL_C_OUT1] = clk; /* PLLM_OUT1 */ clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m", clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div", clk_base + PLLM_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clks[TEGRA30_CLK_PLL_M_OUT1] = clk; /* PLLX */ clk = tegra_clk_register_pll("pll_x", "pll_ref", clk_base, pmc_base, 0, &pll_x_params, NULL); clks[TEGRA30_CLK_PLL_X] = clk; /* PLLX_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_x_out0", "pll_x", CLK_SET_RATE_PARENT, 1, 2); clks[TEGRA30_CLK_PLL_X_OUT0] = clk; /* PLLU */ clk = tegra_clk_register_pllu("pll_u", "pll_ref", clk_base, 0, &pll_u_params, NULL); clks[TEGRA30_CLK_PLL_U] = clk; /* PLLD */ clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc_base, 0, &pll_d_params, &pll_d_lock); clks[TEGRA30_CLK_PLL_D] = clk; /* PLLD_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d", CLK_SET_RATE_PARENT, 1, 2); clks[TEGRA30_CLK_PLL_D_OUT0] = clk; /* PLLD2 */ clk = tegra_clk_register_pll("pll_d2", "pll_ref", clk_base, pmc_base, 0, &pll_d2_params, NULL); clks[TEGRA30_CLK_PLL_D2] = clk; /* PLLD2_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2", CLK_SET_RATE_PARENT, 1, 2); clks[TEGRA30_CLK_PLL_D2_OUT0] = clk; /* PLLE */ clk = clk_register_mux(NULL, "pll_e_mux", pll_e_parents, ARRAY_SIZE(pll_e_parents), CLK_SET_RATE_NO_REPARENT, clk_base + PLLE_AUX, 2, 1, 0, NULL); } static const char *cclk_g_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m", "pll_p_cclkg", "pll_p_out4_cclkg", "pll_p_out3_cclkg", "unused", "pll_x" }; static const char *cclk_lp_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m", "pll_p_cclklp", "pll_p_out4_cclklp", "pll_p_out3_cclklp", "unused", "pll_x", "pll_x_out0" }; static const char *sclk_parents[] = { "clk_m", "pll_c_out1", "pll_p_out4", "pll_p_out3", "pll_p_out2", "unused", "clk_32k", "pll_m_out1" }; static void __init tegra30_super_clk_init(void) { struct clk *clk; /* * Clock input to cclk_g divided from pll_p using * U71 divider of cclk_g. */ clk = tegra_clk_register_divider("pll_p_cclkg", "pll_p", clk_base + SUPER_CCLKG_DIVIDER, 0, TEGRA_DIVIDER_INT, 16, 8, 1, NULL); clk_register_clkdev(clk, "pll_p_cclkg", NULL); /* * Clock input to cclk_g divided from pll_p_out3 using * U71 divider of cclk_g. */ clk = tegra_clk_register_divider("pll_p_out3_cclkg", "pll_p_out3", clk_base + SUPER_CCLKG_DIVIDER, 0, TEGRA_DIVIDER_INT, 16, 8, 1, NULL); clk_register_clkdev(clk, "pll_p_out3_cclkg", NULL); /* * Clock input to cclk_g divided from pll_p_out4 using * U71 divider of cclk_g. */ clk = tegra_clk_register_divider("pll_p_out4_cclkg", "pll_p_out4", clk_base + SUPER_CCLKG_DIVIDER, 0, TEGRA_DIVIDER_INT, 16, 8, 1, NULL); clk_register_clkdev(clk, "pll_p_out4_cclkg", NULL); /* CCLKG */ clk = tegra_clk_register_super_cclk("cclk_g", cclk_g_parents, ARRAY_SIZE(cclk_g_parents), CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE, clk_base + CCLKG_BURST_POLICY, 0, NULL); clks[TEGRA30_CLK_CCLK_G] = clk; /* * Clock input to cclk_lp divided from pll_p using * U71 divider of cclk_lp. */ clk = tegra_clk_register_divider("pll_p_cclklp", "pll_p", clk_base + SUPER_CCLKLP_DIVIDER, 0, TEGRA_DIVIDER_INT, 16, 8, 1, NULL); clk_register_clkdev(clk, "pll_p_cclklp", NULL); /* * Clock input to cclk_lp divided from pll_p_out3 using * U71 divider of cclk_lp. */ clk = tegra_clk_register_divider("pll_p_out3_cclklp", "pll_p_out3", clk_base + SUPER_CCLKLP_DIVIDER, 0, TEGRA_DIVIDER_INT, 16, 8, 1, NULL); clk_register_clkdev(clk, "pll_p_out3_cclklp", NULL); /* * Clock input to cclk_lp divided from pll_p_out4 using * U71 divider of cclk_lp. */ clk = tegra_clk_register_divider("pll_p_out4_cclklp", "pll_p_out4", clk_base + SUPER_CCLKLP_DIVIDER, 0, TEGRA_DIVIDER_INT, 16, 8, 1, NULL); clk_register_clkdev(clk, "pll_p_out4_cclklp", NULL); /* CCLKLP */ clk = tegra_clk_register_super_mux("cclk_lp", cclk_lp_parents, ARRAY_SIZE(cclk_lp_parents), CLK_SET_RATE_PARENT, clk_base + CCLKLP_BURST_POLICY, TEGRA_DIVIDER_2, 4, 8, 9, NULL); clks[TEGRA30_CLK_CCLK_LP] = clk; /* twd */ clk = clk_register_fixed_factor(NULL, "twd", "cclk_g", CLK_SET_RATE_PARENT, 1, 2); clks[TEGRA30_CLK_TWD] = clk; tegra_super_clk_gen4_init(clk_base, pmc_base, tegra30_clks, NULL); } static const char *mux_pllacp_clkm[] = { "pll_a_out0", "unused", "pll_p", "clk_m" }; static const char *mux_pllpcm_clkm[] = { "pll_p", "pll_c", "pll_m", "clk_m" }; static const char *spdif_out_parents[] = { "pll_a_out0", "spdif_2x", "pll_p", "clk_m" }; static const char *mux_pllmcpa[] = { "pll_m", "pll_c", "pll_p", "pll_a_out0" }; static const char *mux_pllpmdacd2_clkm[] = { "pll_p", "pll_m", "pll_d_out0", "pll_a_out0", "pll_c", "pll_d2_out0", "clk_m" }; static const char *mux_plld_out0_plld2_out0[] = { "pll_d_out0", "pll_d2_out0" }; static const char *pwm_parents[] = { "pll_p", "pll_c", "clk_32k", "clk_m" }; static struct tegra_periph_init_data tegra_periph_clk_list[] = { TEGRA_INIT_DATA_MUX("spdif_out", spdif_out_parents, CLK_SOURCE_SPDIF_OUT, 10, TEGRA_PERIPH_ON_APB, TEGRA30_CLK_SPDIF_OUT), TEGRA_INIT_DATA_MUX("d_audio", mux_pllacp_clkm, CLK_SOURCE_D_AUDIO, 106, 0, TEGRA30_CLK_D_AUDIO), TEGRA_INIT_DATA_MUX("dam0", mux_pllacp_clkm, CLK_SOURCE_DAM0, 108, 0, TEGRA30_CLK_DAM0), TEGRA_INIT_DATA_MUX("dam1", mux_pllacp_clkm, CLK_SOURCE_DAM1, 109, 0, TEGRA30_CLK_DAM1), TEGRA_INIT_DATA_MUX("dam2", mux_pllacp_clkm, CLK_SOURCE_DAM2, 110, 0, TEGRA30_CLK_DAM2), TEGRA_INIT_DATA_INT("3d2", mux_pllmcpa, CLK_SOURCE_3D2, 98, 0, TEGRA30_CLK_GR3D2), TEGRA_INIT_DATA_INT("se", mux_pllpcm_clkm, CLK_SOURCE_SE, 127, 0, TEGRA30_CLK_SE), TEGRA_INIT_DATA_MUX8("hdmi", mux_pllpmdacd2_clkm, CLK_SOURCE_HDMI, 51, 0, TEGRA30_CLK_HDMI), TEGRA_INIT_DATA("pwm", NULL, NULL, pwm_parents, CLK_SOURCE_PWM, 28, 2, 0, 0, 8, 1, 0, 17, TEGRA_PERIPH_ON_APB, TEGRA30_CLK_PWM), }; static struct tegra_periph_init_data tegra_periph_nodiv_clk_list[] = { TEGRA_INIT_DATA_NODIV("dsib", mux_plld_out0_plld2_out0, CLK_SOURCE_DSIB, 25, 1, 82, 0, TEGRA30_CLK_DSIB), }; static void __init tegra30_periph_clk_init(void) { struct tegra_periph_init_data *data; struct clk *clk; unsigned int i; /* dsia */ clk = tegra_clk_register_periph_gate("dsia", "pll_d_out0", 0, clk_base, 0, 48, periph_clk_enb_refcnt); clks[TEGRA30_CLK_DSIA] = clk; /* pcie */ clk = tegra_clk_register_periph_gate("pcie", "clk_m", 0, clk_base, 0, 70, periph_clk_enb_refcnt); clks[TEGRA30_CLK_PCIE] = clk; /* afi */ clk = tegra_clk_register_periph_gate("afi", "clk_m", 0, clk_base, 0, 72, periph_clk_enb_refcnt); clks[TEGRA30_CLK_AFI] = clk; /* emc */ clk = tegra20_clk_register_emc(clk_base + CLK_SOURCE_EMC, true); clks[TEGRA30_CLK_EMC] = clk; clk = tegra_clk_register_mc("mc", "emc", clk_base + CLK_SOURCE_EMC, NULL); clks[TEGRA30_CLK_MC] = clk; /* cml0 */ clk = clk_register_gate(NULL, "cml0", "pll_e", 0, clk_base + PLLE_AUX, 0, 0, &cml_lock); clks[TEGRA30_CLK_CML0] = clk; /* cml1 */ clk = clk_register_gate(NULL, "cml1", "pll_e", 0, clk_base + PLLE_AUX, 1, 0, &cml_lock); clks[TEGRA30_CLK_CML1] = clk; for (i = 0; i < ARRAY_SIZE(tegra_periph_clk_list); i++) { data = &tegra_periph_clk_list[i]; clk = tegra_clk_register_periph_data(clk_base, data); clks[data->clk_id] = clk; } for (i = 0; i < ARRAY_SIZE(tegra_periph_nodiv_clk_list); i++) { data = &tegra_periph_nodiv_clk_list[i]; clk = tegra_clk_register_periph_nodiv(data->name, data->p.parent_names, data->num_parents, &data->periph, clk_base, data->offset); clks[data->clk_id] = clk; } tegra_periph_clk_init(clk_base, pmc_base, tegra30_clks, &pll_p_params); } /* Tegra30 CPU clock and reset control functions */ static void tegra30_wait_cpu_in_reset(u32 cpu) { unsigned int reg; do { reg = readl(clk_base + TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS); cpu_relax(); } while (!(reg & (1 << cpu))); /* check CPU been reset or not */ return; } static void tegra30_put_cpu_in_reset(u32 cpu) { writel(CPU_RESET(cpu), clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); dmb(); } static void tegra30_cpu_out_of_reset(u32 cpu) { writel(CPU_RESET(cpu), clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR); wmb(); } static void tegra30_enable_cpu_clock(u32 cpu) { writel(CPU_CLOCK(cpu), clk_base + TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR); readl(clk_base + TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR); } static void tegra30_disable_cpu_clock(u32 cpu) { unsigned int reg; reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); writel(reg | CPU_CLOCK(cpu), clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); } #ifdef CONFIG_PM_SLEEP static bool tegra30_cpu_rail_off_ready(void) { unsigned int cpu_rst_status; int cpu_pwr_status; cpu_rst_status = readl(clk_base + TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS); cpu_pwr_status = tegra_pmc_cpu_is_powered(1) || tegra_pmc_cpu_is_powered(2) || tegra_pmc_cpu_is_powered(3); if (((cpu_rst_status & 0xE) != 0xE) || cpu_pwr_status) return false; return true; } static void tegra30_cpu_clock_suspend(void) { /* switch coresite to clk_m, save off original source */ tegra30_cpu_clk_sctx.clk_csite_src = readl(clk_base + CLK_RESET_SOURCE_CSITE); writel(3 << 30, clk_base + CLK_RESET_SOURCE_CSITE); tegra30_cpu_clk_sctx.cpu_burst = readl(clk_base + CLK_RESET_CCLK_BURST); tegra30_cpu_clk_sctx.pllx_base = readl(clk_base + CLK_RESET_PLLX_BASE); tegra30_cpu_clk_sctx.pllx_misc = readl(clk_base + CLK_RESET_PLLX_MISC); tegra30_cpu_clk_sctx.cclk_divider = readl(clk_base + CLK_RESET_CCLK_DIVIDER); } static void tegra30_cpu_clock_resume(void) { unsigned int reg, policy; u32 misc, base; /* Is CPU complex already running on PLLX? */ reg = readl(clk_base + CLK_RESET_CCLK_BURST); policy = (reg >> CLK_RESET_CCLK_BURST_POLICY_SHIFT) & 0xF; if (policy == CLK_RESET_CCLK_IDLE_POLICY) reg = (reg >> CLK_RESET_CCLK_IDLE_POLICY_SHIFT) & 0xF; else if (policy == CLK_RESET_CCLK_RUN_POLICY) reg = (reg >> CLK_RESET_CCLK_RUN_POLICY_SHIFT) & 0xF; else BUG(); if (reg != CLK_RESET_CCLK_BURST_POLICY_PLLX) { misc = readl_relaxed(clk_base + CLK_RESET_PLLX_MISC); base = readl_relaxed(clk_base + CLK_RESET_PLLX_BASE); if (misc != tegra30_cpu_clk_sctx.pllx_misc || base != tegra30_cpu_clk_sctx.pllx_base) { /* restore PLLX settings if CPU is on different PLL */ writel(tegra30_cpu_clk_sctx.pllx_misc, clk_base + CLK_RESET_PLLX_MISC); writel(tegra30_cpu_clk_sctx.pllx_base, clk_base + CLK_RESET_PLLX_BASE); /* wait for PLL stabilization if PLLX was enabled */ if (tegra30_cpu_clk_sctx.pllx_base & (1 << 30)) udelay(300); } } /* * Restore original burst policy setting for calls resulting from CPU * LP2 in idle or system suspend. */ writel(tegra30_cpu_clk_sctx.cclk_divider, clk_base + CLK_RESET_CCLK_DIVIDER); writel(tegra30_cpu_clk_sctx.cpu_burst, clk_base + CLK_RESET_CCLK_BURST); writel(tegra30_cpu_clk_sctx.clk_csite_src, clk_base + CLK_RESET_SOURCE_CSITE); } #endif static struct tegra_cpu_car_ops tegra30_cpu_car_ops = { .wait_for_reset = tegra30_wait_cpu_in_reset, .put_in_reset = tegra30_put_cpu_in_reset, .out_of_reset = tegra30_cpu_out_of_reset, .enable_clock = tegra30_enable_cpu_clock, .disable_clock = tegra30_disable_cpu_clock, #ifdef CONFIG_PM_SLEEP .rail_off_ready = tegra30_cpu_rail_off_ready, .suspend = tegra30_cpu_clock_suspend, .resume = tegra30_cpu_clock_resume, #endif }; static struct tegra_clk_init_table init_table[] = { { TEGRA30_CLK_UARTA, TEGRA30_CLK_PLL_P, 408000000, 0 }, { TEGRA30_CLK_UARTB, TEGRA30_CLK_PLL_P, 408000000, 0 }, { TEGRA30_CLK_UARTC, TEGRA30_CLK_PLL_P, 408000000, 0 }, { TEGRA30_CLK_UARTD, TEGRA30_CLK_PLL_P, 408000000, 0 }, { TEGRA30_CLK_UARTE, TEGRA30_CLK_PLL_P, 408000000, 0 }, { TEGRA30_CLK_PLL_A, TEGRA30_CLK_CLK_MAX, 564480000, 0 }, { TEGRA30_CLK_PLL_A_OUT0, TEGRA30_CLK_CLK_MAX, 11289600, 0 }, { TEGRA30_CLK_I2S0, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA30_CLK_I2S1, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA30_CLK_I2S2, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA30_CLK_I2S3, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA30_CLK_I2S4, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA30_CLK_SDMMC1, TEGRA30_CLK_PLL_P, 48000000, 0 }, { TEGRA30_CLK_SDMMC2, TEGRA30_CLK_PLL_P, 48000000, 0 }, { TEGRA30_CLK_SDMMC3, TEGRA30_CLK_PLL_P, 48000000, 0 }, { TEGRA30_CLK_CSITE, TEGRA30_CLK_CLK_MAX, 0, 1 }, { TEGRA30_CLK_MSELECT, TEGRA30_CLK_CLK_MAX, 0, 1 }, { TEGRA30_CLK_SBC1, TEGRA30_CLK_PLL_P, 100000000, 0 }, { TEGRA30_CLK_SBC2, TEGRA30_CLK_PLL_P, 100000000, 0 }, { TEGRA30_CLK_SBC3, TEGRA30_CLK_PLL_P, 100000000, 0 }, { TEGRA30_CLK_SBC4, TEGRA30_CLK_PLL_P, 100000000, 0 }, { TEGRA30_CLK_SBC5, TEGRA30_CLK_PLL_P, 100000000, 0 }, { TEGRA30_CLK_SBC6, TEGRA30_CLK_PLL_P, 100000000, 0 }, { TEGRA30_CLK_PLL_C, TEGRA30_CLK_CLK_MAX, 600000000, 0 }, { TEGRA30_CLK_HOST1X, TEGRA30_CLK_PLL_C, 150000000, 0 }, { TEGRA30_CLK_TWD, TEGRA30_CLK_CLK_MAX, 0, 1 }, { TEGRA30_CLK_GR2D, TEGRA30_CLK_PLL_C, 300000000, 0 }, { TEGRA30_CLK_GR3D, TEGRA30_CLK_PLL_C, 300000000, 0 }, { TEGRA30_CLK_GR3D2, TEGRA30_CLK_PLL_C, 300000000, 0 }, { TEGRA30_CLK_PLL_U, TEGRA30_CLK_CLK_MAX, 480000000, 0 }, { TEGRA30_CLK_VDE, TEGRA30_CLK_PLL_C, 300000000, 0 }, { TEGRA30_CLK_SPDIF_IN_SYNC, TEGRA30_CLK_CLK_MAX, 24000000, 0 }, { TEGRA30_CLK_I2S0_SYNC, TEGRA30_CLK_CLK_MAX, 24000000, 0 }, { TEGRA30_CLK_I2S1_SYNC, TEGRA30_CLK_CLK_MAX, 24000000, 0 }, { TEGRA30_CLK_I2S2_SYNC, TEGRA30_CLK_CLK_MAX, 24000000, 0 }, { TEGRA30_CLK_I2S3_SYNC, TEGRA30_CLK_CLK_MAX, 24000000, 0 }, { TEGRA30_CLK_I2S4_SYNC, TEGRA30_CLK_CLK_MAX, 24000000, 0 }, { TEGRA30_CLK_VIMCLK_SYNC, TEGRA30_CLK_CLK_MAX, 24000000, 0 }, { TEGRA30_CLK_HDA, TEGRA30_CLK_PLL_P, 102000000, 0 }, { TEGRA30_CLK_HDA2CODEC_2X, TEGRA30_CLK_PLL_P, 48000000, 0 }, { TEGRA30_CLK_PWM, TEGRA30_CLK_PLL_P, 48000000, 0 }, /* must be the last entry */ { TEGRA30_CLK_CLK_MAX, TEGRA30_CLK_CLK_MAX, 0, 0 }, }; /* * Some clocks may be used by different drivers depending on the board * configuration. List those here to register them twice in the clock lookup * table under two names. */ static struct tegra_clk_duplicate tegra_clk_duplicates[] = { TEGRA_CLK_DUPLICATE(TEGRA30_CLK_USBD, "utmip-pad", NULL), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_USBD, "tegra-ehci.0", NULL), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_USBD, "tegra-otg", NULL), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_BSEV, "tegra-avp", "bsev"), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_BSEV, "nvavp", "bsev"), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_VDE, "tegra-aes", "vde"), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_BSEA, "tegra-aes", "bsea"), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_BSEA, "nvavp", "bsea"), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_CML1, "tegra_sata_cml", NULL), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_CML0, "tegra_pcie", "cml"), TEGRA_CLK_DUPLICATE(TEGRA30_CLK_VCP, "nvavp", "vcp"), /* must be the last entry */ TEGRA_CLK_DUPLICATE(TEGRA30_CLK_CLK_MAX, NULL, NULL), }; static const struct of_device_id pmc_match[] __initconst = { { .compatible = "nvidia,tegra30-pmc" }, { }, }; static struct tegra_audio_clk_info tegra30_audio_plls[] = { { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_p_out1" }, }; static bool tegra30_car_initialized; static struct clk *tegra30_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) { struct clk_hw *hw; struct clk *clk; /* * Timer clocks are needed early, the rest of the clocks shouldn't be * available to device drivers until clock tree is fully initialized. */ if (clkspec->args[0] != TEGRA30_CLK_RTC && clkspec->args[0] != TEGRA30_CLK_TWD && clkspec->args[0] != TEGRA30_CLK_TIMER && !tegra30_car_initialized) return ERR_PTR(-EPROBE_DEFER); clk = of_clk_src_onecell_get(clkspec, data); if (IS_ERR(clk)) return clk; hw = __clk_get_hw(clk); if (clkspec->args[0] == TEGRA30_CLK_EMC) { if (!tegra20_clk_emc_driver_available(hw)) return ERR_PTR(-EPROBE_DEFER); } return clk; } static void __init tegra30_clock_init(struct device_node *np) { struct device_node *node; clk_base = of_iomap(np, 0); if (!clk_base) { pr_err("ioremap tegra30 CAR failed\n"); return; } node = of_find_matching_node(NULL, pmc_match); if (!node) { pr_err("Failed to find pmc node\n"); BUG(); } pmc_base = of_iomap(node, 0); of_node_put(node); if (!pmc_base) { pr_err("Can't map pmc registers\n"); BUG(); } clks = tegra_clk_init(clk_base, TEGRA30_CLK_CLK_MAX, TEGRA30_CLK_PERIPH_BANKS); if (!clks) return; if (tegra_osc_clk_init(clk_base, tegra30_clks, tegra30_input_freq, ARRAY_SIZE(tegra30_input_freq), 1, &input_freq, NULL) < 0) return; tegra_fixed_clk_init(tegra30_clks); tegra30_pll_init(); tegra30_super_clk_init(); tegra30_periph_clk_init(); tegra_audio_clk_init(clk_base, pmc_base, tegra30_clks, tegra30_audio_plls, ARRAY_SIZE(tegra30_audio_plls), 24000000); tegra_init_dup_clks(tegra_clk_duplicates, clks, TEGRA30_CLK_CLK_MAX); tegra_add_of_provider(np, tegra30_clk_src_onecell_get); tegra_cpu_car_ops = &tegra30_cpu_car_ops; } CLK_OF_DECLARE_DRIVER(tegra30, "nvidia,tegra30-car", tegra30_clock_init); /* * Clocks that use runtime PM can't be created at the tegra30_clock_init * time because drivers' base isn't initialized yet, and thus platform * devices can't be created for the clocks. Hence we need to split the * registration of the clocks into two phases. The first phase registers * essential clocks which don't require RPM and are actually used during * early boot. The second phase registers clocks which use RPM and this * is done when device drivers' core API is ready. */ static int tegra30_car_probe(struct platform_device *pdev) { struct clk *clk; /* PLLC */ clk = tegra_clk_register_pll("pll_c", "pll_ref", clk_base, pmc_base, 0, &pll_c_params, NULL); clks[TEGRA30_CLK_PLL_C] = clk; /* PLLE */ clk = tegra_clk_register_plle("pll_e", "pll_e_mux", clk_base, pmc_base, CLK_GET_RATE_NOCACHE, &pll_e_params, NULL); clks[TEGRA30_CLK_PLL_E] = clk; /* PLLM */ clk = tegra_clk_register_pll("pll_m", "pll_ref", clk_base, pmc_base, CLK_SET_RATE_GATE, &pll_m_params, NULL); clks[TEGRA30_CLK_PLL_M] = clk; /* SCLK */ clk = tegra_clk_register_super_mux("sclk", sclk_parents, ARRAY_SIZE(sclk_parents), CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, clk_base + SCLK_BURST_POLICY, 0, 4, 0, 0, NULL); clks[TEGRA30_CLK_SCLK] = clk; tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); tegra_init_from_table(init_table, clks, TEGRA30_CLK_CLK_MAX); tegra30_car_initialized = true; return 0; } static const struct of_device_id tegra30_car_match[] = { { .compatible = "nvidia,tegra30-car" }, { } }; static struct platform_driver tegra30_car_driver = { .driver = { .name = "tegra30-car", .of_match_table = tegra30_car_match, .suppress_bind_attrs = true, }, .probe = tegra30_car_probe, }; /* * Clock driver must be registered before memory controller driver, * which doesn't support deferred probing for today and is registered * from arch init-level. */ static int tegra30_car_init(void) { return platform_driver_register(&tegra30_car_driver); } postcore_initcall(tegra30_car_init);
linux-master
drivers/clk/tegra/clk-tegra30.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/clk-provider.h> #include <linux/clkdev.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/clk/tegra.h> #include "clk.h" #include "clk-id.h" #define CLK_SOURCE_I2S0 0x1d8 #define CLK_SOURCE_I2S1 0x100 #define CLK_SOURCE_I2S2 0x104 #define CLK_SOURCE_NDFLASH 0x160 #define CLK_SOURCE_I2S3 0x3bc #define CLK_SOURCE_I2S4 0x3c0 #define CLK_SOURCE_SPDIF_OUT 0x108 #define CLK_SOURCE_SPDIF_IN 0x10c #define CLK_SOURCE_PWM 0x110 #define CLK_SOURCE_ADX 0x638 #define CLK_SOURCE_ADX1 0x670 #define CLK_SOURCE_AMX 0x63c #define CLK_SOURCE_AMX1 0x674 #define CLK_SOURCE_HDA 0x428 #define CLK_SOURCE_HDA2CODEC_2X 0x3e4 #define CLK_SOURCE_SBC1 0x134 #define CLK_SOURCE_SBC2 0x118 #define CLK_SOURCE_SBC3 0x11c #define CLK_SOURCE_SBC4 0x1b4 #define CLK_SOURCE_SBC5 0x3c8 #define CLK_SOURCE_SBC6 0x3cc #define CLK_SOURCE_SATA_OOB 0x420 #define CLK_SOURCE_SATA 0x424 #define CLK_SOURCE_NDSPEED 0x3f8 #define CLK_SOURCE_VFIR 0x168 #define CLK_SOURCE_SDMMC1 0x150 #define CLK_SOURCE_SDMMC2 0x154 #define CLK_SOURCE_SDMMC3 0x1bc #define CLK_SOURCE_SDMMC4 0x164 #define CLK_SOURCE_CVE 0x140 #define CLK_SOURCE_TVO 0x188 #define CLK_SOURCE_TVDAC 0x194 #define CLK_SOURCE_VDE 0x1c8 #define CLK_SOURCE_CSITE 0x1d4 #define CLK_SOURCE_LA 0x1f8 #define CLK_SOURCE_TRACE 0x634 #define CLK_SOURCE_OWR 0x1cc #define CLK_SOURCE_NOR 0x1d0 #define CLK_SOURCE_MIPI 0x174 #define CLK_SOURCE_I2C1 0x124 #define CLK_SOURCE_I2C2 0x198 #define CLK_SOURCE_I2C3 0x1b8 #define CLK_SOURCE_I2C4 0x3c4 #define CLK_SOURCE_I2C5 0x128 #define CLK_SOURCE_I2C6 0x65c #define CLK_SOURCE_UARTA 0x178 #define CLK_SOURCE_UARTB 0x17c #define CLK_SOURCE_UARTC 0x1a0 #define CLK_SOURCE_UARTD 0x1c0 #define CLK_SOURCE_UARTE 0x1c4 #define CLK_SOURCE_3D 0x158 #define CLK_SOURCE_2D 0x15c #define CLK_SOURCE_MPE 0x170 #define CLK_SOURCE_VI_SENSOR 0x1a8 #define CLK_SOURCE_VI 0x148 #define CLK_SOURCE_EPP 0x16c #define CLK_SOURCE_MSENC 0x1f0 #define CLK_SOURCE_TSEC 0x1f4 #define CLK_SOURCE_HOST1X 0x180 #define CLK_SOURCE_HDMI 0x18c #define CLK_SOURCE_DISP1 0x138 #define CLK_SOURCE_DISP2 0x13c #define CLK_SOURCE_CILAB 0x614 #define CLK_SOURCE_CILCD 0x618 #define CLK_SOURCE_CILE 0x61c #define CLK_SOURCE_DSIALP 0x620 #define CLK_SOURCE_DSIBLP 0x624 #define CLK_SOURCE_TSENSOR 0x3b8 #define CLK_SOURCE_D_AUDIO 0x3d0 #define CLK_SOURCE_DAM0 0x3d8 #define CLK_SOURCE_DAM1 0x3dc #define CLK_SOURCE_DAM2 0x3e0 #define CLK_SOURCE_ACTMON 0x3e8 #define CLK_SOURCE_EXTERN1 0x3ec #define CLK_SOURCE_EXTERN2 0x3f0 #define CLK_SOURCE_EXTERN3 0x3f4 #define CLK_SOURCE_I2CSLOW 0x3fc #define CLK_SOURCE_SE 0x42c #define CLK_SOURCE_MSELECT 0x3b4 #define CLK_SOURCE_DFLL_REF 0x62c #define CLK_SOURCE_DFLL_SOC 0x630 #define CLK_SOURCE_SOC_THERM 0x644 #define CLK_SOURCE_XUSB_HOST_SRC 0x600 #define CLK_SOURCE_XUSB_FALCON_SRC 0x604 #define CLK_SOURCE_XUSB_FS_SRC 0x608 #define CLK_SOURCE_XUSB_SS_SRC 0x610 #define CLK_SOURCE_XUSB_DEV_SRC 0x60c #define CLK_SOURCE_ISP 0x144 #define CLK_SOURCE_SOR0 0x414 #define CLK_SOURCE_DPAUX 0x418 #define CLK_SOURCE_ENTROPY 0x628 #define CLK_SOURCE_VI_SENSOR2 0x658 #define CLK_SOURCE_HDMI_AUDIO 0x668 #define CLK_SOURCE_VIC03 0x678 #define CLK_SOURCE_CLK72MHZ 0x66c #define CLK_SOURCE_DBGAPB 0x718 #define CLK_SOURCE_NVENC 0x6a0 #define CLK_SOURCE_NVDEC 0x698 #define CLK_SOURCE_NVJPG 0x69c #define CLK_SOURCE_APE 0x6c0 #define CLK_SOURCE_SDMMC_LEGACY 0x694 #define CLK_SOURCE_QSPI 0x6c4 #define CLK_SOURCE_VI_I2C 0x6c8 #define CLK_SOURCE_MIPIBIF 0x660 #define CLK_SOURCE_UARTAPE 0x710 #define CLK_SOURCE_TSECB 0x6d8 #define CLK_SOURCE_MAUD 0x6d4 #define CLK_SOURCE_USB2_HSIC_TRK 0x6cc #define CLK_SOURCE_DMIC1 0x64c #define CLK_SOURCE_DMIC2 0x650 #define CLK_SOURCE_DMIC3 0x6bc #define MASK(x) (BIT(x) - 1) #define MUX(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, \ _clk_num, _gate_flags, _clk_id, _parents##_idx, 0,\ NULL) #define MUX_FLAGS(_name, _parents, _offset,\ _clk_num, _gate_flags, _clk_id, flags)\ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP,\ _clk_num, _gate_flags, _clk_id, _parents##_idx, flags,\ NULL) #define MUX8(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP,\ _clk_num, _gate_flags, _clk_id, _parents##_idx, 0,\ NULL) #define MUX8_NOGATE_LOCK(_name, _parents, _offset, _clk_id, _lock) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset, \ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP,\ 0, TEGRA_PERIPH_NO_GATE, _clk_id,\ _parents##_idx, 0, _lock) #define MUX8_NOGATE(_name, _parents, _offset, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset, \ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP,\ 0, TEGRA_PERIPH_NO_GATE, _clk_id,\ _parents##_idx, 0, NULL) #define INT(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 8, 1, TEGRA_DIVIDER_INT| \ TEGRA_DIVIDER_ROUND_UP, _clk_num, _gate_flags,\ _clk_id, _parents##_idx, 0, NULL) #define INT_FLAGS(_name, _parents, _offset,\ _clk_num, _gate_flags, _clk_id, flags)\ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 8, 1, TEGRA_DIVIDER_INT| \ TEGRA_DIVIDER_ROUND_UP, _clk_num, _gate_flags,\ _clk_id, _parents##_idx, flags, NULL) #define INT8(_name, _parents, _offset,\ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_INT| \ TEGRA_DIVIDER_ROUND_UP, _clk_num, _gate_flags,\ _clk_id, _parents##_idx, 0, NULL) #define UART(_name, _parents, _offset,\ _clk_num, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 16, 1, TEGRA_DIVIDER_UART| \ TEGRA_DIVIDER_ROUND_UP, _clk_num, 0, _clk_id,\ _parents##_idx, 0, NULL) #define UART8(_name, _parents, _offset,\ _clk_num, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 29, MASK(3), 0, 0, 16, 1, TEGRA_DIVIDER_UART| \ TEGRA_DIVIDER_ROUND_UP, _clk_num, 0, _clk_id,\ _parents##_idx, 0, NULL) #define I2C(_name, _parents, _offset,\ _clk_num, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 16, 0, TEGRA_DIVIDER_ROUND_UP,\ _clk_num, TEGRA_PERIPH_ON_APB, _clk_id, \ _parents##_idx, 0, NULL) #define XUSB(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset, \ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_INT| \ TEGRA_DIVIDER_ROUND_UP, _clk_num, _gate_flags,\ _clk_id, _parents##_idx, 0, NULL) #define AUDIO(_name, _offset, _clk_num,\ _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, mux_d_audio_clk, \ _offset, 16, 0xE01F, 0, 0, 8, 1, \ TEGRA_DIVIDER_ROUND_UP, _clk_num, _gate_flags, \ _clk_id, mux_d_audio_clk_idx, 0, NULL) #define NODIV(_name, _parents, _offset, \ _mux_shift, _mux_mask, _clk_num, \ _gate_flags, _clk_id, _lock) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ _mux_shift, _mux_mask, 0, 0, 0, 0, 0,\ _clk_num, (_gate_flags) | TEGRA_PERIPH_NO_DIV,\ _clk_id, _parents##_idx, 0, _lock) #define GATE(_name, _parent_name, \ _clk_num, _gate_flags, _clk_id, _flags) \ { \ .name = _name, \ .clk_id = _clk_id, \ .p.parent_name = _parent_name, \ .periph = TEGRA_CLK_PERIPH(0, 0, 0, 0, 0, 0, 0, \ _clk_num, _gate_flags, NULL, NULL), \ .flags = _flags \ } #define DIV8(_name, _parent_name, _offset, _clk_id, _flags) \ { \ .name = _name, \ .clk_id = _clk_id, \ .p.parent_name = _parent_name, \ .periph = TEGRA_CLK_PERIPH(0, 0, 0, 0, 8, 1, \ TEGRA_DIVIDER_ROUND_UP, 0, 0, \ NULL, NULL), \ .offset = _offset, \ .flags = _flags, \ } #define PLLP_BASE 0xa0 #define PLLP_MISC 0xac #define PLLP_MISC1 0x680 #define PLLP_OUTA 0xa4 #define PLLP_OUTB 0xa8 #define PLLP_OUTC 0x67c #define PLL_BASE_LOCK BIT(27) #define PLL_MISC_LOCK_ENABLE 18 static DEFINE_SPINLOCK(PLLP_OUTA_lock); static DEFINE_SPINLOCK(PLLP_OUTB_lock); static DEFINE_SPINLOCK(PLLP_OUTC_lock); #define MUX_I2S_SPDIF(_id) \ static const char *mux_pllaout0_##_id##_2x_pllp_clkm[] = { "pll_a_out0", \ #_id, "pll_p",\ "clk_m"}; MUX_I2S_SPDIF(audio0) MUX_I2S_SPDIF(audio1) MUX_I2S_SPDIF(audio2) MUX_I2S_SPDIF(audio3) MUX_I2S_SPDIF(audio4) MUX_I2S_SPDIF(audio) #define mux_pllaout0_audio0_2x_pllp_clkm_idx NULL #define mux_pllaout0_audio1_2x_pllp_clkm_idx NULL #define mux_pllaout0_audio2_2x_pllp_clkm_idx NULL #define mux_pllaout0_audio3_2x_pllp_clkm_idx NULL #define mux_pllaout0_audio4_2x_pllp_clkm_idx NULL #define mux_pllaout0_audio_2x_pllp_clkm_idx NULL static const char *mux_pllp_pllc_pllm_clkm[] = { "pll_p", "pll_c", "pll_m", "clk_m" }; #define mux_pllp_pllc_pllm_clkm_idx NULL static const char *mux_pllp_pllc_pllm[] = { "pll_p", "pll_c", "pll_m" }; #define mux_pllp_pllc_pllm_idx NULL static const char *mux_pllp_pllc_clk32_clkm[] = { "pll_p", "pll_c", "clk_32k", "clk_m" }; #define mux_pllp_pllc_clk32_clkm_idx NULL static const char *mux_plla_pllc_pllp_clkm[] = { "pll_a_out0", "pll_c", "pll_p", "clk_m" }; #define mux_plla_pllc_pllp_clkm_idx mux_pllp_pllc_pllm_clkm_idx static const char *mux_pllp_pllc2_c_c3_pllm_clkm[] = { "pll_p", "pll_c2", "pll_c", "pll_c3", "pll_m", "clk_m" }; static u32 mux_pllp_pllc2_c_c3_pllm_clkm_idx[] = { [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 6, }; static const char *mux_pllp_clkm[] = { "pll_p", "clk_m" }; static u32 mux_pllp_clkm_idx[] = { [0] = 0, [1] = 3, }; static const char *mux_pllp_clkm_2[] = { "pll_p", "clk_m" }; static u32 mux_pllp_clkm_2_idx[] = { [0] = 2, [1] = 6, }; static const char *mux_pllc2_c_c3_pllp_plla1_clkm[] = { "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a1", "clk_m" }; static u32 mux_pllc2_c_c3_pllp_plla1_clkm_idx[] = { [0] = 1, [1] = 2, [2] = 3, [3] = 4, [4] = 6, [5] = 7, }; static const char * mux_pllc4_out1_pllc_pllc4_out2_pllp_clkm_plla_pllc4_out0[] = { "pll_c4_out1", "pll_c", "pll_c4_out2", "pll_p", "clk_m", "pll_a_out0", "pll_c4_out0" }; static u32 mux_pllc4_out1_pllc_pllc4_out2_pllp_clkm_plla_pllc4_out0_idx[] = { [0] = 0, [1] = 2, [2] = 3, [3] = 4, [4] = 5, [5] = 6, [6] = 7, }; static const char *mux_pllc_pllp_plla[] = { "pll_c", "pll_p", "pll_a_out0" }; static u32 mux_pllc_pllp_plla_idx[] = { [0] = 1, [1] = 2, [2] = 3, }; static const char *mux_clkm_pllc_pllp_plla[] = { "clk_m", "pll_c", "pll_p", "pll_a_out0" }; #define mux_clkm_pllc_pllp_plla_idx NULL static const char *mux_pllc_pllp_plla1_pllc2_c3_clkm[] = { "pll_c", "pll_p", "pll_a1", "pll_c2", "pll_c3", "clk_m" }; static u32 mux_pllc_pllp_plla1_pllc2_c3_clkm_idx[] = { [0] = 1, [1] = 2, [2] = 3, [3] = 4, [4] = 5, [5] = 6, }; static const char *mux_pllc2_c_c3_pllp_clkm_plla1_pllc4[] = { "pll_c2", "pll_c", "pll_c3", "pll_p", "clk_m", "pll_a1", "pll_c4_out0", }; static u32 mux_pllc2_c_c3_pllp_clkm_plla1_pllc4_idx[] = { [0] = 1, [1] = 2, [2] = 3, [3] = 4, [4] = 5, [5] = 6, [6] = 7, }; static const char *mux_pllc_pllp_plla1_pllc2_c3_clkm_pllc4[] = { "pll_c", "pll_p", "pll_a1", "pll_c2", "pll_c3", "clk_m", "pll_c4_out0", }; #define mux_pllc_pllp_plla1_pllc2_c3_clkm_pllc4_idx \ mux_pllc2_c_c3_pllp_clkm_plla1_pllc4_idx static const char * mux_plla_pllc4_out0_pllc_pllc4_out1_pllp_pllc4_out2_clkm[] = { "pll_a_out0", "pll_c4_out0", "pll_c", "pll_c4_out1", "pll_p", "pll_c4_out2", "clk_m" }; #define mux_plla_pllc4_out0_pllc_pllc4_out1_pllp_pllc4_out2_clkm_idx NULL static const char *mux_pllm_pllc2_c_c3_pllp_plla[] = { "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0" }; #define mux_pllm_pllc2_c_c3_pllp_plla_idx mux_pllp_pllc2_c_c3_pllm_clkm_idx static const char *mux_pllp_pllm_plld_plla_pllc_plld2_clkm[] = { "pll_p", "pll_m", "pll_d_out0", "pll_a_out0", "pll_c", "pll_d2_out0", "clk_m" }; #define mux_pllp_pllm_plld_plla_pllc_plld2_clkm_idx NULL static const char *mux_pllm_pllc_pllp_plla[] = { "pll_m", "pll_c", "pll_p", "pll_a_out0" }; #define mux_pllm_pllc_pllp_plla_idx mux_pllp_pllc_pllm_clkm_idx static const char *mux_pllp_pllc_clkm[] = { "pll_p", "pll_c", "clk_m" }; static u32 mux_pllp_pllc_clkm_idx[] = { [0] = 0, [1] = 1, [2] = 3, }; static const char *mux_pllp_pllc_clkm_1[] = { "pll_p", "pll_c", "clk_m" }; static u32 mux_pllp_pllc_clkm_1_idx[] = { [0] = 0, [1] = 2, [2] = 5, }; static const char *mux_pllp_pllc_plla_clkm[] = { "pll_p", "pll_c", "pll_a_out0", "clk_m" }; static u32 mux_pllp_pllc_plla_clkm_idx[] = { [0] = 0, [1] = 2, [2] = 4, [3] = 6, }; static const char *mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2[] = { "pll_p", "pll_c", "pll_c4_out0", "pll_c4_out1", "clk_m", "pll_c4_out2" }; static u32 mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2_idx[] = { [0] = 0, [1] = 2, [2] = 3, [3] = 5, [4] = 6, [5] = 7, }; static const char * mux_pllp_pllc_pllc_out1_pllc4_out2_pllc4_out1_clkm_pllc4_out0[] = { "pll_p", "pll_c_out1", "pll_c", "pll_c4_out2", "pll_c4_out1", "clk_m", "pll_c4_out0" }; static u32 mux_pllp_pllc_pllc_out1_pllc4_out2_pllc4_out1_clkm_pllc4_out0_idx[] = { [0] = 0, [1] = 1, [2] = 2, [3] = 4, [4] = 5, [5] = 6, [6] = 7, }; static const char *mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0[] = { "pll_p", "pll_c4_out2", "pll_c4_out1", "clk_m", "pll_c4_out0" }; static u32 mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0_idx[] = { [0] = 0, [1] = 3, [2] = 4, [3] = 6, [4] = 7, }; static const char *mux_pllp_pllc2_c_c3_clkm[] = { "pll_p", "pll_c2", "pll_c", "pll_c3", "clk_m" }; static u32 mux_pllp_pllc2_c_c3_clkm_idx[] = { [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 6, }; static const char *mux_pllp_clkm_clk32_plle[] = { "pll_p", "clk_m", "clk_32k", "pll_e" }; static u32 mux_pllp_clkm_clk32_plle_idx[] = { [0] = 0, [1] = 2, [2] = 4, [3] = 6, }; static const char *mux_pllp_pllp_out3_clkm_clk32k_plla[] = { "pll_p", "pll_p_out3", "clk_m", "clk_32k", "pll_a_out0" }; #define mux_pllp_pllp_out3_clkm_clk32k_plla_idx NULL static const char *mux_pllp_out3_clkm_pllp_pllc4[] = { "pll_p_out3", "clk_m", "pll_p", "pll_c4_out0", "pll_c4_out1", "pll_c4_out2" }; static u32 mux_pllp_out3_clkm_pllp_pllc4_idx[] = { [0] = 0, [1] = 3, [2] = 4, [3] = 5, [4] = 6, [5] = 7, }; static const char *mux_clkm_pllp_pllre[] = { "clk_m", "pll_p_out_xusb", "pll_re_out" }; static u32 mux_clkm_pllp_pllre_idx[] = { [0] = 0, [1] = 1, [2] = 5, }; static const char *mux_pllp_pllc_clkm_clk32[] = { "pll_p", "pll_c", "clk_m", "clk_32k" }; #define mux_pllp_pllc_clkm_clk32_idx NULL static const char *mux_plla_clk32_pllp_clkm_plle[] = { "pll_a_out0", "clk_32k", "pll_p", "clk_m", "pll_e_out0" }; #define mux_plla_clk32_pllp_clkm_plle_idx NULL static const char *mux_clkm_pllp_pllc_pllre[] = { "clk_m", "pll_p", "pll_c", "pll_re_out" }; static u32 mux_clkm_pllp_pllc_pllre_idx[] = { [0] = 0, [1] = 1, [2] = 3, [3] = 5, }; static const char *mux_clkm_48M_pllp_480M[] = { "clk_m", "pll_u_48M", "pll_p", "pll_u_480M" }; static u32 mux_clkm_48M_pllp_480M_idx[] = { [0] = 0, [1] = 2, [2] = 4, [3] = 6, }; static const char *mux_clkm_pllre_clk32_480M[] = { "clk_m", "pll_re_out", "clk_32k", "pll_u_480M" }; #define mux_clkm_pllre_clk32_480M_idx NULL static const char *mux_clkm_pllre_clk32_480M_pllc_ref[] = { "clk_m", "pll_re_out", "clk_32k", "pll_u_480M", "pll_c", "pll_ref" }; static u32 mux_clkm_pllre_clk32_480M_pllc_ref_idx[] = { [0] = 0, [1] = 1, [2] = 3, [3] = 3, [4] = 4, [5] = 7, }; static const char *mux_pllp_out3_pllp_pllc_clkm[] = { "pll_p_out3", "pll_p", "pll_c", "clk_m" }; static u32 mux_pllp_out3_pllp_pllc_clkm_idx[] = { [0] = 0, [1] = 1, [2] = 2, [3] = 6, }; static const char *mux_ss_div2_60M[] = { "xusb_ss_div2", "pll_u_60M" }; #define mux_ss_div2_60M_idx NULL static const char *mux_ss_div2_60M_ss[] = { "xusb_ss_div2", "pll_u_60M", "xusb_ss_src" }; #define mux_ss_div2_60M_ss_idx NULL static const char *mux_ss_clkm[] = { "xusb_ss_src", "clk_m" }; #define mux_ss_clkm_idx NULL static const char *mux_d_audio_clk[] = { "pll_a_out0", "pll_p", "clk_m", "spdif_in_sync", "i2s0_sync", "i2s1_sync", "i2s2_sync", "i2s3_sync", "i2s4_sync", "vimclk_sync", }; static u32 mux_d_audio_clk_idx[] = { [0] = 0, [1] = 0x8000, [2] = 0xc000, [3] = 0xE000, [4] = 0xE001, [5] = 0xE002, [6] = 0xE003, [7] = 0xE004, [8] = 0xE005, [9] = 0xE007, }; static const char *mux_pllp_plld_pllc_clkm[] = { "pll_p", "pll_d_out0", "pll_c", "clk_m" }; #define mux_pllp_plld_pllc_clkm_idx NULL static const char *mux_pllm_pllc_pllp_plla_clkm_pllc4[] = { "pll_m", "pll_c", "pll_p", "pll_a_out0", "clk_m", "pll_c4", }; static u32 mux_pllm_pllc_pllp_plla_clkm_pllc4_idx[] = { [0] = 0, [1] = 1, [2] = 3, [3] = 3, [4] = 6, [5] = 7, }; static const char *mux_pllp_clkm1[] = { "pll_p", "clk_m", }; #define mux_pllp_clkm1_idx NULL static const char *mux_pllp3_pllc_clkm[] = { "pll_p_out3", "pll_c", "pll_c2", "clk_m", }; #define mux_pllp3_pllc_clkm_idx NULL static const char *mux_pllm_pllc_pllp_plla_pllc2_c3_clkm[] = { "pll_m", "pll_c", "pll_p", "pll_a", "pll_c2", "pll_c3", "clk_m" }; #define mux_pllm_pllc_pllp_plla_pllc2_c3_clkm_idx NULL static const char *mux_pllm_pllc2_c_c3_pllp_plla_pllc4[] = { "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0", "pll_c4", }; static u32 mux_pllm_pllc2_c_c3_pllp_plla_pllc4_idx[] = { [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 6, [6] = 7, }; /* SOR1 mux'es */ static const char *mux_pllp_plld_plld2_clkm[] = { "pll_p", "pll_d_out0", "pll_d2_out0", "clk_m" }; static u32 mux_pllp_plld_plld2_clkm_idx[] = { [0] = 0, [1] = 2, [2] = 5, [3] = 6 }; static const char *mux_pllp_pllre_clkm[] = { "pll_p", "pll_re_out1", "clk_m" }; static u32 mux_pllp_pllre_clkm_idx[] = { [0] = 0, [1] = 2, [2] = 3, }; static const char * const mux_dmic1[] = { "pll_a_out0", "dmic1_sync_clk", "pll_p", "clk_m" }; #define mux_dmic1_idx NULL static const char * const mux_dmic2[] = { "pll_a_out0", "dmic2_sync_clk", "pll_p", "clk_m" }; #define mux_dmic2_idx NULL static const char * const mux_dmic3[] = { "pll_a_out0", "dmic3_sync_clk", "pll_p", "clk_m" }; #define mux_dmic3_idx NULL static struct tegra_periph_init_data periph_clks[] = { AUDIO("d_audio", CLK_SOURCE_D_AUDIO, 106, TEGRA_PERIPH_ON_APB, tegra_clk_d_audio), AUDIO("dam0", CLK_SOURCE_DAM0, 108, TEGRA_PERIPH_ON_APB, tegra_clk_dam0), AUDIO("dam1", CLK_SOURCE_DAM1, 109, TEGRA_PERIPH_ON_APB, tegra_clk_dam1), AUDIO("dam2", CLK_SOURCE_DAM2, 110, TEGRA_PERIPH_ON_APB, tegra_clk_dam2), I2C("i2c1", mux_pllp_clkm, CLK_SOURCE_I2C1, 12, tegra_clk_i2c1), I2C("i2c2", mux_pllp_clkm, CLK_SOURCE_I2C2, 54, tegra_clk_i2c2), I2C("i2c3", mux_pllp_clkm, CLK_SOURCE_I2C3, 67, tegra_clk_i2c3), I2C("i2c4", mux_pllp_clkm, CLK_SOURCE_I2C4, 103, tegra_clk_i2c4), I2C("i2c5", mux_pllp_clkm, CLK_SOURCE_I2C5, 47, tegra_clk_i2c5), I2C("i2c6", mux_pllp_clkm, CLK_SOURCE_I2C6, 166, tegra_clk_i2c6), INT("vde", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_VDE, 61, 0, tegra_clk_vde), INT("vi", mux_pllm_pllc_pllp_plla, CLK_SOURCE_VI, 20, 0, tegra_clk_vi), INT("epp", mux_pllm_pllc_pllp_plla, CLK_SOURCE_EPP, 19, 0, tegra_clk_epp), INT("host1x", mux_pllm_pllc_pllp_plla, CLK_SOURCE_HOST1X, 28, 0, tegra_clk_host1x), INT("mpe", mux_pllm_pllc_pllp_plla, CLK_SOURCE_MPE, 60, 0, tegra_clk_mpe), INT("2d", mux_pllm_pllc_pllp_plla, CLK_SOURCE_2D, 21, 0, tegra_clk_gr2d), INT("3d", mux_pllm_pllc_pllp_plla, CLK_SOURCE_3D, 24, 0, tegra_clk_gr3d), INT8("vde", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_VDE, 61, 0, tegra_clk_vde_8), INT8("vi", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI, 20, 0, tegra_clk_vi_8), INT8("vi", mux_pllm_pllc2_c_c3_pllp_plla_pllc4, CLK_SOURCE_VI, 20, 0, tegra_clk_vi_9), INT8("vi", mux_pllc2_c_c3_pllp_clkm_plla1_pllc4, CLK_SOURCE_VI, 20, 0, tegra_clk_vi_10), INT8("epp", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_EPP, 19, 0, tegra_clk_epp_8), INT8("msenc", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_MSENC, 91, TEGRA_PERIPH_WAR_1005168, tegra_clk_msenc), INT8("tsec", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_TSEC, 83, 0, tegra_clk_tsec), INT("tsec", mux_pllp_pllc_clkm, CLK_SOURCE_TSEC, 83, 0, tegra_clk_tsec_8), INT8("host1x", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_HOST1X, 28, 0, tegra_clk_host1x_8), INT8("host1x", mux_pllc4_out1_pllc_pllc4_out2_pllp_clkm_plla_pllc4_out0, CLK_SOURCE_HOST1X, 28, 0, tegra_clk_host1x_9), INT8("se", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SE, 127, TEGRA_PERIPH_ON_APB, tegra_clk_se), INT8("se", mux_pllp_pllc2_c_c3_clkm, CLK_SOURCE_SE, 127, TEGRA_PERIPH_ON_APB, tegra_clk_se_10), INT8("2d", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_2D, 21, 0, tegra_clk_gr2d_8), INT8("3d", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_3D, 24, 0, tegra_clk_gr3d_8), INT8("vic03", mux_pllm_pllc_pllp_plla_pllc2_c3_clkm, CLK_SOURCE_VIC03, 178, 0, tegra_clk_vic03), INT8("vic03", mux_pllc_pllp_plla1_pllc2_c3_clkm, CLK_SOURCE_VIC03, 178, 0, tegra_clk_vic03_8), INT_FLAGS("mselect", mux_pllp_clkm, CLK_SOURCE_MSELECT, 99, 0, tegra_clk_mselect, CLK_IGNORE_UNUSED), MUX("i2s0", mux_pllaout0_audio0_2x_pllp_clkm, CLK_SOURCE_I2S0, 30, TEGRA_PERIPH_ON_APB, tegra_clk_i2s0), MUX("i2s1", mux_pllaout0_audio1_2x_pllp_clkm, CLK_SOURCE_I2S1, 11, TEGRA_PERIPH_ON_APB, tegra_clk_i2s1), MUX("i2s2", mux_pllaout0_audio2_2x_pllp_clkm, CLK_SOURCE_I2S2, 18, TEGRA_PERIPH_ON_APB, tegra_clk_i2s2), MUX("i2s3", mux_pllaout0_audio3_2x_pllp_clkm, CLK_SOURCE_I2S3, 101, TEGRA_PERIPH_ON_APB, tegra_clk_i2s3), MUX("i2s4", mux_pllaout0_audio4_2x_pllp_clkm, CLK_SOURCE_I2S4, 102, TEGRA_PERIPH_ON_APB, tegra_clk_i2s4), MUX("spdif_out", mux_pllaout0_audio_2x_pllp_clkm, CLK_SOURCE_SPDIF_OUT, 10, TEGRA_PERIPH_ON_APB, tegra_clk_spdif_out), MUX("spdif_in", mux_pllp_pllc_pllm, CLK_SOURCE_SPDIF_IN, 10, TEGRA_PERIPH_ON_APB, tegra_clk_spdif_in), MUX8("spdif_in", mux_pllp_pllc_clkm_1, CLK_SOURCE_SPDIF_IN, 10, TEGRA_PERIPH_ON_APB, tegra_clk_spdif_in_8), MUX("pwm", mux_pllp_pllc_clk32_clkm, CLK_SOURCE_PWM, 17, TEGRA_PERIPH_ON_APB, tegra_clk_pwm), MUX("adx", mux_plla_pllc_pllp_clkm, CLK_SOURCE_ADX, 154, TEGRA_PERIPH_ON_APB, tegra_clk_adx), MUX("amx", mux_plla_pllc_pllp_clkm, CLK_SOURCE_AMX, 153, TEGRA_PERIPH_ON_APB, tegra_clk_amx), MUX("hda", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_HDA, 125, TEGRA_PERIPH_ON_APB, tegra_clk_hda), MUX("hda", mux_pllp_pllc_clkm, CLK_SOURCE_HDA, 125, TEGRA_PERIPH_ON_APB, tegra_clk_hda_8), MUX("hda2codec_2x", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_HDA2CODEC_2X, 111, TEGRA_PERIPH_ON_APB, tegra_clk_hda2codec_2x), MUX8("hda2codec_2x", mux_pllp_pllc_plla_clkm, CLK_SOURCE_HDA2CODEC_2X, 111, TEGRA_PERIPH_ON_APB, tegra_clk_hda2codec_2x_8), MUX("vfir", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_VFIR, 7, TEGRA_PERIPH_ON_APB, tegra_clk_vfir), MUX("sdmmc1", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SDMMC1, 14, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc1), MUX("sdmmc2", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SDMMC2, 9, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc2), MUX("sdmmc3", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SDMMC3, 69, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc3), MUX("sdmmc4", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SDMMC4, 15, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc4), MUX8("sdmmc1", mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0, CLK_SOURCE_SDMMC1, 14, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc1_9), MUX8("sdmmc3", mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0, CLK_SOURCE_SDMMC3, 69, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc3_9), MUX("la", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_LA, 76, TEGRA_PERIPH_ON_APB, tegra_clk_la), MUX("trace", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_TRACE, 77, TEGRA_PERIPH_ON_APB, tegra_clk_trace), MUX("owr", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_OWR, 71, TEGRA_PERIPH_ON_APB, tegra_clk_owr), MUX("owr", mux_pllp_pllc_clkm, CLK_SOURCE_OWR, 71, TEGRA_PERIPH_ON_APB, tegra_clk_owr_8), MUX("nor", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_NOR, 42, 0, tegra_clk_nor), MUX("mipi", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_MIPI, 50, TEGRA_PERIPH_ON_APB, tegra_clk_mipi), MUX("vi_sensor", mux_pllm_pllc_pllp_plla, CLK_SOURCE_VI_SENSOR, 20, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor), MUX("vi_sensor", mux_pllc_pllp_plla, CLK_SOURCE_VI_SENSOR, 20, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor_9), MUX("cilab", mux_pllp_pllc_clkm, CLK_SOURCE_CILAB, 144, 0, tegra_clk_cilab), MUX("cilcd", mux_pllp_pllc_clkm, CLK_SOURCE_CILCD, 145, 0, tegra_clk_cilcd), MUX("cile", mux_pllp_pllc_clkm, CLK_SOURCE_CILE, 146, 0, tegra_clk_cile), MUX("dsialp", mux_pllp_pllc_clkm, CLK_SOURCE_DSIALP, 147, 0, tegra_clk_dsialp), MUX("dsiblp", mux_pllp_pllc_clkm, CLK_SOURCE_DSIBLP, 148, 0, tegra_clk_dsiblp), MUX("tsensor", mux_pllp_pllc_clkm_clk32, CLK_SOURCE_TSENSOR, 100, TEGRA_PERIPH_ON_APB, tegra_clk_tsensor), MUX("actmon", mux_pllp_pllc_clk32_clkm, CLK_SOURCE_ACTMON, 119, 0, tegra_clk_actmon), MUX("dfll_ref", mux_pllp_clkm, CLK_SOURCE_DFLL_REF, 155, TEGRA_PERIPH_ON_APB, tegra_clk_dfll_ref), MUX("dfll_soc", mux_pllp_clkm, CLK_SOURCE_DFLL_SOC, 155, TEGRA_PERIPH_ON_APB, tegra_clk_dfll_soc), MUX("i2cslow", mux_pllp_pllc_clk32_clkm, CLK_SOURCE_I2CSLOW, 81, TEGRA_PERIPH_ON_APB, tegra_clk_i2cslow), MUX("sbc1", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC1, 41, TEGRA_PERIPH_ON_APB, tegra_clk_sbc1), MUX("sbc2", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC2, 44, TEGRA_PERIPH_ON_APB, tegra_clk_sbc2), MUX("sbc3", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC3, 46, TEGRA_PERIPH_ON_APB, tegra_clk_sbc3), MUX("sbc4", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC4, 68, TEGRA_PERIPH_ON_APB, tegra_clk_sbc4), MUX("sbc5", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC5, 104, TEGRA_PERIPH_ON_APB, tegra_clk_sbc5), MUX("sbc6", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SBC6, 105, TEGRA_PERIPH_ON_APB, tegra_clk_sbc6), MUX("cve", mux_pllp_plld_pllc_clkm, CLK_SOURCE_CVE, 49, 0, tegra_clk_cve), MUX("tvo", mux_pllp_plld_pllc_clkm, CLK_SOURCE_TVO, 49, 0, tegra_clk_tvo), MUX("tvdac", mux_pllp_plld_pllc_clkm, CLK_SOURCE_TVDAC, 53, 0, tegra_clk_tvdac), MUX("ndflash", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_NDFLASH, 13, TEGRA_PERIPH_ON_APB, tegra_clk_ndflash), MUX("ndspeed", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_NDSPEED, 80, TEGRA_PERIPH_ON_APB, tegra_clk_ndspeed), MUX("sata_oob", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SATA_OOB, 123, TEGRA_PERIPH_ON_APB, tegra_clk_sata_oob), MUX("sata_oob", mux_pllp_pllc_clkm, CLK_SOURCE_SATA_OOB, 123, TEGRA_PERIPH_ON_APB, tegra_clk_sata_oob_8), MUX("sata", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_SATA, 124, TEGRA_PERIPH_ON_APB, tegra_clk_sata), MUX("sata", mux_pllp_pllc_clkm, CLK_SOURCE_SATA, 124, TEGRA_PERIPH_ON_APB, tegra_clk_sata_8), MUX("adx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_ADX1, 180, TEGRA_PERIPH_ON_APB, tegra_clk_adx1), MUX("amx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_AMX1, 185, TEGRA_PERIPH_ON_APB, tegra_clk_amx1), MUX("vi_sensor2", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR2, 165, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor2), MUX("vi_sensor2", mux_pllc_pllp_plla, CLK_SOURCE_VI_SENSOR2, 165, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor2_8), MUX8("sdmmc1", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC1, 14, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc1_8), MUX8("sdmmc2", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC2, 9, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc2_8), MUX8("sdmmc3", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC3, 69, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc3_8), MUX8("sdmmc4", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC4, 15, TEGRA_PERIPH_ON_APB, tegra_clk_sdmmc4_8), MUX8("sbc1", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC1, 41, TEGRA_PERIPH_ON_APB, tegra_clk_sbc1_8), MUX8("sbc2", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC2, 44, TEGRA_PERIPH_ON_APB, tegra_clk_sbc2_8), MUX8("sbc3", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC3, 46, TEGRA_PERIPH_ON_APB, tegra_clk_sbc3_8), MUX8("sbc4", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC4, 68, TEGRA_PERIPH_ON_APB, tegra_clk_sbc4_8), MUX8("sbc5", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC5, 104, TEGRA_PERIPH_ON_APB, tegra_clk_sbc5_8), MUX8("sbc6", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC6, 105, TEGRA_PERIPH_ON_APB, tegra_clk_sbc6_8), MUX("sbc1", mux_pllp_pllc_clkm, CLK_SOURCE_SBC1, 41, TEGRA_PERIPH_ON_APB, tegra_clk_sbc1_9), MUX("sbc2", mux_pllp_pllc_clkm, CLK_SOURCE_SBC2, 44, TEGRA_PERIPH_ON_APB, tegra_clk_sbc2_9), MUX("sbc3", mux_pllp_pllc_clkm, CLK_SOURCE_SBC3, 46, TEGRA_PERIPH_ON_APB, tegra_clk_sbc3_9), MUX("sbc4", mux_pllp_pllc_clkm, CLK_SOURCE_SBC4, 68, TEGRA_PERIPH_ON_APB, tegra_clk_sbc4_9), MUX8("ndflash", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_NDFLASH, 13, TEGRA_PERIPH_ON_APB, tegra_clk_ndflash_8), MUX8("ndspeed", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_NDSPEED, 80, TEGRA_PERIPH_ON_APB, tegra_clk_ndspeed_8), MUX8("hdmi", mux_pllp_pllm_plld_plla_pllc_plld2_clkm, CLK_SOURCE_HDMI, 51, 0, tegra_clk_hdmi), MUX8("extern1", mux_plla_clk32_pllp_clkm_plle, CLK_SOURCE_EXTERN1, 120, TEGRA_PERIPH_NO_RESET, tegra_clk_extern1), MUX8("extern2", mux_plla_clk32_pllp_clkm_plle, CLK_SOURCE_EXTERN2, 121, TEGRA_PERIPH_NO_RESET, tegra_clk_extern2), MUX8("extern3", mux_plla_clk32_pllp_clkm_plle, CLK_SOURCE_EXTERN3, 122, TEGRA_PERIPH_NO_RESET, tegra_clk_extern3), MUX8("soc_therm", mux_pllm_pllc_pllp_plla, CLK_SOURCE_SOC_THERM, 78, TEGRA_PERIPH_ON_APB, tegra_clk_soc_therm), MUX8("soc_therm", mux_clkm_pllc_pllp_plla, CLK_SOURCE_SOC_THERM, 78, TEGRA_PERIPH_ON_APB, tegra_clk_soc_therm_8), MUX8("vi_sensor", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR, 164, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor_8), MUX8("isp", mux_pllm_pllc_pllp_plla_clkm_pllc4, CLK_SOURCE_ISP, 23, TEGRA_PERIPH_ON_APB, tegra_clk_isp_8), MUX8_NOGATE("isp", mux_pllc_pllp_plla1_pllc2_c3_clkm_pllc4, CLK_SOURCE_ISP, tegra_clk_isp_9), MUX8("entropy", mux_pllp_clkm1, CLK_SOURCE_ENTROPY, 149, 0, tegra_clk_entropy), MUX8("entropy", mux_pllp_clkm_clk32_plle, CLK_SOURCE_ENTROPY, 149, 0, tegra_clk_entropy_8), MUX8("hdmi_audio", mux_pllp3_pllc_clkm, CLK_SOURCE_HDMI_AUDIO, 176, TEGRA_PERIPH_NO_RESET, tegra_clk_hdmi_audio), MUX8("clk72mhz", mux_pllp3_pllc_clkm, CLK_SOURCE_CLK72MHZ, 177, TEGRA_PERIPH_NO_RESET, tegra_clk_clk72Mhz), MUX8("clk72mhz", mux_pllp_out3_pllp_pllc_clkm, CLK_SOURCE_CLK72MHZ, 177, TEGRA_PERIPH_NO_RESET, tegra_clk_clk72Mhz_8), MUX_FLAGS("csite", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_CSITE, 73, TEGRA_PERIPH_ON_APB, tegra_clk_csite, CLK_IGNORE_UNUSED), MUX_FLAGS("csite", mux_pllp_pllre_clkm, CLK_SOURCE_CSITE, 73, TEGRA_PERIPH_ON_APB, tegra_clk_csite_8, CLK_IGNORE_UNUSED), NODIV("disp1", mux_pllp_pllm_plld_plla_pllc_plld2_clkm, CLK_SOURCE_DISP1, 29, 7, 27, 0, tegra_clk_disp1, NULL), NODIV("disp1", mux_pllp_plld_plld2_clkm, CLK_SOURCE_DISP1, 29, 7, 27, 0, tegra_clk_disp1_8, NULL), NODIV("disp2", mux_pllp_pllm_plld_plla_pllc_plld2_clkm, CLK_SOURCE_DISP2, 29, 7, 26, 0, tegra_clk_disp2, NULL), NODIV("disp2", mux_pllp_plld_plld2_clkm, CLK_SOURCE_DISP2, 29, 7, 26, 0, tegra_clk_disp2_8, NULL), UART("uarta", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTA, 6, tegra_clk_uarta), UART("uartb", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTB, 7, tegra_clk_uartb), UART("uartc", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTC, 55, tegra_clk_uartc), UART("uartd", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTD, 65, tegra_clk_uartd), UART("uarte", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTE, 66, tegra_clk_uarte), UART8("uarta", mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2, CLK_SOURCE_UARTA, 6, tegra_clk_uarta_8), UART8("uartb", mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2, CLK_SOURCE_UARTB, 7, tegra_clk_uartb_8), UART8("uartc", mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2, CLK_SOURCE_UARTC, 55, tegra_clk_uartc_8), UART8("uartd", mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2, CLK_SOURCE_UARTD, 65, tegra_clk_uartd_8), XUSB("xusb_host_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_HOST_SRC, 143, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_host_src), XUSB("xusb_host_src", mux_clkm_pllp_pllre, CLK_SOURCE_XUSB_HOST_SRC, 143, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_host_src_8), XUSB("xusb_falcon_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_FALCON_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_falcon_src), XUSB("xusb_falcon_src", mux_clkm_pllp_pllre, CLK_SOURCE_XUSB_FALCON_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_falcon_src_8), XUSB("xusb_fs_src", mux_clkm_48M_pllp_480M, CLK_SOURCE_XUSB_FS_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_fs_src), XUSB("xusb_ss_src", mux_clkm_pllre_clk32_480M_pllc_ref, CLK_SOURCE_XUSB_SS_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_ss_src), XUSB("xusb_ss_src", mux_clkm_pllre_clk32_480M, CLK_SOURCE_XUSB_SS_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_ss_src_8), NODIV("xusb_hs_src", mux_ss_div2_60M, CLK_SOURCE_XUSB_SS_SRC, 25, MASK(1), 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_hs_src, NULL), NODIV("xusb_hs_src", mux_ss_div2_60M_ss, CLK_SOURCE_XUSB_SS_SRC, 25, MASK(2), 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_hs_src_4, NULL), NODIV("xusb_ssp_src", mux_ss_clkm, CLK_SOURCE_XUSB_SS_SRC, 24, MASK(1), 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_ssp_src, NULL), XUSB("xusb_dev_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_DEV_SRC, 95, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_dev_src), XUSB("xusb_dev_src", mux_clkm_pllp_pllre, CLK_SOURCE_XUSB_DEV_SRC, 95, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_dev_src_8), MUX8("dbgapb", mux_pllp_clkm_2, CLK_SOURCE_DBGAPB, 185, TEGRA_PERIPH_NO_RESET, tegra_clk_dbgapb), MUX8("nvenc", mux_pllc2_c_c3_pllp_plla1_clkm, CLK_SOURCE_NVENC, 219, 0, tegra_clk_nvenc), MUX8("nvdec", mux_pllc2_c_c3_pllp_plla1_clkm, CLK_SOURCE_NVDEC, 194, 0, tegra_clk_nvdec), MUX8("nvjpg", mux_pllc2_c_c3_pllp_plla1_clkm, CLK_SOURCE_NVJPG, 195, 0, tegra_clk_nvjpg), MUX8("ape", mux_plla_pllc4_out0_pllc_pllc4_out1_pllp_pllc4_out2_clkm, CLK_SOURCE_APE, 198, TEGRA_PERIPH_ON_APB, tegra_clk_ape), MUX8("sdmmc_legacy", mux_pllp_out3_clkm_pllp_pllc4, CLK_SOURCE_SDMMC_LEGACY, 193, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_sdmmc_legacy), MUX8("qspi", mux_pllp_pllc_pllc_out1_pllc4_out2_pllc4_out1_clkm_pllc4_out0, CLK_SOURCE_QSPI, 211, TEGRA_PERIPH_ON_APB, tegra_clk_qspi), I2C("vii2c", mux_pllp_pllc_clkm, CLK_SOURCE_VI_I2C, 208, tegra_clk_vi_i2c), MUX("mipibif", mux_pllp_clkm, CLK_SOURCE_MIPIBIF, 173, TEGRA_PERIPH_ON_APB, tegra_clk_mipibif), MUX("uartape", mux_pllp_pllc_clkm, CLK_SOURCE_UARTAPE, 212, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_uartape), MUX8("tsecb", mux_pllp_pllc2_c_c3_clkm, CLK_SOURCE_TSECB, 206, 0, tegra_clk_tsecb), MUX8("maud", mux_pllp_pllp_out3_clkm_clk32k_plla, CLK_SOURCE_MAUD, 202, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_maud), MUX8("dmic1", mux_dmic1, CLK_SOURCE_DMIC1, 161, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_dmic1), MUX8("dmic2", mux_dmic2, CLK_SOURCE_DMIC2, 162, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_dmic2), MUX8("dmic3", mux_dmic3, CLK_SOURCE_DMIC3, 197, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_dmic3), }; static struct tegra_periph_init_data gate_clks[] = { GATE("rtc", "clk_32k", 4, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_rtc, 0), GATE("timer", "clk_m", 5, 0, tegra_clk_timer, CLK_IS_CRITICAL), GATE("isp", "clk_m", 23, 0, tegra_clk_isp, 0), GATE("vcp", "clk_m", 29, 0, tegra_clk_vcp, 0), GATE("ahbdma", "hclk", 33, 0, tegra_clk_ahbdma, 0), GATE("apbdma", "pclk", 34, 0, tegra_clk_apbdma, 0), GATE("kbc", "clk_32k", 36, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_kbc, 0), GATE("fuse", "clk_m", 39, TEGRA_PERIPH_ON_APB, tegra_clk_fuse, 0), GATE("fuse_burn", "clk_m", 39, TEGRA_PERIPH_ON_APB, tegra_clk_fuse_burn, 0), GATE("kfuse", "clk_m", 40, TEGRA_PERIPH_ON_APB, tegra_clk_kfuse, 0), GATE("apbif", "clk_m", 107, TEGRA_PERIPH_ON_APB, tegra_clk_apbif, 0), GATE("hda2hdmi", "clk_m", 128, TEGRA_PERIPH_ON_APB, tegra_clk_hda2hdmi, 0), GATE("bsea", "clk_m", 62, 0, tegra_clk_bsea, 0), GATE("bsev", "clk_m", 63, 0, tegra_clk_bsev, 0), GATE("mipi-cal", "clk72mhz", 56, 0, tegra_clk_mipi_cal, 0), GATE("usbd", "clk_m", 22, 0, tegra_clk_usbd, 0), GATE("usb2", "clk_m", 58, 0, tegra_clk_usb2, 0), GATE("usb3", "clk_m", 59, 0, tegra_clk_usb3, 0), GATE("csi", "pll_p_out3", 52, 0, tegra_clk_csi, 0), GATE("afi", "mselect", 72, 0, tegra_clk_afi, 0), GATE("csus", "clk_m", 92, TEGRA_PERIPH_NO_RESET, tegra_clk_csus, 0), GATE("dds", "clk_m", 150, TEGRA_PERIPH_ON_APB, tegra_clk_dds, 0), GATE("dp2", "clk_m", 152, TEGRA_PERIPH_ON_APB, tegra_clk_dp2, 0), GATE("dtv", "clk_m", 79, TEGRA_PERIPH_ON_APB, tegra_clk_dtv, 0), GATE("xusb_host", "xusb_host_src", 89, 0, tegra_clk_xusb_host, 0), GATE("xusb_ss", "xusb_ss_src", 156, 0, tegra_clk_xusb_ss, 0), GATE("xusb_dev", "xusb_dev_src", 95, 0, tegra_clk_xusb_dev, 0), GATE("emc", "emc_mux", 57, 0, tegra_clk_emc, CLK_IS_CRITICAL), GATE("sata_cold", "clk_m", 129, TEGRA_PERIPH_ON_APB, tegra_clk_sata_cold, 0), GATE("ispa", "isp", 23, 0, tegra_clk_ispa, 0), GATE("ispb", "isp", 3, 0, tegra_clk_ispb, 0), GATE("vim2_clk", "clk_m", 11, 0, tegra_clk_vim2_clk, 0), GATE("pcie", "clk_m", 70, 0, tegra_clk_pcie, 0), GATE("gpu", "pll_ref", 184, 0, tegra_clk_gpu, 0), GATE("pllg_ref", "pll_ref", 189, 0, tegra_clk_pll_g_ref, 0), GATE("hsic_trk", "usb2_hsic_trk", 209, TEGRA_PERIPH_NO_RESET, tegra_clk_hsic_trk, 0), GATE("usb2_trk", "usb2_hsic_trk", 210, TEGRA_PERIPH_NO_RESET, tegra_clk_usb2_trk, 0), GATE("xusb_gate", "osc", 143, 0, tegra_clk_xusb_gate, 0), GATE("pll_p_out_cpu", "pll_p", 223, 0, tegra_clk_pll_p_out_cpu, 0), GATE("pll_p_out_adsp", "pll_p", 187, 0, tegra_clk_pll_p_out_adsp, 0), GATE("apb2ape", "clk_m", 107, 0, tegra_clk_apb2ape, 0), GATE("cec", "pclk", 136, 0, tegra_clk_cec, 0), GATE("iqc1", "clk_m", 221, 0, tegra_clk_iqc1, 0), GATE("iqc2", "clk_m", 220, 0, tegra_clk_iqc1, 0), GATE("pll_a_out_adsp", "pll_a", 188, 0, tegra_clk_pll_a_out_adsp, 0), GATE("pll_a_out0_out_adsp", "pll_a", 188, 0, tegra_clk_pll_a_out0_out_adsp, 0), GATE("adsp", "aclk", 199, 0, tegra_clk_adsp, 0), GATE("adsp_neon", "aclk", 218, 0, tegra_clk_adsp_neon, 0), }; static struct tegra_periph_init_data div_clks[] = { DIV8("usb2_hsic_trk", "osc", CLK_SOURCE_USB2_HSIC_TRK, tegra_clk_usb2_hsic_trk, 0), }; struct pll_out_data { char *div_name; char *pll_out_name; u32 offset; int clk_id; u8 div_shift; u8 div_flags; u8 rst_shift; spinlock_t *lock; }; #define PLL_OUT(_num, _offset, _div_shift, _div_flags, _rst_shift, _id) \ {\ .div_name = "pll_p_out" #_num "_div",\ .pll_out_name = "pll_p_out" #_num,\ .offset = _offset,\ .div_shift = _div_shift,\ .div_flags = _div_flags | TEGRA_DIVIDER_FIXED |\ TEGRA_DIVIDER_ROUND_UP,\ .rst_shift = _rst_shift,\ .clk_id = tegra_clk_ ## _id,\ .lock = &_offset ##_lock,\ } static struct pll_out_data pllp_out_clks[] = { PLL_OUT(1, PLLP_OUTA, 8, 0, 0, pll_p_out1), PLL_OUT(2, PLLP_OUTA, 24, 0, 16, pll_p_out2), PLL_OUT(2, PLLP_OUTA, 24, TEGRA_DIVIDER_INT, 16, pll_p_out2_int), PLL_OUT(3, PLLP_OUTB, 8, 0, 0, pll_p_out3), PLL_OUT(4, PLLP_OUTB, 24, 0, 16, pll_p_out4), PLL_OUT(5, PLLP_OUTC, 24, 0, 16, pll_p_out5), }; static void __init periph_clk_init(void __iomem *clk_base, struct tegra_clk *tegra_clks) { int i; struct clk *clk; struct clk **dt_clk; for (i = 0; i < ARRAY_SIZE(periph_clks); i++) { const struct tegra_clk_periph_regs *bank; struct tegra_periph_init_data *data; data = periph_clks + i; dt_clk = tegra_lookup_dt_id(data->clk_id, tegra_clks); if (!dt_clk) continue; bank = get_reg_bank(data->periph.gate.clk_num); if (!bank) continue; data->periph.gate.regs = bank; clk = tegra_clk_register_periph_data(clk_base, data); *dt_clk = clk; } } static void __init gate_clk_init(void __iomem *clk_base, struct tegra_clk *tegra_clks) { int i; struct clk *clk; struct clk **dt_clk; for (i = 0; i < ARRAY_SIZE(gate_clks); i++) { struct tegra_periph_init_data *data; data = gate_clks + i; dt_clk = tegra_lookup_dt_id(data->clk_id, tegra_clks); if (!dt_clk) continue; clk = tegra_clk_register_periph_gate(data->name, data->p.parent_name, data->periph.gate.flags, clk_base, data->flags, data->periph.gate.clk_num, periph_clk_enb_refcnt); *dt_clk = clk; } } static void __init div_clk_init(void __iomem *clk_base, struct tegra_clk *tegra_clks) { int i; struct clk *clk; struct clk **dt_clk; for (i = 0; i < ARRAY_SIZE(div_clks); i++) { struct tegra_periph_init_data *data; data = div_clks + i; dt_clk = tegra_lookup_dt_id(data->clk_id, tegra_clks); if (!dt_clk) continue; clk = tegra_clk_register_divider(data->name, data->p.parent_name, clk_base + data->offset, data->flags, data->periph.divider.flags, data->periph.divider.shift, data->periph.divider.width, data->periph.divider.frac_width, data->periph.divider.lock); *dt_clk = clk; } } static void __init init_pllp(void __iomem *clk_base, void __iomem *pmc_base, struct tegra_clk *tegra_clks, struct tegra_clk_pll_params *pll_params) { struct clk *clk; struct clk **dt_clk; int i; dt_clk = tegra_lookup_dt_id(tegra_clk_pll_p, tegra_clks); if (dt_clk) { /* PLLP */ clk = tegra_clk_register_pll("pll_p", "pll_ref", clk_base, pmc_base, 0, pll_params, NULL); clk_register_clkdev(clk, "pll_p", NULL); *dt_clk = clk; } for (i = 0; i < ARRAY_SIZE(pllp_out_clks); i++) { struct pll_out_data *data; data = pllp_out_clks + i; dt_clk = tegra_lookup_dt_id(data->clk_id, tegra_clks); if (!dt_clk) continue; clk = tegra_clk_register_divider(data->div_name, "pll_p", clk_base + data->offset, 0, data->div_flags, data->div_shift, 8, 1, data->lock); clk = tegra_clk_register_pll_out(data->pll_out_name, data->div_name, clk_base + data->offset, data->rst_shift + 1, data->rst_shift, CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0, data->lock); *dt_clk = clk; } dt_clk = tegra_lookup_dt_id(tegra_clk_pll_p_out_cpu, tegra_clks); if (dt_clk) { /* * Tegra210 has control on enabling/disabling PLLP branches to * CPU, register a gate clock "pll_p_out_cpu" for this gating * function and parent "pll_p_out4" to it, so when we are * re-parenting CPU off from "pll_p_out4" the PLLP branching to * CPU can be disabled automatically. */ clk = tegra_clk_register_divider("pll_p_out4_div", "pll_p_out_cpu", clk_base + PLLP_OUTB, 0, 0, 24, 8, 1, &PLLP_OUTB_lock); dt_clk = tegra_lookup_dt_id(tegra_clk_pll_p_out4_cpu, tegra_clks); if (dt_clk) { clk = tegra_clk_register_pll_out("pll_p_out4", "pll_p_out4_div", clk_base + PLLP_OUTB, 17, 16, CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0, &PLLP_OUTB_lock); *dt_clk = clk; } } dt_clk = tegra_lookup_dt_id(tegra_clk_pll_p_out_hsio, tegra_clks); if (dt_clk) { /* PLLP_OUT_HSIO */ clk = clk_register_gate(NULL, "pll_p_out_hsio", "pll_p", CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, clk_base + PLLP_MISC1, 29, 0, NULL); *dt_clk = clk; } dt_clk = tegra_lookup_dt_id(tegra_clk_pll_p_out_xusb, tegra_clks); if (dt_clk) { /* PLLP_OUT_XUSB */ clk = clk_register_gate(NULL, "pll_p_out_xusb", "pll_p_out_hsio", CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, clk_base + PLLP_MISC1, 28, 0, NULL); clk_register_clkdev(clk, "pll_p_out_xusb", NULL); *dt_clk = clk; } } void __init tegra_periph_clk_init(void __iomem *clk_base, void __iomem *pmc_base, struct tegra_clk *tegra_clks, struct tegra_clk_pll_params *pll_params) { init_pllp(clk_base, pmc_base, tegra_clks, pll_params); periph_clk_init(clk_base, tegra_clks); gate_clk_init(clk_base, tegra_clks); div_clk_init(clk_base, tegra_clks); }
linux-master
drivers/clk/tegra/clk-tegra-periph.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. */ #include <asm/div64.h> #include "clk.h" #define div_mask(w) ((1 << (w)) - 1) int div_frac_get(unsigned long rate, unsigned parent_rate, u8 width, u8 frac_width, u8 flags) { u64 divider_ux1 = parent_rate; int mul; if (!rate) return 0; mul = 1 << frac_width; if (!(flags & TEGRA_DIVIDER_INT)) divider_ux1 *= mul; if (flags & TEGRA_DIVIDER_ROUND_UP) divider_ux1 += rate - 1; do_div(divider_ux1, rate); if (flags & TEGRA_DIVIDER_INT) divider_ux1 *= mul; if (divider_ux1 < mul) return 0; divider_ux1 -= mul; if (divider_ux1 > div_mask(width)) return div_mask(width); return divider_ux1; }
linux-master
drivers/clk/tegra/clk-utils.c
// SPDX-License-Identifier: GPL-2.0-only /* * clk-dfll.c - Tegra DFLL clock source common code * * Copyright (C) 2012-2019 NVIDIA Corporation. All rights reserved. * * Aleksandr Frid <[email protected]> * Paul Walmsley <[email protected]> * * This library is for the DVCO and DFLL IP blocks on the Tegra124 * SoC. These IP blocks together are also known at NVIDIA as * "CL-DVFS". To try to avoid confusion, this code refers to them * collectively as the "DFLL." * * The DFLL is a root clocksource which tolerates some amount of * supply voltage noise. Tegra124 uses it to clock the fast CPU * complex when the target CPU speed is above a particular rate. The * DFLL can be operated in either open-loop mode or closed-loop mode. * In open-loop mode, the DFLL generates an output clock appropriate * to the supply voltage. In closed-loop mode, when configured with a * target frequency, the DFLL minimizes supply voltage while * delivering an average frequency equal to the target. * * Devices clocked by the DFLL must be able to tolerate frequency * variation. In the case of the CPU, it's important to note that the * CPU cycle time will vary. This has implications for * performance-measurement code and any code that relies on the CPU * cycle time to delay for a certain length of time. */ #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/debugfs.h> #include <linux/device.h> #include <linux/err.h> #include <linux/i2c.h> #include <linux/io.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> #include <linux/pinctrl/consumer.h> #include <linux/pm_opp.h> #include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/reset.h> #include <linux/seq_file.h> #include "clk-dfll.h" #include "cvb.h" /* * DFLL control registers - access via dfll_{readl,writel} */ /* DFLL_CTRL: DFLL control register */ #define DFLL_CTRL 0x00 #define DFLL_CTRL_MODE_MASK 0x03 /* DFLL_CONFIG: DFLL sample rate control */ #define DFLL_CONFIG 0x04 #define DFLL_CONFIG_DIV_MASK 0xff #define DFLL_CONFIG_DIV_PRESCALE 32 /* DFLL_PARAMS: tuning coefficients for closed loop integrator */ #define DFLL_PARAMS 0x08 #define DFLL_PARAMS_CG_SCALE (0x1 << 24) #define DFLL_PARAMS_FORCE_MODE_SHIFT 22 #define DFLL_PARAMS_FORCE_MODE_MASK (0x3 << DFLL_PARAMS_FORCE_MODE_SHIFT) #define DFLL_PARAMS_CF_PARAM_SHIFT 16 #define DFLL_PARAMS_CF_PARAM_MASK (0x3f << DFLL_PARAMS_CF_PARAM_SHIFT) #define DFLL_PARAMS_CI_PARAM_SHIFT 8 #define DFLL_PARAMS_CI_PARAM_MASK (0x7 << DFLL_PARAMS_CI_PARAM_SHIFT) #define DFLL_PARAMS_CG_PARAM_SHIFT 0 #define DFLL_PARAMS_CG_PARAM_MASK (0xff << DFLL_PARAMS_CG_PARAM_SHIFT) /* DFLL_TUNE0: delay line configuration register 0 */ #define DFLL_TUNE0 0x0c /* DFLL_TUNE1: delay line configuration register 1 */ #define DFLL_TUNE1 0x10 /* DFLL_FREQ_REQ: target DFLL frequency control */ #define DFLL_FREQ_REQ 0x14 #define DFLL_FREQ_REQ_FORCE_ENABLE (0x1 << 28) #define DFLL_FREQ_REQ_FORCE_SHIFT 16 #define DFLL_FREQ_REQ_FORCE_MASK (0xfff << DFLL_FREQ_REQ_FORCE_SHIFT) #define FORCE_MAX 2047 #define FORCE_MIN -2048 #define DFLL_FREQ_REQ_SCALE_SHIFT 8 #define DFLL_FREQ_REQ_SCALE_MASK (0xff << DFLL_FREQ_REQ_SCALE_SHIFT) #define DFLL_FREQ_REQ_SCALE_MAX 256 #define DFLL_FREQ_REQ_FREQ_VALID (0x1 << 7) #define DFLL_FREQ_REQ_MULT_SHIFT 0 #define DFLL_FREQ_REG_MULT_MASK (0x7f << DFLL_FREQ_REQ_MULT_SHIFT) #define FREQ_MAX 127 /* DFLL_DROOP_CTRL: droop prevention control */ #define DFLL_DROOP_CTRL 0x1c /* DFLL_OUTPUT_CFG: closed loop mode control registers */ /* NOTE: access via dfll_i2c_{readl,writel} */ #define DFLL_OUTPUT_CFG 0x20 #define DFLL_OUTPUT_CFG_I2C_ENABLE (0x1 << 30) #define OUT_MASK 0x3f #define DFLL_OUTPUT_CFG_SAFE_SHIFT 24 #define DFLL_OUTPUT_CFG_SAFE_MASK \ (OUT_MASK << DFLL_OUTPUT_CFG_SAFE_SHIFT) #define DFLL_OUTPUT_CFG_MAX_SHIFT 16 #define DFLL_OUTPUT_CFG_MAX_MASK \ (OUT_MASK << DFLL_OUTPUT_CFG_MAX_SHIFT) #define DFLL_OUTPUT_CFG_MIN_SHIFT 8 #define DFLL_OUTPUT_CFG_MIN_MASK \ (OUT_MASK << DFLL_OUTPUT_CFG_MIN_SHIFT) #define DFLL_OUTPUT_CFG_PWM_DELTA (0x1 << 7) #define DFLL_OUTPUT_CFG_PWM_ENABLE (0x1 << 6) #define DFLL_OUTPUT_CFG_PWM_DIV_SHIFT 0 #define DFLL_OUTPUT_CFG_PWM_DIV_MASK \ (OUT_MASK << DFLL_OUTPUT_CFG_PWM_DIV_SHIFT) /* DFLL_OUTPUT_FORCE: closed loop mode voltage forcing control */ #define DFLL_OUTPUT_FORCE 0x24 #define DFLL_OUTPUT_FORCE_ENABLE (0x1 << 6) #define DFLL_OUTPUT_FORCE_VALUE_SHIFT 0 #define DFLL_OUTPUT_FORCE_VALUE_MASK \ (OUT_MASK << DFLL_OUTPUT_FORCE_VALUE_SHIFT) /* DFLL_MONITOR_CTRL: internal monitor data source control */ #define DFLL_MONITOR_CTRL 0x28 #define DFLL_MONITOR_CTRL_FREQ 6 /* DFLL_MONITOR_DATA: internal monitor data output */ #define DFLL_MONITOR_DATA 0x2c #define DFLL_MONITOR_DATA_NEW_MASK (0x1 << 16) #define DFLL_MONITOR_DATA_VAL_SHIFT 0 #define DFLL_MONITOR_DATA_VAL_MASK (0xFFFF << DFLL_MONITOR_DATA_VAL_SHIFT) /* * I2C output control registers - access via dfll_i2c_{readl,writel} */ /* DFLL_I2C_CFG: I2C controller configuration register */ #define DFLL_I2C_CFG 0x40 #define DFLL_I2C_CFG_ARB_ENABLE (0x1 << 20) #define DFLL_I2C_CFG_HS_CODE_SHIFT 16 #define DFLL_I2C_CFG_HS_CODE_MASK (0x7 << DFLL_I2C_CFG_HS_CODE_SHIFT) #define DFLL_I2C_CFG_PACKET_ENABLE (0x1 << 15) #define DFLL_I2C_CFG_SIZE_SHIFT 12 #define DFLL_I2C_CFG_SIZE_MASK (0x7 << DFLL_I2C_CFG_SIZE_SHIFT) #define DFLL_I2C_CFG_SLAVE_ADDR_10 (0x1 << 10) #define DFLL_I2C_CFG_SLAVE_ADDR_SHIFT_7BIT 1 #define DFLL_I2C_CFG_SLAVE_ADDR_SHIFT_10BIT 0 /* DFLL_I2C_VDD_REG_ADDR: PMIC I2C address for closed loop mode */ #define DFLL_I2C_VDD_REG_ADDR 0x44 /* DFLL_I2C_STS: I2C controller status */ #define DFLL_I2C_STS 0x48 #define DFLL_I2C_STS_I2C_LAST_SHIFT 1 #define DFLL_I2C_STS_I2C_REQ_PENDING 0x1 /* DFLL_INTR_STS: DFLL interrupt status register */ #define DFLL_INTR_STS 0x5c /* DFLL_INTR_EN: DFLL interrupt enable register */ #define DFLL_INTR_EN 0x60 #define DFLL_INTR_MIN_MASK 0x1 #define DFLL_INTR_MAX_MASK 0x2 /* * Integrated I2C controller registers - relative to td->i2c_controller_base */ /* DFLL_I2C_CLK_DIVISOR: I2C controller clock divisor */ #define DFLL_I2C_CLK_DIVISOR 0x6c #define DFLL_I2C_CLK_DIVISOR_MASK 0xffff #define DFLL_I2C_CLK_DIVISOR_FS_SHIFT 16 #define DFLL_I2C_CLK_DIVISOR_HS_SHIFT 0 #define DFLL_I2C_CLK_DIVISOR_PREDIV 8 #define DFLL_I2C_CLK_DIVISOR_HSMODE_PREDIV 12 /* * Other constants */ /* MAX_DFLL_VOLTAGES: number of LUT entries in the DFLL IP block */ #define MAX_DFLL_VOLTAGES 33 /* * REF_CLK_CYC_PER_DVCO_SAMPLE: the number of ref_clk cycles that the hardware * integrates the DVCO counter over - used for debug rate monitoring and * droop control */ #define REF_CLK_CYC_PER_DVCO_SAMPLE 4 /* * REF_CLOCK_RATE: the DFLL reference clock rate currently supported by this * driver, in Hz */ #define REF_CLOCK_RATE 51000000UL #define DVCO_RATE_TO_MULT(rate, ref_rate) ((rate) / ((ref_rate) / 2)) #define MULT_TO_DVCO_RATE(mult, ref_rate) ((mult) * ((ref_rate) / 2)) /** * enum dfll_ctrl_mode - DFLL hardware operating mode * @DFLL_UNINITIALIZED: (uninitialized state - not in hardware bitfield) * @DFLL_DISABLED: DFLL not generating an output clock * @DFLL_OPEN_LOOP: DVCO running, but DFLL not adjusting voltage * @DFLL_CLOSED_LOOP: DVCO running, and DFLL adjusting voltage to match * the requested rate * * The integer corresponding to the last two states, minus one, is * written to the DFLL hardware to change operating modes. */ enum dfll_ctrl_mode { DFLL_UNINITIALIZED = 0, DFLL_DISABLED = 1, DFLL_OPEN_LOOP = 2, DFLL_CLOSED_LOOP = 3, }; /** * enum dfll_tune_range - voltage range that the driver believes it's in * @DFLL_TUNE_UNINITIALIZED: DFLL tuning not yet programmed * @DFLL_TUNE_LOW: DFLL in the low-voltage range (or open-loop mode) * * Some DFLL tuning parameters may need to change depending on the * DVCO's voltage; these states represent the ranges that the driver * supports. These are software states; these values are never * written into registers. */ enum dfll_tune_range { DFLL_TUNE_UNINITIALIZED = 0, DFLL_TUNE_LOW = 1, }; enum tegra_dfll_pmu_if { TEGRA_DFLL_PMU_I2C = 0, TEGRA_DFLL_PMU_PWM = 1, }; /** * struct dfll_rate_req - target DFLL rate request data * @rate: target frequency, after the postscaling * @dvco_target_rate: target frequency, after the postscaling * @lut_index: LUT index at which voltage the dvco_target_rate will be reached * @mult_bits: value to program to the MULT bits of the DFLL_FREQ_REQ register * @scale_bits: value to program to the SCALE bits of the DFLL_FREQ_REQ register */ struct dfll_rate_req { unsigned long rate; unsigned long dvco_target_rate; int lut_index; u8 mult_bits; u8 scale_bits; }; struct tegra_dfll { struct device *dev; struct tegra_dfll_soc_data *soc; void __iomem *base; void __iomem *i2c_base; void __iomem *i2c_controller_base; void __iomem *lut_base; struct regulator *vdd_reg; struct clk *soc_clk; struct clk *ref_clk; struct clk *i2c_clk; struct clk *dfll_clk; struct reset_control *dfll_rst; struct reset_control *dvco_rst; unsigned long ref_rate; unsigned long i2c_clk_rate; unsigned long dvco_rate_min; enum dfll_ctrl_mode mode; enum dfll_tune_range tune_range; struct dentry *debugfs_dir; struct clk_hw dfll_clk_hw; const char *output_clock_name; struct dfll_rate_req last_req; unsigned long last_unrounded_rate; /* Parameters from DT */ u32 droop_ctrl; u32 sample_rate; u32 force_mode; u32 cf; u32 ci; u32 cg; bool cg_scale; /* I2C interface parameters */ u32 i2c_fs_rate; u32 i2c_reg; u32 i2c_slave_addr; /* lut array entries are regulator framework selectors or PWM values*/ unsigned lut[MAX_DFLL_VOLTAGES]; unsigned long lut_uv[MAX_DFLL_VOLTAGES]; int lut_size; u8 lut_bottom, lut_min, lut_max, lut_safe; /* PWM interface */ enum tegra_dfll_pmu_if pmu_if; unsigned long pwm_rate; struct pinctrl *pwm_pin; struct pinctrl_state *pwm_enable_state; struct pinctrl_state *pwm_disable_state; u32 reg_init_uV; }; #define clk_hw_to_dfll(_hw) container_of(_hw, struct tegra_dfll, dfll_clk_hw) /* mode_name: map numeric DFLL modes to names for friendly console messages */ static const char * const mode_name[] = { [DFLL_UNINITIALIZED] = "uninitialized", [DFLL_DISABLED] = "disabled", [DFLL_OPEN_LOOP] = "open_loop", [DFLL_CLOSED_LOOP] = "closed_loop", }; /* * Register accessors */ static inline u32 dfll_readl(struct tegra_dfll *td, u32 offs) { return __raw_readl(td->base + offs); } static inline void dfll_writel(struct tegra_dfll *td, u32 val, u32 offs) { WARN_ON(offs >= DFLL_I2C_CFG); __raw_writel(val, td->base + offs); } static inline void dfll_wmb(struct tegra_dfll *td) { dfll_readl(td, DFLL_CTRL); } /* I2C output control registers - for addresses above DFLL_I2C_CFG */ static inline u32 dfll_i2c_readl(struct tegra_dfll *td, u32 offs) { return __raw_readl(td->i2c_base + offs); } static inline void dfll_i2c_writel(struct tegra_dfll *td, u32 val, u32 offs) { __raw_writel(val, td->i2c_base + offs); } static inline void dfll_i2c_wmb(struct tegra_dfll *td) { dfll_i2c_readl(td, DFLL_I2C_CFG); } /** * dfll_is_running - is the DFLL currently generating a clock? * @td: DFLL instance * * If the DFLL is currently generating an output clock signal, return * true; otherwise return false. */ static bool dfll_is_running(struct tegra_dfll *td) { return td->mode >= DFLL_OPEN_LOOP; } /* * Runtime PM suspend/resume callbacks */ /** * tegra_dfll_runtime_resume - enable all clocks needed by the DFLL * @dev: DFLL device * * * Enable all clocks needed by the DFLL. Assumes that clk_prepare() * has already been called on all the clocks. * * XXX Should also handle context restore when returning from off. */ int tegra_dfll_runtime_resume(struct device *dev) { struct tegra_dfll *td = dev_get_drvdata(dev); int ret; ret = clk_enable(td->ref_clk); if (ret) { dev_err(dev, "could not enable ref clock: %d\n", ret); return ret; } ret = clk_enable(td->soc_clk); if (ret) { dev_err(dev, "could not enable register clock: %d\n", ret); clk_disable(td->ref_clk); return ret; } ret = clk_enable(td->i2c_clk); if (ret) { dev_err(dev, "could not enable i2c clock: %d\n", ret); clk_disable(td->soc_clk); clk_disable(td->ref_clk); return ret; } return 0; } EXPORT_SYMBOL(tegra_dfll_runtime_resume); /** * tegra_dfll_runtime_suspend - disable all clocks needed by the DFLL * @dev: DFLL device * * * Disable all clocks needed by the DFLL. Assumes that other code * will later call clk_unprepare(). */ int tegra_dfll_runtime_suspend(struct device *dev) { struct tegra_dfll *td = dev_get_drvdata(dev); clk_disable(td->ref_clk); clk_disable(td->soc_clk); clk_disable(td->i2c_clk); return 0; } EXPORT_SYMBOL(tegra_dfll_runtime_suspend); /* * DFLL tuning operations (per-voltage-range tuning settings) */ /** * dfll_tune_low - tune to DFLL and CPU settings valid for any voltage * @td: DFLL instance * * Tune the DFLL oscillator parameters and the CPU clock shaper for * the low-voltage range. These settings are valid for any voltage, * but may not be optimal. */ static void dfll_tune_low(struct tegra_dfll *td) { td->tune_range = DFLL_TUNE_LOW; dfll_writel(td, td->soc->cvb->cpu_dfll_data.tune0_low, DFLL_TUNE0); dfll_writel(td, td->soc->cvb->cpu_dfll_data.tune1, DFLL_TUNE1); dfll_wmb(td); if (td->soc->set_clock_trimmers_low) td->soc->set_clock_trimmers_low(); } /* * Output clock scaler helpers */ /** * dfll_scale_dvco_rate - calculate scaled rate from the DVCO rate * @scale_bits: clock scaler value (bits in the DFLL_FREQ_REQ_SCALE field) * @dvco_rate: the DVCO rate * * Apply the same scaling formula that the DFLL hardware uses to scale * the DVCO rate. */ static unsigned long dfll_scale_dvco_rate(int scale_bits, unsigned long dvco_rate) { return (u64)dvco_rate * (scale_bits + 1) / DFLL_FREQ_REQ_SCALE_MAX; } /* * DFLL mode switching */ /** * dfll_set_mode - change the DFLL control mode * @td: DFLL instance * @mode: DFLL control mode (see enum dfll_ctrl_mode) * * Change the DFLL's operating mode between disabled, open-loop mode, * and closed-loop mode, or vice versa. */ static void dfll_set_mode(struct tegra_dfll *td, enum dfll_ctrl_mode mode) { td->mode = mode; dfll_writel(td, mode - 1, DFLL_CTRL); dfll_wmb(td); } /* * DVCO rate control */ static unsigned long get_dvco_rate_below(struct tegra_dfll *td, u8 out_min) { struct dev_pm_opp *opp; unsigned long rate, prev_rate; unsigned long uv, min_uv; min_uv = td->lut_uv[out_min]; for (rate = 0, prev_rate = 0; ; rate++) { opp = dev_pm_opp_find_freq_ceil(td->soc->dev, &rate); if (IS_ERR(opp)) break; uv = dev_pm_opp_get_voltage(opp); dev_pm_opp_put(opp); if (uv && uv > min_uv) return prev_rate; prev_rate = rate; } return prev_rate; } /* * DFLL-to-I2C controller interface */ /** * dfll_i2c_set_output_enabled - enable/disable I2C PMIC voltage requests * @td: DFLL instance * @enable: whether to enable or disable the I2C voltage requests * * Set the master enable control for I2C control value updates. If disabled, * then I2C control messages are inhibited, regardless of the DFLL mode. */ static int dfll_i2c_set_output_enabled(struct tegra_dfll *td, bool enable) { u32 val; val = dfll_i2c_readl(td, DFLL_OUTPUT_CFG); if (enable) val |= DFLL_OUTPUT_CFG_I2C_ENABLE; else val &= ~DFLL_OUTPUT_CFG_I2C_ENABLE; dfll_i2c_writel(td, val, DFLL_OUTPUT_CFG); dfll_i2c_wmb(td); return 0; } /* * DFLL-to-PWM controller interface */ /** * dfll_pwm_set_output_enabled - enable/disable PWM voltage requests * @td: DFLL instance * @enable: whether to enable or disable the PWM voltage requests * * Set the master enable control for PWM control value updates. If disabled, * then the PWM signal is not driven. Also configure the PWM output pad * to the appropriate state. */ static int dfll_pwm_set_output_enabled(struct tegra_dfll *td, bool enable) { int ret; u32 val, div; if (enable) { ret = pinctrl_select_state(td->pwm_pin, td->pwm_enable_state); if (ret < 0) { dev_err(td->dev, "setting enable state failed\n"); return -EINVAL; } val = dfll_readl(td, DFLL_OUTPUT_CFG); val &= ~DFLL_OUTPUT_CFG_PWM_DIV_MASK; div = DIV_ROUND_UP(td->ref_rate, td->pwm_rate); val |= (div << DFLL_OUTPUT_CFG_PWM_DIV_SHIFT) & DFLL_OUTPUT_CFG_PWM_DIV_MASK; dfll_writel(td, val, DFLL_OUTPUT_CFG); dfll_wmb(td); val |= DFLL_OUTPUT_CFG_PWM_ENABLE; dfll_writel(td, val, DFLL_OUTPUT_CFG); dfll_wmb(td); } else { ret = pinctrl_select_state(td->pwm_pin, td->pwm_disable_state); if (ret < 0) dev_warn(td->dev, "setting disable state failed\n"); val = dfll_readl(td, DFLL_OUTPUT_CFG); val &= ~DFLL_OUTPUT_CFG_PWM_ENABLE; dfll_writel(td, val, DFLL_OUTPUT_CFG); dfll_wmb(td); } return 0; } /** * dfll_set_force_output_value - set fixed value for force output * @td: DFLL instance * @out_val: value to force output * * Set the fixed value for force output, DFLL will output this value when * force output is enabled. */ static u32 dfll_set_force_output_value(struct tegra_dfll *td, u8 out_val) { u32 val = dfll_readl(td, DFLL_OUTPUT_FORCE); val = (val & DFLL_OUTPUT_FORCE_ENABLE) | (out_val & OUT_MASK); dfll_writel(td, val, DFLL_OUTPUT_FORCE); dfll_wmb(td); return dfll_readl(td, DFLL_OUTPUT_FORCE); } /** * dfll_set_force_output_enabled - enable/disable force output * @td: DFLL instance * @enable: whether to enable or disable the force output * * Set the enable control for fouce output with fixed value. */ static void dfll_set_force_output_enabled(struct tegra_dfll *td, bool enable) { u32 val = dfll_readl(td, DFLL_OUTPUT_FORCE); if (enable) val |= DFLL_OUTPUT_FORCE_ENABLE; else val &= ~DFLL_OUTPUT_FORCE_ENABLE; dfll_writel(td, val, DFLL_OUTPUT_FORCE); dfll_wmb(td); } /** * dfll_force_output - force output a fixed value * @td: DFLL instance * @out_sel: value to force output * * Set the fixed value for force output, DFLL will output this value. */ static int dfll_force_output(struct tegra_dfll *td, unsigned int out_sel) { u32 val; if (out_sel > OUT_MASK) return -EINVAL; val = dfll_set_force_output_value(td, out_sel); if ((td->mode < DFLL_CLOSED_LOOP) && !(val & DFLL_OUTPUT_FORCE_ENABLE)) { dfll_set_force_output_enabled(td, true); } return 0; } /** * dfll_load_i2c_lut - load the voltage lookup table * @td: struct tegra_dfll * * * Load the voltage-to-PMIC register value lookup table into the DFLL * IP block memory. Look-up tables can be loaded at any time. */ static void dfll_load_i2c_lut(struct tegra_dfll *td) { int i, lut_index; u32 val; for (i = 0; i < MAX_DFLL_VOLTAGES; i++) { if (i < td->lut_min) lut_index = td->lut_min; else if (i > td->lut_max) lut_index = td->lut_max; else lut_index = i; val = regulator_list_hardware_vsel(td->vdd_reg, td->lut[lut_index]); __raw_writel(val, td->lut_base + i * 4); } dfll_i2c_wmb(td); } /** * dfll_init_i2c_if - set up the DFLL's DFLL-I2C interface * @td: DFLL instance * * During DFLL driver initialization, program the DFLL-I2C interface * with the PMU slave address, vdd register offset, and transfer mode. * This data is used by the DFLL to automatically construct I2C * voltage-set commands, which are then passed to the DFLL's internal * I2C controller. */ static void dfll_init_i2c_if(struct tegra_dfll *td) { u32 val; if (td->i2c_slave_addr > 0x7f) { val = td->i2c_slave_addr << DFLL_I2C_CFG_SLAVE_ADDR_SHIFT_10BIT; val |= DFLL_I2C_CFG_SLAVE_ADDR_10; } else { val = td->i2c_slave_addr << DFLL_I2C_CFG_SLAVE_ADDR_SHIFT_7BIT; } val |= DFLL_I2C_CFG_SIZE_MASK; val |= DFLL_I2C_CFG_ARB_ENABLE; dfll_i2c_writel(td, val, DFLL_I2C_CFG); dfll_i2c_writel(td, td->i2c_reg, DFLL_I2C_VDD_REG_ADDR); val = DIV_ROUND_UP(td->i2c_clk_rate, td->i2c_fs_rate * 8); BUG_ON(!val || (val > DFLL_I2C_CLK_DIVISOR_MASK)); val = (val - 1) << DFLL_I2C_CLK_DIVISOR_FS_SHIFT; /* default hs divisor just in case */ val |= 1 << DFLL_I2C_CLK_DIVISOR_HS_SHIFT; __raw_writel(val, td->i2c_controller_base + DFLL_I2C_CLK_DIVISOR); dfll_i2c_wmb(td); } /** * dfll_init_out_if - prepare DFLL-to-PMIC interface * @td: DFLL instance * * During DFLL driver initialization or resume from context loss, * disable the I2C command output to the PMIC, set safe voltage and * output limits, and disable and clear limit interrupts. */ static void dfll_init_out_if(struct tegra_dfll *td) { u32 val; td->lut_min = td->lut_bottom; td->lut_max = td->lut_size - 1; td->lut_safe = td->lut_min + (td->lut_min < td->lut_max ? 1 : 0); /* clear DFLL_OUTPUT_CFG before setting new value */ dfll_writel(td, 0, DFLL_OUTPUT_CFG); dfll_wmb(td); val = (td->lut_safe << DFLL_OUTPUT_CFG_SAFE_SHIFT) | (td->lut_max << DFLL_OUTPUT_CFG_MAX_SHIFT) | (td->lut_min << DFLL_OUTPUT_CFG_MIN_SHIFT); dfll_writel(td, val, DFLL_OUTPUT_CFG); dfll_wmb(td); dfll_writel(td, 0, DFLL_OUTPUT_FORCE); dfll_i2c_writel(td, 0, DFLL_INTR_EN); dfll_i2c_writel(td, DFLL_INTR_MAX_MASK | DFLL_INTR_MIN_MASK, DFLL_INTR_STS); if (td->pmu_if == TEGRA_DFLL_PMU_PWM) { u32 vinit = td->reg_init_uV; int vstep = td->soc->alignment.step_uv; unsigned long vmin = td->lut_uv[0]; /* set initial voltage */ if ((vinit >= vmin) && vstep) { unsigned int vsel; vsel = DIV_ROUND_UP((vinit - vmin), vstep); dfll_force_output(td, vsel); } } else { dfll_load_i2c_lut(td); dfll_init_i2c_if(td); } } /* * Set/get the DFLL's targeted output clock rate */ /** * find_lut_index_for_rate - determine I2C LUT index for given DFLL rate * @td: DFLL instance * @rate: clock rate * * Determines the index of a I2C LUT entry for a voltage that approximately * produces the given DFLL clock rate. This is used when forcing a value * to the integrator during rate changes. Returns -ENOENT if a suitable * LUT index is not found. */ static int find_lut_index_for_rate(struct tegra_dfll *td, unsigned long rate) { struct dev_pm_opp *opp; int i, align_step; opp = dev_pm_opp_find_freq_ceil(td->soc->dev, &rate); if (IS_ERR(opp)) return PTR_ERR(opp); align_step = dev_pm_opp_get_voltage(opp) / td->soc->alignment.step_uv; dev_pm_opp_put(opp); for (i = td->lut_bottom; i < td->lut_size; i++) { if ((td->lut_uv[i] / td->soc->alignment.step_uv) >= align_step) return i; } return -ENOENT; } /** * dfll_calculate_rate_request - calculate DFLL parameters for a given rate * @td: DFLL instance * @req: DFLL-rate-request structure * @rate: the desired DFLL rate * * Populate the DFLL-rate-request record @req fields with the scale_bits * and mult_bits fields, based on the target input rate. Returns 0 upon * success, or -EINVAL if the requested rate in req->rate is too high * or low for the DFLL to generate. */ static int dfll_calculate_rate_request(struct tegra_dfll *td, struct dfll_rate_req *req, unsigned long rate) { u32 val; /* * If requested rate is below the minimum DVCO rate, active the scaler. * In the future the DVCO minimum voltage should be selected based on * chip temperature and the actual minimum rate should be calibrated * at runtime. */ req->scale_bits = DFLL_FREQ_REQ_SCALE_MAX - 1; if (rate < td->dvco_rate_min) { int scale; scale = DIV_ROUND_CLOSEST(rate / 1000 * DFLL_FREQ_REQ_SCALE_MAX, td->dvco_rate_min / 1000); if (!scale) { dev_err(td->dev, "%s: Rate %lu is too low\n", __func__, rate); return -EINVAL; } req->scale_bits = scale - 1; rate = td->dvco_rate_min; } /* Convert requested rate into frequency request and scale settings */ val = DVCO_RATE_TO_MULT(rate, td->ref_rate); if (val > FREQ_MAX) { dev_err(td->dev, "%s: Rate %lu is above dfll range\n", __func__, rate); return -EINVAL; } req->mult_bits = val; req->dvco_target_rate = MULT_TO_DVCO_RATE(req->mult_bits, td->ref_rate); req->rate = dfll_scale_dvco_rate(req->scale_bits, req->dvco_target_rate); req->lut_index = find_lut_index_for_rate(td, req->dvco_target_rate); if (req->lut_index < 0) return req->lut_index; return 0; } /** * dfll_set_frequency_request - start the frequency change operation * @td: DFLL instance * @req: rate request structure * * Tell the DFLL to try to change its output frequency to the * frequency represented by @req. DFLL must be in closed-loop mode. */ static void dfll_set_frequency_request(struct tegra_dfll *td, struct dfll_rate_req *req) { u32 val = 0; int force_val; int coef = 128; /* FIXME: td->cg_scale? */; force_val = (req->lut_index - td->lut_safe) * coef / td->cg; force_val = clamp(force_val, FORCE_MIN, FORCE_MAX); val |= req->mult_bits << DFLL_FREQ_REQ_MULT_SHIFT; val |= req->scale_bits << DFLL_FREQ_REQ_SCALE_SHIFT; val |= ((u32)force_val << DFLL_FREQ_REQ_FORCE_SHIFT) & DFLL_FREQ_REQ_FORCE_MASK; val |= DFLL_FREQ_REQ_FREQ_VALID | DFLL_FREQ_REQ_FORCE_ENABLE; dfll_writel(td, val, DFLL_FREQ_REQ); dfll_wmb(td); } /** * dfll_request_rate - set the next rate for the DFLL to tune to * @td: DFLL instance * @rate: clock rate to target * * Convert the requested clock rate @rate into the DFLL control logic * settings. In closed-loop mode, update new settings immediately to * adjust DFLL output rate accordingly. Otherwise, just save them * until the next switch to closed loop. Returns 0 upon success, * -EPERM if the DFLL driver has not yet been initialized, or -EINVAL * if @rate is outside the DFLL's tunable range. */ static int dfll_request_rate(struct tegra_dfll *td, unsigned long rate) { int ret; struct dfll_rate_req req; if (td->mode == DFLL_UNINITIALIZED) { dev_err(td->dev, "%s: Cannot set DFLL rate in %s mode\n", __func__, mode_name[td->mode]); return -EPERM; } ret = dfll_calculate_rate_request(td, &req, rate); if (ret) return ret; td->last_unrounded_rate = rate; td->last_req = req; if (td->mode == DFLL_CLOSED_LOOP) dfll_set_frequency_request(td, &td->last_req); return 0; } /* * DFLL enable/disable & open-loop <-> closed-loop transitions */ /** * dfll_disable - switch from open-loop mode to disabled mode * @td: DFLL instance * * Switch from OPEN_LOOP state to DISABLED state. Returns 0 upon success * or -EPERM if the DFLL is not currently in open-loop mode. */ static int dfll_disable(struct tegra_dfll *td) { if (td->mode != DFLL_OPEN_LOOP) { dev_err(td->dev, "cannot disable DFLL in %s mode\n", mode_name[td->mode]); return -EINVAL; } dfll_set_mode(td, DFLL_DISABLED); pm_runtime_put_sync(td->dev); return 0; } /** * dfll_enable - switch a disabled DFLL to open-loop mode * @td: DFLL instance * * Switch from DISABLED state to OPEN_LOOP state. Returns 0 upon success * or -EPERM if the DFLL is not currently disabled. */ static int dfll_enable(struct tegra_dfll *td) { if (td->mode != DFLL_DISABLED) { dev_err(td->dev, "cannot enable DFLL in %s mode\n", mode_name[td->mode]); return -EPERM; } pm_runtime_get_sync(td->dev); dfll_set_mode(td, DFLL_OPEN_LOOP); return 0; } /** * dfll_set_open_loop_config - prepare to switch to open-loop mode * @td: DFLL instance * * Prepare to switch the DFLL to open-loop mode. This switches the * DFLL to the low-voltage tuning range, ensures that I2C output * forcing is disabled, and disables the output clock rate scaler. * The DFLL's low-voltage tuning range parameters must be * characterized to keep the downstream device stable at any DVCO * input voltage. No return value. */ static void dfll_set_open_loop_config(struct tegra_dfll *td) { u32 val; /* always tune low (safe) in open loop */ if (td->tune_range != DFLL_TUNE_LOW) dfll_tune_low(td); val = dfll_readl(td, DFLL_FREQ_REQ); val |= DFLL_FREQ_REQ_SCALE_MASK; val &= ~DFLL_FREQ_REQ_FORCE_ENABLE; dfll_writel(td, val, DFLL_FREQ_REQ); dfll_wmb(td); } /** * dfll_lock - switch from open-loop to closed-loop mode * @td: DFLL instance * * Switch from OPEN_LOOP state to CLOSED_LOOP state. Returns 0 upon success, * -EINVAL if the DFLL's target rate hasn't been set yet, or -EPERM if the * DFLL is not currently in open-loop mode. */ static int dfll_lock(struct tegra_dfll *td) { struct dfll_rate_req *req = &td->last_req; switch (td->mode) { case DFLL_CLOSED_LOOP: return 0; case DFLL_OPEN_LOOP: if (req->rate == 0) { dev_err(td->dev, "%s: Cannot lock DFLL at rate 0\n", __func__); return -EINVAL; } if (td->pmu_if == TEGRA_DFLL_PMU_PWM) dfll_pwm_set_output_enabled(td, true); else dfll_i2c_set_output_enabled(td, true); dfll_set_mode(td, DFLL_CLOSED_LOOP); dfll_set_frequency_request(td, req); dfll_set_force_output_enabled(td, false); return 0; default: BUG_ON(td->mode > DFLL_CLOSED_LOOP); dev_err(td->dev, "%s: Cannot lock DFLL in %s mode\n", __func__, mode_name[td->mode]); return -EPERM; } } /** * dfll_unlock - switch from closed-loop to open-loop mode * @td: DFLL instance * * Switch from CLOSED_LOOP state to OPEN_LOOP state. Returns 0 upon success, * or -EPERM if the DFLL is not currently in open-loop mode. */ static int dfll_unlock(struct tegra_dfll *td) { switch (td->mode) { case DFLL_CLOSED_LOOP: dfll_set_open_loop_config(td); dfll_set_mode(td, DFLL_OPEN_LOOP); if (td->pmu_if == TEGRA_DFLL_PMU_PWM) dfll_pwm_set_output_enabled(td, false); else dfll_i2c_set_output_enabled(td, false); return 0; case DFLL_OPEN_LOOP: return 0; default: BUG_ON(td->mode > DFLL_CLOSED_LOOP); dev_err(td->dev, "%s: Cannot unlock DFLL in %s mode\n", __func__, mode_name[td->mode]); return -EPERM; } } /* * Clock framework integration * * When the DFLL is being controlled by the CCF, always enter closed loop * mode when the clk is enabled. This requires that a DFLL rate request * has been set beforehand, which implies that a clk_set_rate() call is * always required before a clk_enable(). */ static int dfll_clk_is_enabled(struct clk_hw *hw) { struct tegra_dfll *td = clk_hw_to_dfll(hw); return dfll_is_running(td); } static int dfll_clk_enable(struct clk_hw *hw) { struct tegra_dfll *td = clk_hw_to_dfll(hw); int ret; ret = dfll_enable(td); if (ret) return ret; ret = dfll_lock(td); if (ret) dfll_disable(td); return ret; } static void dfll_clk_disable(struct clk_hw *hw) { struct tegra_dfll *td = clk_hw_to_dfll(hw); int ret; ret = dfll_unlock(td); if (!ret) dfll_disable(td); } static unsigned long dfll_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_dfll *td = clk_hw_to_dfll(hw); return td->last_unrounded_rate; } /* Must use determine_rate since it allows for rates exceeding 2^31-1 */ static int dfll_clk_determine_rate(struct clk_hw *hw, struct clk_rate_request *clk_req) { struct tegra_dfll *td = clk_hw_to_dfll(hw); struct dfll_rate_req req; int ret; ret = dfll_calculate_rate_request(td, &req, clk_req->rate); if (ret) return ret; /* * Don't set the rounded rate, since it doesn't really matter as * the output rate will be voltage controlled anyway, and cpufreq * freaks out if any rounding happens. */ return 0; } static int dfll_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_dfll *td = clk_hw_to_dfll(hw); return dfll_request_rate(td, rate); } static const struct clk_ops dfll_clk_ops = { .is_enabled = dfll_clk_is_enabled, .enable = dfll_clk_enable, .disable = dfll_clk_disable, .recalc_rate = dfll_clk_recalc_rate, .determine_rate = dfll_clk_determine_rate, .set_rate = dfll_clk_set_rate, }; static struct clk_init_data dfll_clk_init_data = { .ops = &dfll_clk_ops, .num_parents = 0, }; /** * dfll_register_clk - register the DFLL output clock with the clock framework * @td: DFLL instance * * Register the DFLL's output clock with the Linux clock framework and register * the DFLL driver as an OF clock provider. Returns 0 upon success or -EINVAL * or -ENOMEM upon failure. */ static int dfll_register_clk(struct tegra_dfll *td) { int ret; dfll_clk_init_data.name = td->output_clock_name; td->dfll_clk_hw.init = &dfll_clk_init_data; td->dfll_clk = clk_register(td->dev, &td->dfll_clk_hw); if (IS_ERR(td->dfll_clk)) { dev_err(td->dev, "DFLL clock registration error\n"); return -EINVAL; } ret = of_clk_add_provider(td->dev->of_node, of_clk_src_simple_get, td->dfll_clk); if (ret) { dev_err(td->dev, "of_clk_add_provider() failed\n"); clk_unregister(td->dfll_clk); return ret; } return 0; } /** * dfll_unregister_clk - unregister the DFLL output clock * @td: DFLL instance * * Unregister the DFLL's output clock from the Linux clock framework * and from clkdev. No return value. */ static void dfll_unregister_clk(struct tegra_dfll *td) { of_clk_del_provider(td->dev->of_node); clk_unregister(td->dfll_clk); td->dfll_clk = NULL; } /* * Debugfs interface */ #ifdef CONFIG_DEBUG_FS /* * Monitor control */ /** * dfll_calc_monitored_rate - convert DFLL_MONITOR_DATA_VAL rate into real freq * @monitor_data: value read from the DFLL_MONITOR_DATA_VAL bitfield * @ref_rate: DFLL reference clock rate * * Convert @monitor_data from DFLL_MONITOR_DATA_VAL units into cycles * per second. Returns the converted value. */ static u64 dfll_calc_monitored_rate(u32 monitor_data, unsigned long ref_rate) { return monitor_data * (ref_rate / REF_CLK_CYC_PER_DVCO_SAMPLE); } /** * dfll_read_monitor_rate - return the DFLL's output rate from internal monitor * @td: DFLL instance * * If the DFLL is enabled, return the last rate reported by the DFLL's * internal monitoring hardware. This works in both open-loop and * closed-loop mode, and takes the output scaler setting into account. * Assumes that the monitor was programmed to monitor frequency before * the sample period started. If the driver believes that the DFLL is * currently uninitialized or disabled, it will return 0, since * otherwise the DFLL monitor data register will return the last * measured rate from when the DFLL was active. */ static u64 dfll_read_monitor_rate(struct tegra_dfll *td) { u32 v, s; u64 pre_scaler_rate, post_scaler_rate; if (!dfll_is_running(td)) return 0; v = dfll_readl(td, DFLL_MONITOR_DATA); v = (v & DFLL_MONITOR_DATA_VAL_MASK) >> DFLL_MONITOR_DATA_VAL_SHIFT; pre_scaler_rate = dfll_calc_monitored_rate(v, td->ref_rate); s = dfll_readl(td, DFLL_FREQ_REQ); s = (s & DFLL_FREQ_REQ_SCALE_MASK) >> DFLL_FREQ_REQ_SCALE_SHIFT; post_scaler_rate = dfll_scale_dvco_rate(s, pre_scaler_rate); return post_scaler_rate; } static int attr_enable_get(void *data, u64 *val) { struct tegra_dfll *td = data; *val = dfll_is_running(td); return 0; } static int attr_enable_set(void *data, u64 val) { struct tegra_dfll *td = data; return val ? dfll_enable(td) : dfll_disable(td); } DEFINE_DEBUGFS_ATTRIBUTE(enable_fops, attr_enable_get, attr_enable_set, "%llu\n"); static int attr_lock_get(void *data, u64 *val) { struct tegra_dfll *td = data; *val = (td->mode == DFLL_CLOSED_LOOP); return 0; } static int attr_lock_set(void *data, u64 val) { struct tegra_dfll *td = data; return val ? dfll_lock(td) : dfll_unlock(td); } DEFINE_DEBUGFS_ATTRIBUTE(lock_fops, attr_lock_get, attr_lock_set, "%llu\n"); static int attr_rate_get(void *data, u64 *val) { struct tegra_dfll *td = data; *val = dfll_read_monitor_rate(td); return 0; } static int attr_rate_set(void *data, u64 val) { struct tegra_dfll *td = data; return dfll_request_rate(td, val); } DEFINE_DEBUGFS_ATTRIBUTE(rate_fops, attr_rate_get, attr_rate_set, "%llu\n"); static int attr_registers_show(struct seq_file *s, void *data) { u32 val, offs; struct tegra_dfll *td = s->private; seq_puts(s, "CONTROL REGISTERS:\n"); for (offs = 0; offs <= DFLL_MONITOR_DATA; offs += 4) { if (offs == DFLL_OUTPUT_CFG) val = dfll_i2c_readl(td, offs); else val = dfll_readl(td, offs); seq_printf(s, "[0x%02x] = 0x%08x\n", offs, val); } seq_puts(s, "\nI2C and INTR REGISTERS:\n"); for (offs = DFLL_I2C_CFG; offs <= DFLL_I2C_STS; offs += 4) seq_printf(s, "[0x%02x] = 0x%08x\n", offs, dfll_i2c_readl(td, offs)); for (offs = DFLL_INTR_STS; offs <= DFLL_INTR_EN; offs += 4) seq_printf(s, "[0x%02x] = 0x%08x\n", offs, dfll_i2c_readl(td, offs)); if (td->pmu_if == TEGRA_DFLL_PMU_I2C) { seq_puts(s, "\nINTEGRATED I2C CONTROLLER REGISTERS:\n"); offs = DFLL_I2C_CLK_DIVISOR; seq_printf(s, "[0x%02x] = 0x%08x\n", offs, __raw_readl(td->i2c_controller_base + offs)); seq_puts(s, "\nLUT:\n"); for (offs = 0; offs < 4 * MAX_DFLL_VOLTAGES; offs += 4) seq_printf(s, "[0x%02x] = 0x%08x\n", offs, __raw_readl(td->lut_base + offs)); } return 0; } DEFINE_SHOW_ATTRIBUTE(attr_registers); static void dfll_debug_init(struct tegra_dfll *td) { struct dentry *root; if (!td || (td->mode == DFLL_UNINITIALIZED)) return; root = debugfs_create_dir("tegra_dfll_fcpu", NULL); td->debugfs_dir = root; debugfs_create_file_unsafe("enable", 0644, root, td, &enable_fops); debugfs_create_file_unsafe("lock", 0444, root, td, &lock_fops); debugfs_create_file_unsafe("rate", 0444, root, td, &rate_fops); debugfs_create_file("registers", 0444, root, td, &attr_registers_fops); } #else static inline void dfll_debug_init(struct tegra_dfll *td) { } #endif /* CONFIG_DEBUG_FS */ /* * DFLL initialization */ /** * dfll_set_default_params - program non-output related DFLL parameters * @td: DFLL instance * * During DFLL driver initialization or resume from context loss, * program parameters for the closed loop integrator, DVCO tuning, * voltage droop control and monitor control. */ static void dfll_set_default_params(struct tegra_dfll *td) { u32 val; val = DIV_ROUND_UP(td->ref_rate, td->sample_rate * 32); BUG_ON(val > DFLL_CONFIG_DIV_MASK); dfll_writel(td, val, DFLL_CONFIG); val = (td->force_mode << DFLL_PARAMS_FORCE_MODE_SHIFT) | (td->cf << DFLL_PARAMS_CF_PARAM_SHIFT) | (td->ci << DFLL_PARAMS_CI_PARAM_SHIFT) | (td->cg << DFLL_PARAMS_CG_PARAM_SHIFT) | (td->cg_scale ? DFLL_PARAMS_CG_SCALE : 0); dfll_writel(td, val, DFLL_PARAMS); dfll_tune_low(td); dfll_writel(td, td->droop_ctrl, DFLL_DROOP_CTRL); dfll_writel(td, DFLL_MONITOR_CTRL_FREQ, DFLL_MONITOR_CTRL); } /** * dfll_init_clks - clk_get() the DFLL source clocks * @td: DFLL instance * * Call clk_get() on the DFLL source clocks and save the pointers for later * use. Returns 0 upon success or error (see devm_clk_get) if one or more * of the clocks couldn't be looked up. */ static int dfll_init_clks(struct tegra_dfll *td) { td->ref_clk = devm_clk_get(td->dev, "ref"); if (IS_ERR(td->ref_clk)) { dev_err(td->dev, "missing ref clock\n"); return PTR_ERR(td->ref_clk); } td->soc_clk = devm_clk_get(td->dev, "soc"); if (IS_ERR(td->soc_clk)) { dev_err(td->dev, "missing soc clock\n"); return PTR_ERR(td->soc_clk); } td->i2c_clk = devm_clk_get(td->dev, "i2c"); if (IS_ERR(td->i2c_clk)) { dev_err(td->dev, "missing i2c clock\n"); return PTR_ERR(td->i2c_clk); } td->i2c_clk_rate = clk_get_rate(td->i2c_clk); return 0; } /** * dfll_init - Prepare the DFLL IP block for use * @td: DFLL instance * * Do everything necessary to prepare the DFLL IP block for use. The * DFLL will be left in DISABLED state. Called by dfll_probe(). * Returns 0 upon success, or passes along the error from whatever * function returned it. */ static int dfll_init(struct tegra_dfll *td) { int ret; td->ref_rate = clk_get_rate(td->ref_clk); if (td->ref_rate != REF_CLOCK_RATE) { dev_err(td->dev, "unexpected ref clk rate %lu, expecting %lu", td->ref_rate, REF_CLOCK_RATE); return -EINVAL; } reset_control_deassert(td->dfll_rst); reset_control_deassert(td->dvco_rst); ret = clk_prepare(td->ref_clk); if (ret) { dev_err(td->dev, "failed to prepare ref_clk\n"); return ret; } ret = clk_prepare(td->soc_clk); if (ret) { dev_err(td->dev, "failed to prepare soc_clk\n"); goto di_err1; } ret = clk_prepare(td->i2c_clk); if (ret) { dev_err(td->dev, "failed to prepare i2c_clk\n"); goto di_err2; } td->last_unrounded_rate = 0; pm_runtime_enable(td->dev); pm_runtime_get_sync(td->dev); dfll_set_mode(td, DFLL_DISABLED); dfll_set_default_params(td); if (td->soc->init_clock_trimmers) td->soc->init_clock_trimmers(); dfll_set_open_loop_config(td); dfll_init_out_if(td); pm_runtime_put_sync(td->dev); return 0; di_err2: clk_unprepare(td->soc_clk); di_err1: clk_unprepare(td->ref_clk); reset_control_assert(td->dvco_rst); reset_control_assert(td->dfll_rst); return ret; } /** * tegra_dfll_suspend - check DFLL is disabled * @dev: DFLL instance * * DFLL clock should be disabled by the CPUFreq driver. So, make * sure it is disabled and disable all clocks needed by the DFLL. */ int tegra_dfll_suspend(struct device *dev) { struct tegra_dfll *td = dev_get_drvdata(dev); if (dfll_is_running(td)) { dev_err(td->dev, "DFLL still enabled while suspending\n"); return -EBUSY; } reset_control_assert(td->dvco_rst); reset_control_assert(td->dfll_rst); return 0; } EXPORT_SYMBOL(tegra_dfll_suspend); /** * tegra_dfll_resume - reinitialize DFLL on resume * @dev: DFLL instance * * DFLL is disabled and reset during suspend and resume. * So, reinitialize the DFLL IP block back for use. * DFLL clock is enabled later in closed loop mode by CPUFreq * driver before switching its clock source to DFLL output. */ int tegra_dfll_resume(struct device *dev) { struct tegra_dfll *td = dev_get_drvdata(dev); reset_control_deassert(td->dfll_rst); reset_control_deassert(td->dvco_rst); pm_runtime_get_sync(td->dev); dfll_set_mode(td, DFLL_DISABLED); dfll_set_default_params(td); if (td->soc->init_clock_trimmers) td->soc->init_clock_trimmers(); dfll_set_open_loop_config(td); dfll_init_out_if(td); pm_runtime_put_sync(td->dev); return 0; } EXPORT_SYMBOL(tegra_dfll_resume); /* * DT data fetch */ /* * Find a PMIC voltage register-to-voltage mapping for the given voltage. * An exact voltage match is required. */ static int find_vdd_map_entry_exact(struct tegra_dfll *td, int uV) { int i, n_voltages, reg_uV,reg_volt_id, align_step; if (WARN_ON(td->pmu_if == TEGRA_DFLL_PMU_PWM)) return -EINVAL; align_step = uV / td->soc->alignment.step_uv; n_voltages = regulator_count_voltages(td->vdd_reg); for (i = 0; i < n_voltages; i++) { reg_uV = regulator_list_voltage(td->vdd_reg, i); if (reg_uV < 0) break; reg_volt_id = reg_uV / td->soc->alignment.step_uv; if (align_step == reg_volt_id) return i; } dev_err(td->dev, "no voltage map entry for %d uV\n", uV); return -EINVAL; } /* * Find a PMIC voltage register-to-voltage mapping for the given voltage, * rounding up to the closest supported voltage. * */ static int find_vdd_map_entry_min(struct tegra_dfll *td, int uV) { int i, n_voltages, reg_uV, reg_volt_id, align_step; if (WARN_ON(td->pmu_if == TEGRA_DFLL_PMU_PWM)) return -EINVAL; align_step = uV / td->soc->alignment.step_uv; n_voltages = regulator_count_voltages(td->vdd_reg); for (i = 0; i < n_voltages; i++) { reg_uV = regulator_list_voltage(td->vdd_reg, i); if (reg_uV < 0) break; reg_volt_id = reg_uV / td->soc->alignment.step_uv; if (align_step <= reg_volt_id) return i; } dev_err(td->dev, "no voltage map entry rounding to %d uV\n", uV); return -EINVAL; } /* * dfll_build_pwm_lut - build the PWM regulator lookup table * @td: DFLL instance * @v_max: Vmax from OPP table * * Look-up table in h/w is ignored when PWM is used as DFLL interface to PMIC. * In this case closed loop output is controlling duty cycle directly. The s/w * look-up that maps PWM duty cycle to voltage is still built by this function. */ static int dfll_build_pwm_lut(struct tegra_dfll *td, unsigned long v_max) { int i; unsigned long rate, reg_volt; u8 lut_bottom = MAX_DFLL_VOLTAGES; int v_min = td->soc->cvb->min_millivolts * 1000; for (i = 0; i < MAX_DFLL_VOLTAGES; i++) { reg_volt = td->lut_uv[i]; /* since opp voltage is exact mv */ reg_volt = (reg_volt / 1000) * 1000; if (reg_volt > v_max) break; td->lut[i] = i; if ((lut_bottom == MAX_DFLL_VOLTAGES) && (reg_volt >= v_min)) lut_bottom = i; } /* determine voltage boundaries */ td->lut_size = i; if ((lut_bottom == MAX_DFLL_VOLTAGES) || (lut_bottom + 1 >= td->lut_size)) { dev_err(td->dev, "no voltage above DFLL minimum %d mV\n", td->soc->cvb->min_millivolts); return -EINVAL; } td->lut_bottom = lut_bottom; /* determine rate boundaries */ rate = get_dvco_rate_below(td, td->lut_bottom); if (!rate) { dev_err(td->dev, "no opp below DFLL minimum voltage %d mV\n", td->soc->cvb->min_millivolts); return -EINVAL; } td->dvco_rate_min = rate; return 0; } /** * dfll_build_i2c_lut - build the I2C voltage register lookup table * @td: DFLL instance * @v_max: Vmax from OPP table * * The DFLL hardware has 33 bytes of look-up table RAM that must be filled with * PMIC voltage register values that span the entire DFLL operating range. * This function builds the look-up table based on the OPP table provided by * the soc-specific platform driver (td->soc->opp_dev) and the PMIC * register-to-voltage mapping queried from the regulator framework. * * On success, fills in td->lut and returns 0, or -err on failure. */ static int dfll_build_i2c_lut(struct tegra_dfll *td, unsigned long v_max) { unsigned long rate, v, v_opp; int ret = -EINVAL; int j, selector, lut; v = td->soc->cvb->min_millivolts * 1000; lut = find_vdd_map_entry_exact(td, v); if (lut < 0) goto out; td->lut[0] = lut; td->lut_bottom = 0; for (j = 1, rate = 0; ; rate++) { struct dev_pm_opp *opp; opp = dev_pm_opp_find_freq_ceil(td->soc->dev, &rate); if (IS_ERR(opp)) break; v_opp = dev_pm_opp_get_voltage(opp); if (v_opp <= td->soc->cvb->min_millivolts * 1000) td->dvco_rate_min = dev_pm_opp_get_freq(opp); dev_pm_opp_put(opp); for (;;) { v += max(1UL, (v_max - v) / (MAX_DFLL_VOLTAGES - j)); if (v >= v_opp) break; selector = find_vdd_map_entry_min(td, v); if (selector < 0) goto out; if (selector != td->lut[j - 1]) td->lut[j++] = selector; } v = (j == MAX_DFLL_VOLTAGES - 1) ? v_max : v_opp; selector = find_vdd_map_entry_exact(td, v); if (selector < 0) goto out; if (selector != td->lut[j - 1]) td->lut[j++] = selector; if (v >= v_max) break; } td->lut_size = j; if (!td->dvco_rate_min) dev_err(td->dev, "no opp above DFLL minimum voltage %d mV\n", td->soc->cvb->min_millivolts); else { ret = 0; for (j = 0; j < td->lut_size; j++) td->lut_uv[j] = regulator_list_voltage(td->vdd_reg, td->lut[j]); } out: return ret; } static int dfll_build_lut(struct tegra_dfll *td) { unsigned long rate, v_max; struct dev_pm_opp *opp; rate = ULONG_MAX; opp = dev_pm_opp_find_freq_floor(td->soc->dev, &rate); if (IS_ERR(opp)) { dev_err(td->dev, "couldn't get vmax opp, empty opp table?\n"); return -EINVAL; } v_max = dev_pm_opp_get_voltage(opp); dev_pm_opp_put(opp); if (td->pmu_if == TEGRA_DFLL_PMU_PWM) return dfll_build_pwm_lut(td, v_max); else return dfll_build_i2c_lut(td, v_max); } /** * read_dt_param - helper function for reading required parameters from the DT * @td: DFLL instance * @param: DT property name * @dest: output pointer for the value read * * Read a required numeric parameter from the DFLL device node, or complain * if the property doesn't exist. Returns a boolean indicating success for * easy chaining of multiple calls to this function. */ static bool read_dt_param(struct tegra_dfll *td, const char *param, u32 *dest) { int err = of_property_read_u32(td->dev->of_node, param, dest); if (err < 0) { dev_err(td->dev, "failed to read DT parameter %s: %d\n", param, err); return false; } return true; } /** * dfll_fetch_i2c_params - query PMIC I2C params from DT & regulator subsystem * @td: DFLL instance * * Read all the parameters required for operation in I2C mode. The parameters * can originate from the device tree or the regulator subsystem. * Returns 0 on success or -err on failure. */ static int dfll_fetch_i2c_params(struct tegra_dfll *td) { struct regmap *regmap; struct device *i2c_dev; struct i2c_client *i2c_client; int vsel_reg, vsel_mask; int ret; if (!read_dt_param(td, "nvidia,i2c-fs-rate", &td->i2c_fs_rate)) return -EINVAL; regmap = regulator_get_regmap(td->vdd_reg); i2c_dev = regmap_get_device(regmap); i2c_client = to_i2c_client(i2c_dev); td->i2c_slave_addr = i2c_client->addr; ret = regulator_get_hardware_vsel_register(td->vdd_reg, &vsel_reg, &vsel_mask); if (ret < 0) { dev_err(td->dev, "regulator unsuitable for DFLL I2C operation\n"); return -EINVAL; } td->i2c_reg = vsel_reg; return 0; } static int dfll_fetch_pwm_params(struct tegra_dfll *td) { int ret, i; u32 pwm_period; if (!td->soc->alignment.step_uv || !td->soc->alignment.offset_uv) { dev_err(td->dev, "Missing step or alignment info for PWM regulator"); return -EINVAL; } for (i = 0; i < MAX_DFLL_VOLTAGES; i++) td->lut_uv[i] = td->soc->alignment.offset_uv + i * td->soc->alignment.step_uv; ret = read_dt_param(td, "nvidia,pwm-tristate-microvolts", &td->reg_init_uV); if (!ret) { dev_err(td->dev, "couldn't get initialized voltage\n"); return -EINVAL; } ret = read_dt_param(td, "nvidia,pwm-period-nanoseconds", &pwm_period); if (!ret) { dev_err(td->dev, "couldn't get PWM period\n"); return -EINVAL; } td->pwm_rate = (NSEC_PER_SEC / pwm_period) * (MAX_DFLL_VOLTAGES - 1); td->pwm_pin = devm_pinctrl_get(td->dev); if (IS_ERR(td->pwm_pin)) { dev_err(td->dev, "DT: missing pinctrl device\n"); return PTR_ERR(td->pwm_pin); } td->pwm_enable_state = pinctrl_lookup_state(td->pwm_pin, "dvfs_pwm_enable"); if (IS_ERR(td->pwm_enable_state)) { dev_err(td->dev, "DT: missing pwm enabled state\n"); return PTR_ERR(td->pwm_enable_state); } td->pwm_disable_state = pinctrl_lookup_state(td->pwm_pin, "dvfs_pwm_disable"); if (IS_ERR(td->pwm_disable_state)) { dev_err(td->dev, "DT: missing pwm disabled state\n"); return PTR_ERR(td->pwm_disable_state); } return 0; } /** * dfll_fetch_common_params - read DFLL parameters from the device tree * @td: DFLL instance * * Read all the DT parameters that are common to both I2C and PWM operation. * Returns 0 on success or -EINVAL on any failure. */ static int dfll_fetch_common_params(struct tegra_dfll *td) { bool ok = true; ok &= read_dt_param(td, "nvidia,droop-ctrl", &td->droop_ctrl); ok &= read_dt_param(td, "nvidia,sample-rate", &td->sample_rate); ok &= read_dt_param(td, "nvidia,force-mode", &td->force_mode); ok &= read_dt_param(td, "nvidia,cf", &td->cf); ok &= read_dt_param(td, "nvidia,ci", &td->ci); ok &= read_dt_param(td, "nvidia,cg", &td->cg); td->cg_scale = of_property_read_bool(td->dev->of_node, "nvidia,cg-scale"); if (of_property_read_string(td->dev->of_node, "clock-output-names", &td->output_clock_name)) { dev_err(td->dev, "missing clock-output-names property\n"); ok = false; } return ok ? 0 : -EINVAL; } /* * API exported to per-SoC platform drivers */ /** * tegra_dfll_register - probe a Tegra DFLL device * @pdev: DFLL platform_device * * @soc: Per-SoC integration and characterization data for this DFLL instance * * Probe and initialize a DFLL device instance. Intended to be called * by a SoC-specific shim driver that passes in per-SoC integration * and configuration data via @soc. Returns 0 on success or -err on failure. */ int tegra_dfll_register(struct platform_device *pdev, struct tegra_dfll_soc_data *soc) { struct resource *mem; struct tegra_dfll *td; int ret; if (!soc) { dev_err(&pdev->dev, "no tegra_dfll_soc_data provided\n"); return -EINVAL; } td = devm_kzalloc(&pdev->dev, sizeof(*td), GFP_KERNEL); if (!td) return -ENOMEM; td->dev = &pdev->dev; platform_set_drvdata(pdev, td); td->soc = soc; td->dfll_rst = devm_reset_control_get_optional(td->dev, "dfll"); if (IS_ERR(td->dfll_rst)) { dev_err(td->dev, "couldn't get dfll reset\n"); return PTR_ERR(td->dfll_rst); } td->dvco_rst = devm_reset_control_get(td->dev, "dvco"); if (IS_ERR(td->dvco_rst)) { dev_err(td->dev, "couldn't get dvco reset\n"); return PTR_ERR(td->dvco_rst); } ret = dfll_fetch_common_params(td); if (ret) { dev_err(td->dev, "couldn't parse device tree parameters\n"); return ret; } if (of_property_read_bool(td->dev->of_node, "nvidia,pwm-to-pmic")) { td->pmu_if = TEGRA_DFLL_PMU_PWM; ret = dfll_fetch_pwm_params(td); } else { td->vdd_reg = devm_regulator_get(td->dev, "vdd-cpu"); if (IS_ERR(td->vdd_reg)) { dev_err(td->dev, "couldn't get vdd_cpu regulator\n"); return PTR_ERR(td->vdd_reg); } td->pmu_if = TEGRA_DFLL_PMU_I2C; ret = dfll_fetch_i2c_params(td); } if (ret) return ret; ret = dfll_build_lut(td); if (ret) { dev_err(td->dev, "couldn't build LUT\n"); return ret; } mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!mem) { dev_err(td->dev, "no control register resource\n"); return -ENODEV; } td->base = devm_ioremap(td->dev, mem->start, resource_size(mem)); if (!td->base) { dev_err(td->dev, "couldn't ioremap DFLL control registers\n"); return -ENODEV; } mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); if (!mem) { dev_err(td->dev, "no i2c_base resource\n"); return -ENODEV; } td->i2c_base = devm_ioremap(td->dev, mem->start, resource_size(mem)); if (!td->i2c_base) { dev_err(td->dev, "couldn't ioremap i2c_base resource\n"); return -ENODEV; } mem = platform_get_resource(pdev, IORESOURCE_MEM, 2); if (!mem) { dev_err(td->dev, "no i2c_controller_base resource\n"); return -ENODEV; } td->i2c_controller_base = devm_ioremap(td->dev, mem->start, resource_size(mem)); if (!td->i2c_controller_base) { dev_err(td->dev, "couldn't ioremap i2c_controller_base resource\n"); return -ENODEV; } mem = platform_get_resource(pdev, IORESOURCE_MEM, 3); if (!mem) { dev_err(td->dev, "no lut_base resource\n"); return -ENODEV; } td->lut_base = devm_ioremap(td->dev, mem->start, resource_size(mem)); if (!td->lut_base) { dev_err(td->dev, "couldn't ioremap lut_base resource\n"); return -ENODEV; } ret = dfll_init_clks(td); if (ret) { dev_err(&pdev->dev, "DFLL clock init error\n"); return ret; } /* Enable the clocks and set the device up */ ret = dfll_init(td); if (ret) return ret; ret = dfll_register_clk(td); if (ret) { dev_err(&pdev->dev, "DFLL clk registration failed\n"); return ret; } dfll_debug_init(td); return 0; } EXPORT_SYMBOL(tegra_dfll_register); /** * tegra_dfll_unregister - release all of the DFLL driver resources for a device * @pdev: DFLL platform_device * * * Unbind this driver from the DFLL hardware device represented by * @pdev. The DFLL must be disabled for this to succeed. Returns a * soc pointer upon success or -EBUSY if the DFLL is still active. */ struct tegra_dfll_soc_data *tegra_dfll_unregister(struct platform_device *pdev) { struct tegra_dfll *td = platform_get_drvdata(pdev); /* * Note that exiting early here doesn't prevent unbinding the driver. * Exiting early here only leaks some resources. */ if (td->mode != DFLL_DISABLED) { dev_err(&pdev->dev, "must disable DFLL before removing driver\n"); return ERR_PTR(-EBUSY); } debugfs_remove_recursive(td->debugfs_dir); dfll_unregister_clk(td); pm_runtime_disable(&pdev->dev); clk_unprepare(td->ref_clk); clk_unprepare(td->soc_clk); clk_unprepare(td->i2c_clk); reset_control_assert(td->dvco_rst); reset_control_assert(td->dfll_rst); return td->soc; } EXPORT_SYMBOL(tegra_dfll_unregister);
linux-master
drivers/clk/tegra/clk-dfll.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/clk/tegra.h> #include <dt-bindings/clock/tegra114-car.h> #include "clk.h" #include "clk-id.h" #define RST_DFLL_DVCO 0x2F4 #define CPU_FINETRIM_SELECT 0x4d4 /* override default prop dlys */ #define CPU_FINETRIM_DR 0x4d8 /* rise->rise prop dly A */ #define CPU_FINETRIM_R 0x4e4 /* rise->rise prop dly inc A */ /* RST_DFLL_DVCO bitfields */ #define DVFS_DFLL_RESET_SHIFT 0 /* CPU_FINETRIM_SELECT and CPU_FINETRIM_DR bitfields */ #define CPU_FINETRIM_1_FCPU_1 BIT(0) /* fcpu0 */ #define CPU_FINETRIM_1_FCPU_2 BIT(1) /* fcpu1 */ #define CPU_FINETRIM_1_FCPU_3 BIT(2) /* fcpu2 */ #define CPU_FINETRIM_1_FCPU_4 BIT(3) /* fcpu3 */ #define CPU_FINETRIM_1_FCPU_5 BIT(4) /* fl2 */ #define CPU_FINETRIM_1_FCPU_6 BIT(5) /* ftop */ /* CPU_FINETRIM_R bitfields */ #define CPU_FINETRIM_R_FCPU_1_SHIFT 0 /* fcpu0 */ #define CPU_FINETRIM_R_FCPU_1_MASK (0x3 << CPU_FINETRIM_R_FCPU_1_SHIFT) #define CPU_FINETRIM_R_FCPU_2_SHIFT 2 /* fcpu1 */ #define CPU_FINETRIM_R_FCPU_2_MASK (0x3 << CPU_FINETRIM_R_FCPU_2_SHIFT) #define CPU_FINETRIM_R_FCPU_3_SHIFT 4 /* fcpu2 */ #define CPU_FINETRIM_R_FCPU_3_MASK (0x3 << CPU_FINETRIM_R_FCPU_3_SHIFT) #define CPU_FINETRIM_R_FCPU_4_SHIFT 6 /* fcpu3 */ #define CPU_FINETRIM_R_FCPU_4_MASK (0x3 << CPU_FINETRIM_R_FCPU_4_SHIFT) #define CPU_FINETRIM_R_FCPU_5_SHIFT 8 /* fl2 */ #define CPU_FINETRIM_R_FCPU_5_MASK (0x3 << CPU_FINETRIM_R_FCPU_5_SHIFT) #define CPU_FINETRIM_R_FCPU_6_SHIFT 10 /* ftop */ #define CPU_FINETRIM_R_FCPU_6_MASK (0x3 << CPU_FINETRIM_R_FCPU_6_SHIFT) #define TEGRA114_CLK_PERIPH_BANKS 5 #define PLLC_BASE 0x80 #define PLLC_MISC2 0x88 #define PLLC_MISC 0x8c #define PLLC2_BASE 0x4e8 #define PLLC2_MISC 0x4ec #define PLLC3_BASE 0x4fc #define PLLC3_MISC 0x500 #define PLLM_BASE 0x90 #define PLLM_MISC 0x9c #define PLLP_BASE 0xa0 #define PLLP_MISC 0xac #define PLLX_BASE 0xe0 #define PLLX_MISC 0xe4 #define PLLX_MISC2 0x514 #define PLLX_MISC3 0x518 #define PLLD_BASE 0xd0 #define PLLD_MISC 0xdc #define PLLD2_BASE 0x4b8 #define PLLD2_MISC 0x4bc #define PLLE_BASE 0xe8 #define PLLE_MISC 0xec #define PLLA_BASE 0xb0 #define PLLA_MISC 0xbc #define PLLU_BASE 0xc0 #define PLLU_MISC 0xcc #define PLLRE_BASE 0x4c4 #define PLLRE_MISC 0x4c8 #define PLL_MISC_LOCK_ENABLE 18 #define PLLC_MISC_LOCK_ENABLE 24 #define PLLDU_MISC_LOCK_ENABLE 22 #define PLLE_MISC_LOCK_ENABLE 9 #define PLLRE_MISC_LOCK_ENABLE 30 #define PLLC_IDDQ_BIT 26 #define PLLX_IDDQ_BIT 3 #define PLLRE_IDDQ_BIT 16 #define PLL_BASE_LOCK BIT(27) #define PLLE_MISC_LOCK BIT(11) #define PLLRE_MISC_LOCK BIT(24) #define PLLCX_BASE_LOCK (BIT(26)|BIT(27)) #define PLLE_AUX 0x48c #define PLLC_OUT 0x84 #define PLLM_OUT 0x94 #define OSC_CTRL 0x50 #define OSC_CTRL_OSC_FREQ_SHIFT 28 #define OSC_CTRL_PLL_REF_DIV_SHIFT 26 #define PLLXC_SW_MAX_P 6 #define CCLKG_BURST_POLICY 0x368 #define CLK_SOURCE_CSITE 0x1d4 #define CLK_SOURCE_EMC 0x19c /* PLLM override registers */ #define PMC_PLLM_WB0_OVERRIDE 0x1dc #define PMC_PLLM_WB0_OVERRIDE_2 0x2b0 /* Tegra CPU clock and reset control regs */ #define CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470 #define MUX8(_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP,\ _clk_num, _gate_flags, _clk_id, _parents##_idx, 0,\ NULL) #ifdef CONFIG_PM_SLEEP static struct cpu_clk_suspend_context { u32 clk_csite_src; u32 cclkg_burst; u32 cclkg_divider; } tegra114_cpu_clk_sctx; #endif static void __iomem *clk_base; static void __iomem *pmc_base; static DEFINE_SPINLOCK(pll_d_lock); static DEFINE_SPINLOCK(pll_d2_lock); static DEFINE_SPINLOCK(pll_u_lock); static DEFINE_SPINLOCK(pll_re_lock); static DEFINE_SPINLOCK(emc_lock); static struct div_nmp pllxc_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 20, .divp_width = 4, }; static const struct pdiv_map pllxc_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 3, .hw_val = 2 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 5, .hw_val = 4 }, { .pdiv = 6, .hw_val = 5 }, { .pdiv = 8, .hw_val = 6 }, { .pdiv = 10, .hw_val = 7 }, { .pdiv = 12, .hw_val = 8 }, { .pdiv = 16, .hw_val = 9 }, { .pdiv = 12, .hw_val = 10 }, { .pdiv = 16, .hw_val = 11 }, { .pdiv = 20, .hw_val = 12 }, { .pdiv = 24, .hw_val = 13 }, { .pdiv = 32, .hw_val = 14 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_c_freq_table[] = { { 12000000, 624000000, 104, 1, 2, 0 }, { 12000000, 600000000, 100, 1, 2, 0 }, { 13000000, 600000000, 92, 1, 2, 0 }, /* actual: 598.0 MHz */ { 16800000, 600000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */ { 19200000, 600000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */ { 26000000, 600000000, 92, 2, 2, 0 }, /* actual: 598.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_c_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */ .vco_min = 600000000, .vco_max = 1400000000, .base_reg = PLLC_BASE, .misc_reg = PLLC_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLC_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLC_MISC, .iddq_bit_idx = PLLC_IDDQ_BIT, .max_p = PLLXC_SW_MAX_P, .dyn_ramp_reg = PLLC_MISC2, .stepa_shift = 17, .stepb_shift = 9, .pdiv_tohw = pllxc_p, .div_nmp = &pllxc_nmp, .freq_table = pll_c_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct div_nmp pllcx_nmp = { .divm_shift = 0, .divm_width = 2, .divn_shift = 8, .divn_width = 8, .divp_shift = 20, .divp_width = 3, }; static const struct pdiv_map pllc_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 8, .hw_val = 5 }, { .pdiv = 16, .hw_val = 7 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_cx_freq_table[] = { { 12000000, 600000000, 100, 1, 2, 0 }, { 13000000, 600000000, 92, 1, 2, 0 }, /* actual: 598.0 MHz */ { 16800000, 600000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */ { 19200000, 600000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */ { 26000000, 600000000, 92, 2, 2, 0 }, /* actual: 598.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_c2_params = { .input_min = 12000000, .input_max = 48000000, .cf_min = 12000000, .cf_max = 19200000, .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLC2_BASE, .misc_reg = PLLC2_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .pdiv_tohw = pllc_p, .div_nmp = &pllcx_nmp, .max_p = 7, .ext_misc_reg[0] = 0x4f0, .ext_misc_reg[1] = 0x4f4, .ext_misc_reg[2] = 0x4f8, .freq_table = pll_cx_freq_table, .flags = TEGRA_PLL_USE_LOCK, }; static struct tegra_clk_pll_params pll_c3_params = { .input_min = 12000000, .input_max = 48000000, .cf_min = 12000000, .cf_max = 19200000, .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLC3_BASE, .misc_reg = PLLC3_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .pdiv_tohw = pllc_p, .div_nmp = &pllcx_nmp, .max_p = 7, .ext_misc_reg[0] = 0x504, .ext_misc_reg[1] = 0x508, .ext_misc_reg[2] = 0x50c, .freq_table = pll_cx_freq_table, .flags = TEGRA_PLL_USE_LOCK, }; static struct div_nmp pllm_nmp = { .divm_shift = 0, .divm_width = 8, .override_divm_shift = 0, .divn_shift = 8, .divn_width = 8, .override_divn_shift = 8, .divp_shift = 20, .divp_width = 1, .override_divp_shift = 27, }; static const struct pdiv_map pllm_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_m_freq_table[] = { { 12000000, 800000000, 66, 1, 1, 0 }, /* actual: 792.0 MHz */ { 13000000, 800000000, 61, 1, 1, 0 }, /* actual: 793.0 MHz */ { 16800000, 800000000, 47, 1, 1, 0 }, /* actual: 789.6 MHz */ { 19200000, 800000000, 41, 1, 1, 0 }, /* actual: 787.2 MHz */ { 26000000, 800000000, 61, 2, 1, 0 }, /* actual: 793.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_m_params = { .input_min = 12000000, .input_max = 500000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */ .vco_min = 400000000, .vco_max = 1066000000, .base_reg = PLLM_BASE, .misc_reg = PLLM_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .max_p = 2, .pdiv_tohw = pllm_p, .div_nmp = &pllm_nmp, .pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE, .pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE_2, .freq_table = pll_m_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE | TEGRA_PLL_FIXED, }; static struct div_nmp pllp_nmp = { .divm_shift = 0, .divm_width = 5, .divn_shift = 8, .divn_width = 10, .divp_shift = 20, .divp_width = 3, }; static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { { 12000000, 216000000, 432, 12, 2, 8 }, { 13000000, 216000000, 432, 13, 2, 8 }, { 16800000, 216000000, 360, 14, 2, 8 }, { 19200000, 216000000, 360, 16, 2, 8 }, { 26000000, 216000000, 432, 26, 2, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_p_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 200000000, .vco_max = 700000000, .base_reg = PLLP_BASE, .misc_reg = PLLP_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .div_nmp = &pllp_nmp, .freq_table = pll_p_freq_table, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, .fixed_rate = 408000000, }; static struct tegra_clk_pll_freq_table pll_a_freq_table[] = { { 9600000, 282240000, 147, 5, 1, 4 }, { 9600000, 368640000, 192, 5, 1, 4 }, { 9600000, 240000000, 200, 8, 1, 8 }, { 28800000, 282240000, 245, 25, 1, 8 }, { 28800000, 368640000, 320, 25, 1, 8 }, { 28800000, 240000000, 200, 24, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_a_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 200000000, .vco_max = 700000000, .base_reg = PLLA_BASE, .misc_reg = PLLA_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .div_nmp = &pllp_nmp, .freq_table = pll_a_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { { 12000000, 216000000, 864, 12, 4, 12 }, { 13000000, 216000000, 864, 13, 4, 12 }, { 16800000, 216000000, 720, 14, 4, 12 }, { 19200000, 216000000, 720, 16, 4, 12 }, { 26000000, 216000000, 864, 26, 4, 12 }, { 12000000, 594000000, 594, 12, 1, 12 }, { 13000000, 594000000, 594, 13, 1, 12 }, { 16800000, 594000000, 495, 14, 1, 12 }, { 19200000, 594000000, 495, 16, 1, 12 }, { 26000000, 594000000, 594, 26, 1, 12 }, { 12000000, 1000000000, 1000, 12, 1, 12 }, { 13000000, 1000000000, 1000, 13, 1, 12 }, { 19200000, 1000000000, 625, 12, 1, 12 }, { 26000000, 1000000000, 1000, 26, 1, 12 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_d_params = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 500000000, .vco_max = 1000000000, .base_reg = PLLD_BASE, .misc_reg = PLLD_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .div_nmp = &pllp_nmp, .freq_table = pll_d_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_params pll_d2_params = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 500000000, .vco_max = 1000000000, .base_reg = PLLD2_BASE, .misc_reg = PLLD2_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .div_nmp = &pllp_nmp, .freq_table = pll_d_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | TEGRA_PLL_HAS_LOCK_ENABLE, }; static const struct pdiv_map pllu_p[] = { { .pdiv = 1, .hw_val = 1 }, { .pdiv = 2, .hw_val = 0 }, { .pdiv = 0, .hw_val = 0 }, }; static struct div_nmp pllu_nmp = { .divm_shift = 0, .divm_width = 5, .divn_shift = 8, .divn_width = 10, .divp_shift = 20, .divp_width = 1, }; static struct tegra_clk_pll_freq_table pll_u_freq_table[] = { { 12000000, 480000000, 960, 12, 2, 12 }, { 13000000, 480000000, 960, 13, 2, 12 }, { 16800000, 480000000, 400, 7, 2, 5 }, { 19200000, 480000000, 200, 4, 2, 3 }, { 26000000, 480000000, 960, 26, 2, 12 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_u_params = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 480000000, .vco_max = 960000000, .base_reg = PLLU_BASE, .misc_reg = PLLU_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .pdiv_tohw = pllu_p, .div_nmp = &pllu_nmp, .freq_table = pll_u_freq_table, .flags = TEGRA_PLLU | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_freq_table pll_x_freq_table[] = { /* 1 GHz */ { 12000000, 1000000000, 83, 1, 1, 0 }, /* actual: 996.0 MHz */ { 13000000, 1000000000, 76, 1, 1, 0 }, /* actual: 988.0 MHz */ { 16800000, 1000000000, 59, 1, 1, 0 }, /* actual: 991.2 MHz */ { 19200000, 1000000000, 52, 1, 1, 0 }, /* actual: 998.4 MHz */ { 26000000, 1000000000, 76, 2, 1, 0 }, /* actual: 988.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_x_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */ .vco_min = 700000000, .vco_max = 2400000000U, .base_reg = PLLX_BASE, .misc_reg = PLLX_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLX_MISC3, .iddq_bit_idx = PLLX_IDDQ_BIT, .max_p = PLLXC_SW_MAX_P, .dyn_ramp_reg = PLLX_MISC2, .stepa_shift = 16, .stepb_shift = 24, .pdiv_tohw = pllxc_p, .div_nmp = &pllxc_nmp, .freq_table = pll_x_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_freq_table pll_e_freq_table[] = { /* PLLE special case: use cpcon field to store cml divider value */ { 336000000, 100000000, 100, 21, 16, 11 }, { 312000000, 100000000, 200, 26, 24, 13 }, { 12000000, 100000000, 200, 1, 24, 13 }, { 0, 0, 0, 0, 0, 0 }, }; static const struct pdiv_map plle_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 3, .hw_val = 2 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 5, .hw_val = 4 }, { .pdiv = 6, .hw_val = 5 }, { .pdiv = 8, .hw_val = 6 }, { .pdiv = 10, .hw_val = 7 }, { .pdiv = 12, .hw_val = 8 }, { .pdiv = 16, .hw_val = 9 }, { .pdiv = 12, .hw_val = 10 }, { .pdiv = 16, .hw_val = 11 }, { .pdiv = 20, .hw_val = 12 }, { .pdiv = 24, .hw_val = 13 }, { .pdiv = 32, .hw_val = 14 }, { .pdiv = 0, .hw_val = 0 } }; static struct div_nmp plle_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 24, .divp_width = 4, }; static struct tegra_clk_pll_params pll_e_params = { .input_min = 12000000, .input_max = 1000000000, .cf_min = 12000000, .cf_max = 75000000, .vco_min = 1600000000, .vco_max = 2400000000U, .base_reg = PLLE_BASE, .misc_reg = PLLE_MISC, .aux_reg = PLLE_AUX, .lock_mask = PLLE_MISC_LOCK, .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE, .lock_delay = 300, .pdiv_tohw = plle_p, .div_nmp = &plle_nmp, .freq_table = pll_e_freq_table, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_HAS_LOCK_ENABLE, .fixed_rate = 100000000, }; static struct div_nmp pllre_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 16, .divp_width = 4, }; static struct tegra_clk_pll_params pll_re_vco_params = { .input_min = 12000000, .input_max = 1000000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 38 MHz */ .vco_min = 300000000, .vco_max = 600000000, .base_reg = PLLRE_BASE, .misc_reg = PLLRE_MISC, .lock_mask = PLLRE_MISC_LOCK, .lock_enable_bit_idx = PLLRE_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLRE_MISC, .iddq_bit_idx = PLLRE_IDDQ_BIT, .div_nmp = &pllre_nmp, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE | TEGRA_PLL_LOCK_MISC, }; /* possible OSC frequencies in Hz */ static unsigned long tegra114_input_freq[] = { [ 0] = 13000000, [ 1] = 16800000, [ 4] = 19200000, [ 5] = 38400000, [ 8] = 12000000, [ 9] = 48000000, [12] = 26000000, }; #define MASK(x) (BIT(x) - 1) /* peripheral mux definitions */ static const char *mux_plld_out0_plld2_out0[] = { "pll_d_out0", "pll_d2_out0", }; #define mux_plld_out0_plld2_out0_idx NULL static const char *mux_pllmcp_clkm[] = { "pll_m_out0", "pll_c_out0", "pll_p_out0", "clk_m", "pll_m_ud", }; static const struct clk_div_table pll_re_div_table[] = { { .val = 0, .div = 1 }, { .val = 1, .div = 2 }, { .val = 2, .div = 3 }, { .val = 3, .div = 4 }, { .val = 4, .div = 5 }, { .val = 5, .div = 6 }, { .val = 0, .div = 0 }, }; static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = { [tegra_clk_rtc] = { .dt_id = TEGRA114_CLK_RTC, .present = true }, [tegra_clk_timer] = { .dt_id = TEGRA114_CLK_TIMER, .present = true }, [tegra_clk_uarta] = { .dt_id = TEGRA114_CLK_UARTA, .present = true }, [tegra_clk_uartd] = { .dt_id = TEGRA114_CLK_UARTD, .present = true }, [tegra_clk_sdmmc2_8] = { .dt_id = TEGRA114_CLK_SDMMC2, .present = true }, [tegra_clk_i2s1] = { .dt_id = TEGRA114_CLK_I2S1, .present = true }, [tegra_clk_i2c1] = { .dt_id = TEGRA114_CLK_I2C1, .present = true }, [tegra_clk_ndflash] = { .dt_id = TEGRA114_CLK_NDFLASH, .present = true }, [tegra_clk_sdmmc1_8] = { .dt_id = TEGRA114_CLK_SDMMC1, .present = true }, [tegra_clk_sdmmc4_8] = { .dt_id = TEGRA114_CLK_SDMMC4, .present = true }, [tegra_clk_pwm] = { .dt_id = TEGRA114_CLK_PWM, .present = true }, [tegra_clk_i2s0] = { .dt_id = TEGRA114_CLK_I2S0, .present = true }, [tegra_clk_i2s2] = { .dt_id = TEGRA114_CLK_I2S2, .present = true }, [tegra_clk_epp_8] = { .dt_id = TEGRA114_CLK_EPP, .present = true }, [tegra_clk_gr2d_8] = { .dt_id = TEGRA114_CLK_GR2D, .present = true }, [tegra_clk_usbd] = { .dt_id = TEGRA114_CLK_USBD, .present = true }, [tegra_clk_isp] = { .dt_id = TEGRA114_CLK_ISP, .present = true }, [tegra_clk_gr3d_8] = { .dt_id = TEGRA114_CLK_GR3D, .present = true }, [tegra_clk_disp2] = { .dt_id = TEGRA114_CLK_DISP2, .present = true }, [tegra_clk_disp1] = { .dt_id = TEGRA114_CLK_DISP1, .present = true }, [tegra_clk_host1x_8] = { .dt_id = TEGRA114_CLK_HOST1X, .present = true }, [tegra_clk_vcp] = { .dt_id = TEGRA114_CLK_VCP, .present = true }, [tegra_clk_apbdma] = { .dt_id = TEGRA114_CLK_APBDMA, .present = true }, [tegra_clk_kbc] = { .dt_id = TEGRA114_CLK_KBC, .present = true }, [tegra_clk_kfuse] = { .dt_id = TEGRA114_CLK_KFUSE, .present = true }, [tegra_clk_sbc1_8] = { .dt_id = TEGRA114_CLK_SBC1, .present = true }, [tegra_clk_nor] = { .dt_id = TEGRA114_CLK_NOR, .present = true }, [tegra_clk_sbc2_8] = { .dt_id = TEGRA114_CLK_SBC2, .present = true }, [tegra_clk_sbc3_8] = { .dt_id = TEGRA114_CLK_SBC3, .present = true }, [tegra_clk_i2c5] = { .dt_id = TEGRA114_CLK_I2C5, .present = true }, [tegra_clk_mipi] = { .dt_id = TEGRA114_CLK_MIPI, .present = true }, [tegra_clk_hdmi] = { .dt_id = TEGRA114_CLK_HDMI, .present = true }, [tegra_clk_csi] = { .dt_id = TEGRA114_CLK_CSI, .present = true }, [tegra_clk_i2c2] = { .dt_id = TEGRA114_CLK_I2C2, .present = true }, [tegra_clk_uartc] = { .dt_id = TEGRA114_CLK_UARTC, .present = true }, [tegra_clk_emc] = { .dt_id = TEGRA114_CLK_EMC, .present = true }, [tegra_clk_usb2] = { .dt_id = TEGRA114_CLK_USB2, .present = true }, [tegra_clk_usb3] = { .dt_id = TEGRA114_CLK_USB3, .present = true }, [tegra_clk_vde_8] = { .dt_id = TEGRA114_CLK_VDE, .present = true }, [tegra_clk_bsea] = { .dt_id = TEGRA114_CLK_BSEA, .present = true }, [tegra_clk_bsev] = { .dt_id = TEGRA114_CLK_BSEV, .present = true }, [tegra_clk_i2c3] = { .dt_id = TEGRA114_CLK_I2C3, .present = true }, [tegra_clk_sbc4_8] = { .dt_id = TEGRA114_CLK_SBC4, .present = true }, [tegra_clk_sdmmc3_8] = { .dt_id = TEGRA114_CLK_SDMMC3, .present = true }, [tegra_clk_owr] = { .dt_id = TEGRA114_CLK_OWR, .present = true }, [tegra_clk_csite] = { .dt_id = TEGRA114_CLK_CSITE, .present = true }, [tegra_clk_la] = { .dt_id = TEGRA114_CLK_LA, .present = true }, [tegra_clk_trace] = { .dt_id = TEGRA114_CLK_TRACE, .present = true }, [tegra_clk_soc_therm] = { .dt_id = TEGRA114_CLK_SOC_THERM, .present = true }, [tegra_clk_dtv] = { .dt_id = TEGRA114_CLK_DTV, .present = true }, [tegra_clk_ndspeed] = { .dt_id = TEGRA114_CLK_NDSPEED, .present = true }, [tegra_clk_i2cslow] = { .dt_id = TEGRA114_CLK_I2CSLOW, .present = true }, [tegra_clk_tsec] = { .dt_id = TEGRA114_CLK_TSEC, .present = true }, [tegra_clk_xusb_host] = { .dt_id = TEGRA114_CLK_XUSB_HOST, .present = true }, [tegra_clk_msenc] = { .dt_id = TEGRA114_CLK_MSENC, .present = true }, [tegra_clk_csus] = { .dt_id = TEGRA114_CLK_CSUS, .present = true }, [tegra_clk_mselect] = { .dt_id = TEGRA114_CLK_MSELECT, .present = true }, [tegra_clk_tsensor] = { .dt_id = TEGRA114_CLK_TSENSOR, .present = true }, [tegra_clk_i2s3] = { .dt_id = TEGRA114_CLK_I2S3, .present = true }, [tegra_clk_i2s4] = { .dt_id = TEGRA114_CLK_I2S4, .present = true }, [tegra_clk_i2c4] = { .dt_id = TEGRA114_CLK_I2C4, .present = true }, [tegra_clk_sbc5_8] = { .dt_id = TEGRA114_CLK_SBC5, .present = true }, [tegra_clk_sbc6_8] = { .dt_id = TEGRA114_CLK_SBC6, .present = true }, [tegra_clk_d_audio] = { .dt_id = TEGRA114_CLK_D_AUDIO, .present = true }, [tegra_clk_apbif] = { .dt_id = TEGRA114_CLK_APBIF, .present = true }, [tegra_clk_dam0] = { .dt_id = TEGRA114_CLK_DAM0, .present = true }, [tegra_clk_dam1] = { .dt_id = TEGRA114_CLK_DAM1, .present = true }, [tegra_clk_dam2] = { .dt_id = TEGRA114_CLK_DAM2, .present = true }, [tegra_clk_hda2codec_2x] = { .dt_id = TEGRA114_CLK_HDA2CODEC_2X, .present = true }, [tegra_clk_audio0_2x] = { .dt_id = TEGRA114_CLK_AUDIO0_2X, .present = true }, [tegra_clk_audio1_2x] = { .dt_id = TEGRA114_CLK_AUDIO1_2X, .present = true }, [tegra_clk_audio2_2x] = { .dt_id = TEGRA114_CLK_AUDIO2_2X, .present = true }, [tegra_clk_audio3_2x] = { .dt_id = TEGRA114_CLK_AUDIO3_2X, .present = true }, [tegra_clk_audio4_2x] = { .dt_id = TEGRA114_CLK_AUDIO4_2X, .present = true }, [tegra_clk_spdif_2x] = { .dt_id = TEGRA114_CLK_SPDIF_2X, .present = true }, [tegra_clk_actmon] = { .dt_id = TEGRA114_CLK_ACTMON, .present = true }, [tegra_clk_extern1] = { .dt_id = TEGRA114_CLK_EXTERN1, .present = true }, [tegra_clk_extern2] = { .dt_id = TEGRA114_CLK_EXTERN2, .present = true }, [tegra_clk_extern3] = { .dt_id = TEGRA114_CLK_EXTERN3, .present = true }, [tegra_clk_hda] = { .dt_id = TEGRA114_CLK_HDA, .present = true }, [tegra_clk_se] = { .dt_id = TEGRA114_CLK_SE, .present = true }, [tegra_clk_hda2hdmi] = { .dt_id = TEGRA114_CLK_HDA2HDMI, .present = true }, [tegra_clk_cilab] = { .dt_id = TEGRA114_CLK_CILAB, .present = true }, [tegra_clk_cilcd] = { .dt_id = TEGRA114_CLK_CILCD, .present = true }, [tegra_clk_cile] = { .dt_id = TEGRA114_CLK_CILE, .present = true }, [tegra_clk_dsialp] = { .dt_id = TEGRA114_CLK_DSIALP, .present = true }, [tegra_clk_dsiblp] = { .dt_id = TEGRA114_CLK_DSIBLP, .present = true }, [tegra_clk_dds] = { .dt_id = TEGRA114_CLK_DDS, .present = true }, [tegra_clk_dp2] = { .dt_id = TEGRA114_CLK_DP2, .present = true }, [tegra_clk_amx] = { .dt_id = TEGRA114_CLK_AMX, .present = true }, [tegra_clk_adx] = { .dt_id = TEGRA114_CLK_ADX, .present = true }, [tegra_clk_xusb_ss] = { .dt_id = TEGRA114_CLK_XUSB_SS, .present = true }, [tegra_clk_uartb] = { .dt_id = TEGRA114_CLK_UARTB, .present = true }, [tegra_clk_vfir] = { .dt_id = TEGRA114_CLK_VFIR, .present = true }, [tegra_clk_spdif_in] = { .dt_id = TEGRA114_CLK_SPDIF_IN, .present = true }, [tegra_clk_spdif_out] = { .dt_id = TEGRA114_CLK_SPDIF_OUT, .present = true }, [tegra_clk_vi_8] = { .dt_id = TEGRA114_CLK_VI, .present = true }, [tegra_clk_fuse] = { .dt_id = TEGRA114_CLK_FUSE, .present = true }, [tegra_clk_fuse_burn] = { .dt_id = TEGRA114_CLK_FUSE_BURN, .present = true }, [tegra_clk_clk_32k] = { .dt_id = TEGRA114_CLK_CLK_32K, .present = true }, [tegra_clk_clk_m] = { .dt_id = TEGRA114_CLK_CLK_M, .present = true }, [tegra_clk_osc] = { .dt_id = TEGRA114_CLK_OSC, .present = true }, [tegra_clk_osc_div2] = { .dt_id = TEGRA114_CLK_OSC_DIV2, .present = true }, [tegra_clk_osc_div4] = { .dt_id = TEGRA114_CLK_OSC_DIV4, .present = true }, [tegra_clk_pll_ref] = { .dt_id = TEGRA114_CLK_PLL_REF, .present = true }, [tegra_clk_pll_c] = { .dt_id = TEGRA114_CLK_PLL_C, .present = true }, [tegra_clk_pll_c_out1] = { .dt_id = TEGRA114_CLK_PLL_C_OUT1, .present = true }, [tegra_clk_pll_c2] = { .dt_id = TEGRA114_CLK_PLL_C2, .present = true }, [tegra_clk_pll_c3] = { .dt_id = TEGRA114_CLK_PLL_C3, .present = true }, [tegra_clk_pll_m] = { .dt_id = TEGRA114_CLK_PLL_M, .present = true }, [tegra_clk_pll_m_out1] = { .dt_id = TEGRA114_CLK_PLL_M_OUT1, .present = true }, [tegra_clk_pll_p] = { .dt_id = TEGRA114_CLK_PLL_P, .present = true }, [tegra_clk_pll_p_out1] = { .dt_id = TEGRA114_CLK_PLL_P_OUT1, .present = true }, [tegra_clk_pll_p_out2_int] = { .dt_id = TEGRA114_CLK_PLL_P_OUT2, .present = true }, [tegra_clk_pll_p_out3] = { .dt_id = TEGRA114_CLK_PLL_P_OUT3, .present = true }, [tegra_clk_pll_p_out4] = { .dt_id = TEGRA114_CLK_PLL_P_OUT4, .present = true }, [tegra_clk_pll_a] = { .dt_id = TEGRA114_CLK_PLL_A, .present = true }, [tegra_clk_pll_a_out0] = { .dt_id = TEGRA114_CLK_PLL_A_OUT0, .present = true }, [tegra_clk_pll_d] = { .dt_id = TEGRA114_CLK_PLL_D, .present = true }, [tegra_clk_pll_d_out0] = { .dt_id = TEGRA114_CLK_PLL_D_OUT0, .present = true }, [tegra_clk_pll_d2] = { .dt_id = TEGRA114_CLK_PLL_D2, .present = true }, [tegra_clk_pll_d2_out0] = { .dt_id = TEGRA114_CLK_PLL_D2_OUT0, .present = true }, [tegra_clk_pll_u] = { .dt_id = TEGRA114_CLK_PLL_U, .present = true }, [tegra_clk_pll_u_480m] = { .dt_id = TEGRA114_CLK_PLL_U_480M, .present = true }, [tegra_clk_pll_u_60m] = { .dt_id = TEGRA114_CLK_PLL_U_60M, .present = true }, [tegra_clk_pll_u_48m] = { .dt_id = TEGRA114_CLK_PLL_U_48M, .present = true }, [tegra_clk_pll_u_12m] = { .dt_id = TEGRA114_CLK_PLL_U_12M, .present = true }, [tegra_clk_pll_x] = { .dt_id = TEGRA114_CLK_PLL_X, .present = true }, [tegra_clk_pll_x_out0] = { .dt_id = TEGRA114_CLK_PLL_X_OUT0, .present = true }, [tegra_clk_pll_re_vco] = { .dt_id = TEGRA114_CLK_PLL_RE_VCO, .present = true }, [tegra_clk_pll_re_out] = { .dt_id = TEGRA114_CLK_PLL_RE_OUT, .present = true }, [tegra_clk_pll_e_out0] = { .dt_id = TEGRA114_CLK_PLL_E_OUT0, .present = true }, [tegra_clk_spdif_in_sync] = { .dt_id = TEGRA114_CLK_SPDIF_IN_SYNC, .present = true }, [tegra_clk_i2s0_sync] = { .dt_id = TEGRA114_CLK_I2S0_SYNC, .present = true }, [tegra_clk_i2s1_sync] = { .dt_id = TEGRA114_CLK_I2S1_SYNC, .present = true }, [tegra_clk_i2s2_sync] = { .dt_id = TEGRA114_CLK_I2S2_SYNC, .present = true }, [tegra_clk_i2s3_sync] = { .dt_id = TEGRA114_CLK_I2S3_SYNC, .present = true }, [tegra_clk_i2s4_sync] = { .dt_id = TEGRA114_CLK_I2S4_SYNC, .present = true }, [tegra_clk_vimclk_sync] = { .dt_id = TEGRA114_CLK_VIMCLK_SYNC, .present = true }, [tegra_clk_audio0] = { .dt_id = TEGRA114_CLK_AUDIO0, .present = true }, [tegra_clk_audio1] = { .dt_id = TEGRA114_CLK_AUDIO1, .present = true }, [tegra_clk_audio2] = { .dt_id = TEGRA114_CLK_AUDIO2, .present = true }, [tegra_clk_audio3] = { .dt_id = TEGRA114_CLK_AUDIO3, .present = true }, [tegra_clk_audio4] = { .dt_id = TEGRA114_CLK_AUDIO4, .present = true }, [tegra_clk_spdif] = { .dt_id = TEGRA114_CLK_SPDIF, .present = true }, [tegra_clk_xusb_host_src] = { .dt_id = TEGRA114_CLK_XUSB_HOST_SRC, .present = true }, [tegra_clk_xusb_falcon_src] = { .dt_id = TEGRA114_CLK_XUSB_FALCON_SRC, .present = true }, [tegra_clk_xusb_fs_src] = { .dt_id = TEGRA114_CLK_XUSB_FS_SRC, .present = true }, [tegra_clk_xusb_ss_src] = { .dt_id = TEGRA114_CLK_XUSB_SS_SRC, .present = true }, [tegra_clk_xusb_ss_div2] = { .dt_id = TEGRA114_CLK_XUSB_SS_DIV2, .present = true}, [tegra_clk_xusb_dev_src] = { .dt_id = TEGRA114_CLK_XUSB_DEV_SRC, .present = true }, [tegra_clk_xusb_dev] = { .dt_id = TEGRA114_CLK_XUSB_DEV, .present = true }, [tegra_clk_xusb_hs_src] = { .dt_id = TEGRA114_CLK_XUSB_HS_SRC, .present = true }, [tegra_clk_sclk] = { .dt_id = TEGRA114_CLK_SCLK, .present = true }, [tegra_clk_hclk] = { .dt_id = TEGRA114_CLK_HCLK, .present = true }, [tegra_clk_pclk] = { .dt_id = TEGRA114_CLK_PCLK, .present = true }, [tegra_clk_cclk_g] = { .dt_id = TEGRA114_CLK_CCLK_G, .present = true }, [tegra_clk_cclk_lp] = { .dt_id = TEGRA114_CLK_CCLK_LP, .present = true }, [tegra_clk_dfll_ref] = { .dt_id = TEGRA114_CLK_DFLL_REF, .present = true }, [tegra_clk_dfll_soc] = { .dt_id = TEGRA114_CLK_DFLL_SOC, .present = true }, [tegra_clk_audio0_mux] = { .dt_id = TEGRA114_CLK_AUDIO0_MUX, .present = true }, [tegra_clk_audio1_mux] = { .dt_id = TEGRA114_CLK_AUDIO1_MUX, .present = true }, [tegra_clk_audio2_mux] = { .dt_id = TEGRA114_CLK_AUDIO2_MUX, .present = true }, [tegra_clk_audio3_mux] = { .dt_id = TEGRA114_CLK_AUDIO3_MUX, .present = true }, [tegra_clk_audio4_mux] = { .dt_id = TEGRA114_CLK_AUDIO4_MUX, .present = true }, [tegra_clk_spdif_mux] = { .dt_id = TEGRA114_CLK_SPDIF_MUX, .present = true }, [tegra_clk_dsia_mux] = { .dt_id = TEGRA114_CLK_DSIA_MUX, .present = true }, [tegra_clk_dsib_mux] = { .dt_id = TEGRA114_CLK_DSIB_MUX, .present = true }, [tegra_clk_cec] = { .dt_id = TEGRA114_CLK_CEC, .present = true }, }; static struct tegra_devclk devclks[] __initdata = { { .con_id = "clk_m", .dt_id = TEGRA114_CLK_CLK_M }, { .con_id = "pll_ref", .dt_id = TEGRA114_CLK_PLL_REF }, { .con_id = "clk_32k", .dt_id = TEGRA114_CLK_CLK_32K }, { .con_id = "osc", .dt_id = TEGRA114_CLK_OSC }, { .con_id = "osc_div2", .dt_id = TEGRA114_CLK_OSC_DIV2 }, { .con_id = "osc_div4", .dt_id = TEGRA114_CLK_OSC_DIV4 }, { .con_id = "pll_c", .dt_id = TEGRA114_CLK_PLL_C }, { .con_id = "pll_c_out1", .dt_id = TEGRA114_CLK_PLL_C_OUT1 }, { .con_id = "pll_c2", .dt_id = TEGRA114_CLK_PLL_C2 }, { .con_id = "pll_c3", .dt_id = TEGRA114_CLK_PLL_C3 }, { .con_id = "pll_p", .dt_id = TEGRA114_CLK_PLL_P }, { .con_id = "pll_p_out1", .dt_id = TEGRA114_CLK_PLL_P_OUT1 }, { .con_id = "pll_p_out2", .dt_id = TEGRA114_CLK_PLL_P_OUT2 }, { .con_id = "pll_p_out3", .dt_id = TEGRA114_CLK_PLL_P_OUT3 }, { .con_id = "pll_p_out4", .dt_id = TEGRA114_CLK_PLL_P_OUT4 }, { .con_id = "pll_m", .dt_id = TEGRA114_CLK_PLL_M }, { .con_id = "pll_m_out1", .dt_id = TEGRA114_CLK_PLL_M_OUT1 }, { .con_id = "pll_x", .dt_id = TEGRA114_CLK_PLL_X }, { .con_id = "pll_x_out0", .dt_id = TEGRA114_CLK_PLL_X_OUT0 }, { .con_id = "pll_u", .dt_id = TEGRA114_CLK_PLL_U }, { .con_id = "pll_u_480M", .dt_id = TEGRA114_CLK_PLL_U_480M }, { .con_id = "pll_u_60M", .dt_id = TEGRA114_CLK_PLL_U_60M }, { .con_id = "pll_u_48M", .dt_id = TEGRA114_CLK_PLL_U_48M }, { .con_id = "pll_u_12M", .dt_id = TEGRA114_CLK_PLL_U_12M }, { .con_id = "pll_d", .dt_id = TEGRA114_CLK_PLL_D }, { .con_id = "pll_d_out0", .dt_id = TEGRA114_CLK_PLL_D_OUT0 }, { .con_id = "pll_d2", .dt_id = TEGRA114_CLK_PLL_D2 }, { .con_id = "pll_d2_out0", .dt_id = TEGRA114_CLK_PLL_D2_OUT0 }, { .con_id = "pll_a", .dt_id = TEGRA114_CLK_PLL_A }, { .con_id = "pll_a_out0", .dt_id = TEGRA114_CLK_PLL_A_OUT0 }, { .con_id = "pll_re_vco", .dt_id = TEGRA114_CLK_PLL_RE_VCO }, { .con_id = "pll_re_out", .dt_id = TEGRA114_CLK_PLL_RE_OUT }, { .con_id = "pll_e_out0", .dt_id = TEGRA114_CLK_PLL_E_OUT0 }, { .con_id = "spdif_in_sync", .dt_id = TEGRA114_CLK_SPDIF_IN_SYNC }, { .con_id = "i2s0_sync", .dt_id = TEGRA114_CLK_I2S0_SYNC }, { .con_id = "i2s1_sync", .dt_id = TEGRA114_CLK_I2S1_SYNC }, { .con_id = "i2s2_sync", .dt_id = TEGRA114_CLK_I2S2_SYNC }, { .con_id = "i2s3_sync", .dt_id = TEGRA114_CLK_I2S3_SYNC }, { .con_id = "i2s4_sync", .dt_id = TEGRA114_CLK_I2S4_SYNC }, { .con_id = "vimclk_sync", .dt_id = TEGRA114_CLK_VIMCLK_SYNC }, { .con_id = "audio0", .dt_id = TEGRA114_CLK_AUDIO0 }, { .con_id = "audio1", .dt_id = TEGRA114_CLK_AUDIO1 }, { .con_id = "audio2", .dt_id = TEGRA114_CLK_AUDIO2 }, { .con_id = "audio3", .dt_id = TEGRA114_CLK_AUDIO3 }, { .con_id = "audio4", .dt_id = TEGRA114_CLK_AUDIO4 }, { .con_id = "spdif", .dt_id = TEGRA114_CLK_SPDIF }, { .con_id = "audio0_2x", .dt_id = TEGRA114_CLK_AUDIO0_2X }, { .con_id = "audio1_2x", .dt_id = TEGRA114_CLK_AUDIO1_2X }, { .con_id = "audio2_2x", .dt_id = TEGRA114_CLK_AUDIO2_2X }, { .con_id = "audio3_2x", .dt_id = TEGRA114_CLK_AUDIO3_2X }, { .con_id = "audio4_2x", .dt_id = TEGRA114_CLK_AUDIO4_2X }, { .con_id = "spdif_2x", .dt_id = TEGRA114_CLK_SPDIF_2X }, { .con_id = "extern1", .dt_id = TEGRA114_CLK_EXTERN1 }, { .con_id = "extern2", .dt_id = TEGRA114_CLK_EXTERN2 }, { .con_id = "extern3", .dt_id = TEGRA114_CLK_EXTERN3 }, { .con_id = "cclk_g", .dt_id = TEGRA114_CLK_CCLK_G }, { .con_id = "cclk_lp", .dt_id = TEGRA114_CLK_CCLK_LP }, { .con_id = "sclk", .dt_id = TEGRA114_CLK_SCLK }, { .con_id = "hclk", .dt_id = TEGRA114_CLK_HCLK }, { .con_id = "pclk", .dt_id = TEGRA114_CLK_PCLK }, { .con_id = "fuse", .dt_id = TEGRA114_CLK_FUSE }, { .dev_id = "rtc-tegra", .dt_id = TEGRA114_CLK_RTC }, { .dev_id = "timer", .dt_id = TEGRA114_CLK_TIMER }, }; static const char *mux_pllm_pllc2_c_c3_pllp_plla[] = { "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0" }; static u32 mux_pllm_pllc2_c_c3_pllp_plla_idx[] = { [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 6, }; static struct tegra_audio_clk_info tegra114_audio_plls[] = { { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_p_out1" }, }; static struct clk **clks; static unsigned long osc_freq; static unsigned long pll_ref_freq; static void __init tegra114_fixed_clk_init(void __iomem *clk_base) { struct clk *clk; /* clk_32k */ clk = clk_register_fixed_rate(NULL, "clk_32k", NULL, 0, 32768); clks[TEGRA114_CLK_CLK_32K] = clk; } static void __init tegra114_pll_init(void __iomem *clk_base, void __iomem *pmc) { struct clk *clk; /* PLLC */ clk = tegra_clk_register_pllxc("pll_c", "pll_ref", clk_base, pmc, 0, &pll_c_params, NULL); clks[TEGRA114_CLK_PLL_C] = clk; /* PLLC_OUT1 */ clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c", clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div", clk_base + PLLC_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clks[TEGRA114_CLK_PLL_C_OUT1] = clk; /* PLLC2 */ clk = tegra_clk_register_pllc("pll_c2", "pll_ref", clk_base, pmc, 0, &pll_c2_params, NULL); clks[TEGRA114_CLK_PLL_C2] = clk; /* PLLC3 */ clk = tegra_clk_register_pllc("pll_c3", "pll_ref", clk_base, pmc, 0, &pll_c3_params, NULL); clks[TEGRA114_CLK_PLL_C3] = clk; /* PLLM */ clk = tegra_clk_register_pllm("pll_m", "pll_ref", clk_base, pmc, CLK_SET_RATE_GATE, &pll_m_params, NULL); clks[TEGRA114_CLK_PLL_M] = clk; /* PLLM_OUT1 */ clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m", clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div", clk_base + PLLM_OUT, 1, 0, CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0, NULL); clks[TEGRA114_CLK_PLL_M_OUT1] = clk; /* PLLM_UD */ clk = clk_register_fixed_factor(NULL, "pll_m_ud", "pll_m", CLK_SET_RATE_PARENT, 1, 1); /* PLLU */ clk = tegra_clk_register_pllu_tegra114("pll_u", "pll_ref", clk_base, 0, &pll_u_params, &pll_u_lock); clks[TEGRA114_CLK_PLL_U] = clk; /* PLLU_480M */ clk = clk_register_gate(NULL, "pll_u_480M", "pll_u", CLK_SET_RATE_PARENT, clk_base + PLLU_BASE, 22, 0, &pll_u_lock); clks[TEGRA114_CLK_PLL_U_480M] = clk; /* PLLU_60M */ clk = clk_register_fixed_factor(NULL, "pll_u_60M", "pll_u", CLK_SET_RATE_PARENT, 1, 8); clks[TEGRA114_CLK_PLL_U_60M] = clk; /* PLLU_48M */ clk = clk_register_fixed_factor(NULL, "pll_u_48M", "pll_u", CLK_SET_RATE_PARENT, 1, 10); clks[TEGRA114_CLK_PLL_U_48M] = clk; /* PLLU_12M */ clk = clk_register_fixed_factor(NULL, "pll_u_12M", "pll_u", CLK_SET_RATE_PARENT, 1, 40); clks[TEGRA114_CLK_PLL_U_12M] = clk; /* PLLD */ clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc, 0, &pll_d_params, &pll_d_lock); clks[TEGRA114_CLK_PLL_D] = clk; /* PLLD_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d", CLK_SET_RATE_PARENT, 1, 2); clks[TEGRA114_CLK_PLL_D_OUT0] = clk; /* PLLD2 */ clk = tegra_clk_register_pll("pll_d2", "pll_ref", clk_base, pmc, 0, &pll_d2_params, &pll_d2_lock); clks[TEGRA114_CLK_PLL_D2] = clk; /* PLLD2_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2", CLK_SET_RATE_PARENT, 1, 2); clks[TEGRA114_CLK_PLL_D2_OUT0] = clk; /* PLLRE */ clk = tegra_clk_register_pllre("pll_re_vco", "pll_ref", clk_base, pmc, 0, &pll_re_vco_params, &pll_re_lock, pll_ref_freq); clks[TEGRA114_CLK_PLL_RE_VCO] = clk; clk = clk_register_divider_table(NULL, "pll_re_out", "pll_re_vco", 0, clk_base + PLLRE_BASE, 16, 4, 0, pll_re_div_table, &pll_re_lock); clks[TEGRA114_CLK_PLL_RE_OUT] = clk; /* PLLE */ clk = tegra_clk_register_plle_tegra114("pll_e_out0", "pll_ref", clk_base, 0, &pll_e_params, NULL); clks[TEGRA114_CLK_PLL_E_OUT0] = clk; } #define CLK_SOURCE_VI_SENSOR 0x1a8 static struct tegra_periph_init_data tegra_periph_clk_list[] = { MUX8("vi_sensor", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR, 20, TEGRA_PERIPH_NO_RESET, TEGRA114_CLK_VI_SENSOR), }; static __init void tegra114_periph_clk_init(void __iomem *clk_base, void __iomem *pmc_base) { struct clk *clk; struct tegra_periph_init_data *data; unsigned int i; /* xusb_ss_div2 */ clk = clk_register_fixed_factor(NULL, "xusb_ss_div2", "xusb_ss_src", 0, 1, 2); clks[TEGRA114_CLK_XUSB_SS_DIV2] = clk; /* dsia mux */ clk = clk_register_mux(NULL, "dsia_mux", mux_plld_out0_plld2_out0, ARRAY_SIZE(mux_plld_out0_plld2_out0), CLK_SET_RATE_NO_REPARENT, clk_base + PLLD_BASE, 25, 1, 0, &pll_d_lock); clks[TEGRA114_CLK_DSIA_MUX] = clk; /* dsib mux */ clk = clk_register_mux(NULL, "dsib_mux", mux_plld_out0_plld2_out0, ARRAY_SIZE(mux_plld_out0_plld2_out0), CLK_SET_RATE_NO_REPARENT, clk_base + PLLD2_BASE, 25, 1, 0, &pll_d2_lock); clks[TEGRA114_CLK_DSIB_MUX] = clk; clk = tegra_clk_register_periph_gate("dsia", "dsia_mux", 0, clk_base, 0, 48, periph_clk_enb_refcnt); clks[TEGRA114_CLK_DSIA] = clk; clk = tegra_clk_register_periph_gate("dsib", "dsib_mux", 0, clk_base, 0, 82, periph_clk_enb_refcnt); clks[TEGRA114_CLK_DSIB] = clk; /* emc mux */ clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm, ARRAY_SIZE(mux_pllmcp_clkm), CLK_SET_RATE_NO_REPARENT, clk_base + CLK_SOURCE_EMC, 29, 3, 0, &emc_lock); clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC, &emc_lock); clks[TEGRA114_CLK_MC] = clk; clk = tegra_clk_register_periph_gate("mipi-cal", "clk_m", 0, clk_base, CLK_SET_RATE_PARENT, 56, periph_clk_enb_refcnt); clks[TEGRA114_CLK_MIPI_CAL] = clk; for (i = 0; i < ARRAY_SIZE(tegra_periph_clk_list); i++) { data = &tegra_periph_clk_list[i]; clk = tegra_clk_register_periph_data(clk_base, data); clks[data->clk_id] = clk; } tegra_periph_clk_init(clk_base, pmc_base, tegra114_clks, &pll_p_params); } /* Tegra114 CPU clock and reset control functions */ static void tegra114_wait_cpu_in_reset(u32 cpu) { unsigned int reg; do { reg = readl(clk_base + CLK_RST_CONTROLLER_CPU_CMPLX_STATUS); cpu_relax(); } while (!(reg & (1 << cpu))); /* check CPU been reset or not */ } static void tegra114_disable_cpu_clock(u32 cpu) { /* flow controller would take care in the power sequence. */ } #ifdef CONFIG_PM_SLEEP static void tegra114_cpu_clock_suspend(void) { /* switch coresite to clk_m, save off original source */ tegra114_cpu_clk_sctx.clk_csite_src = readl(clk_base + CLK_SOURCE_CSITE); writel(3 << 30, clk_base + CLK_SOURCE_CSITE); tegra114_cpu_clk_sctx.cclkg_burst = readl(clk_base + CCLKG_BURST_POLICY); tegra114_cpu_clk_sctx.cclkg_divider = readl(clk_base + CCLKG_BURST_POLICY + 4); } static void tegra114_cpu_clock_resume(void) { writel(tegra114_cpu_clk_sctx.clk_csite_src, clk_base + CLK_SOURCE_CSITE); writel(tegra114_cpu_clk_sctx.cclkg_burst, clk_base + CCLKG_BURST_POLICY); writel(tegra114_cpu_clk_sctx.cclkg_divider, clk_base + CCLKG_BURST_POLICY + 4); } #endif static struct tegra_cpu_car_ops tegra114_cpu_car_ops = { .wait_for_reset = tegra114_wait_cpu_in_reset, .disable_clock = tegra114_disable_cpu_clock, #ifdef CONFIG_PM_SLEEP .suspend = tegra114_cpu_clock_suspend, .resume = tegra114_cpu_clock_resume, #endif }; static const struct of_device_id pmc_match[] __initconst = { { .compatible = "nvidia,tegra114-pmc" }, { }, }; /* * dfll_soc/dfll_ref apparently must be kept enabled, otherwise I2C5 * breaks */ static struct tegra_clk_init_table init_table[] __initdata = { { TEGRA114_CLK_UARTA, TEGRA114_CLK_PLL_P, 408000000, 0 }, { TEGRA114_CLK_UARTB, TEGRA114_CLK_PLL_P, 408000000, 0 }, { TEGRA114_CLK_UARTC, TEGRA114_CLK_PLL_P, 408000000, 0 }, { TEGRA114_CLK_UARTD, TEGRA114_CLK_PLL_P, 408000000, 0 }, { TEGRA114_CLK_PLL_A, TEGRA114_CLK_CLK_MAX, 564480000, 0 }, { TEGRA114_CLK_PLL_A_OUT0, TEGRA114_CLK_CLK_MAX, 11289600, 0 }, { TEGRA114_CLK_I2S0, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA114_CLK_I2S1, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA114_CLK_I2S2, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA114_CLK_I2S3, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA114_CLK_I2S4, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA114_CLK_HOST1X, TEGRA114_CLK_PLL_P, 136000000, 0 }, { TEGRA114_CLK_DFLL_SOC, TEGRA114_CLK_PLL_P, 51000000, 1 }, { TEGRA114_CLK_DFLL_REF, TEGRA114_CLK_PLL_P, 51000000, 1 }, { TEGRA114_CLK_DISP1, TEGRA114_CLK_PLL_P, 0, 0 }, { TEGRA114_CLK_DISP2, TEGRA114_CLK_PLL_P, 0, 0 }, { TEGRA114_CLK_GR2D, TEGRA114_CLK_PLL_C2, 300000000, 0 }, { TEGRA114_CLK_GR3D, TEGRA114_CLK_PLL_C2, 300000000, 0 }, { TEGRA114_CLK_DSIALP, TEGRA114_CLK_PLL_P, 68000000, 0 }, { TEGRA114_CLK_DSIBLP, TEGRA114_CLK_PLL_P, 68000000, 0 }, { TEGRA114_CLK_PLL_RE_VCO, TEGRA114_CLK_CLK_MAX, 612000000, 0 }, { TEGRA114_CLK_XUSB_SS_SRC, TEGRA114_CLK_PLL_RE_OUT, 122400000, 0 }, { TEGRA114_CLK_XUSB_FS_SRC, TEGRA114_CLK_PLL_U_48M, 48000000, 0 }, { TEGRA114_CLK_XUSB_HS_SRC, TEGRA114_CLK_XUSB_SS_DIV2, 61200000, 0 }, { TEGRA114_CLK_XUSB_FALCON_SRC, TEGRA114_CLK_PLL_P, 204000000, 0 }, { TEGRA114_CLK_XUSB_HOST_SRC, TEGRA114_CLK_PLL_P, 102000000, 0 }, { TEGRA114_CLK_VDE, TEGRA114_CLK_PLL_P, 408000000, 0 }, { TEGRA114_CLK_SPDIF_IN_SYNC, TEGRA114_CLK_CLK_MAX, 24000000, 0 }, { TEGRA114_CLK_I2S0_SYNC, TEGRA114_CLK_CLK_MAX, 24000000, 0 }, { TEGRA114_CLK_I2S1_SYNC, TEGRA114_CLK_CLK_MAX, 24000000, 0 }, { TEGRA114_CLK_I2S2_SYNC, TEGRA114_CLK_CLK_MAX, 24000000, 0 }, { TEGRA114_CLK_I2S3_SYNC, TEGRA114_CLK_CLK_MAX, 24000000, 0 }, { TEGRA114_CLK_I2S4_SYNC, TEGRA114_CLK_CLK_MAX, 24000000, 0 }, { TEGRA114_CLK_VIMCLK_SYNC, TEGRA114_CLK_CLK_MAX, 24000000, 0 }, { TEGRA114_CLK_PWM, TEGRA114_CLK_PLL_P, 408000000, 0 }, /* must be the last entry */ { TEGRA114_CLK_CLK_MAX, TEGRA114_CLK_CLK_MAX, 0, 0 }, }; static void __init tegra114_clock_apply_init_table(void) { tegra_init_from_table(init_table, clks, TEGRA114_CLK_CLK_MAX); } /** * tegra114_car_barrier - wait for pending writes to the CAR to complete * * Wait for any outstanding writes to the CAR MMIO space from this CPU * to complete before continuing execution. No return value. */ static void tegra114_car_barrier(void) { wmb(); /* probably unnecessary */ readl_relaxed(clk_base + CPU_FINETRIM_SELECT); } /** * tegra114_clock_tune_cpu_trimmers_high - use high-voltage propagation delays * * When the CPU rail voltage is in the high-voltage range, use the * built-in hardwired clock propagation delays in the CPU clock * shaper. No return value. */ void tegra114_clock_tune_cpu_trimmers_high(void) { u32 select = 0; /* Use hardwired rise->rise & fall->fall clock propagation delays */ select |= ~(CPU_FINETRIM_1_FCPU_1 | CPU_FINETRIM_1_FCPU_2 | CPU_FINETRIM_1_FCPU_3 | CPU_FINETRIM_1_FCPU_4 | CPU_FINETRIM_1_FCPU_5 | CPU_FINETRIM_1_FCPU_6); writel_relaxed(select, clk_base + CPU_FINETRIM_SELECT); tegra114_car_barrier(); } EXPORT_SYMBOL(tegra114_clock_tune_cpu_trimmers_high); /** * tegra114_clock_tune_cpu_trimmers_low - use low-voltage propagation delays * * When the CPU rail voltage is in the low-voltage range, use the * extended clock propagation delays set by * tegra114_clock_tune_cpu_trimmers_init(). The intention is to * maintain the input clock duty cycle that the FCPU subsystem * expects. No return value. */ void tegra114_clock_tune_cpu_trimmers_low(void) { u32 select = 0; /* * Use software-specified rise->rise & fall->fall clock * propagation delays (from * tegra114_clock_tune_cpu_trimmers_init() */ select |= (CPU_FINETRIM_1_FCPU_1 | CPU_FINETRIM_1_FCPU_2 | CPU_FINETRIM_1_FCPU_3 | CPU_FINETRIM_1_FCPU_4 | CPU_FINETRIM_1_FCPU_5 | CPU_FINETRIM_1_FCPU_6); writel_relaxed(select, clk_base + CPU_FINETRIM_SELECT); tegra114_car_barrier(); } EXPORT_SYMBOL(tegra114_clock_tune_cpu_trimmers_low); /** * tegra114_clock_tune_cpu_trimmers_init - set up and enable clk prop delays * * Program extended clock propagation delays into the FCPU clock * shaper and enable them. XXX Define the purpose - peak current * reduction? No return value. */ /* XXX Initial voltage rail state assumption issues? */ void tegra114_clock_tune_cpu_trimmers_init(void) { u32 dr = 0, r = 0; /* Increment the rise->rise clock delay by four steps */ r |= (CPU_FINETRIM_R_FCPU_1_MASK | CPU_FINETRIM_R_FCPU_2_MASK | CPU_FINETRIM_R_FCPU_3_MASK | CPU_FINETRIM_R_FCPU_4_MASK | CPU_FINETRIM_R_FCPU_5_MASK | CPU_FINETRIM_R_FCPU_6_MASK); writel_relaxed(r, clk_base + CPU_FINETRIM_R); /* * Use the rise->rise clock propagation delay specified in the * r field */ dr |= (CPU_FINETRIM_1_FCPU_1 | CPU_FINETRIM_1_FCPU_2 | CPU_FINETRIM_1_FCPU_3 | CPU_FINETRIM_1_FCPU_4 | CPU_FINETRIM_1_FCPU_5 | CPU_FINETRIM_1_FCPU_6); writel_relaxed(dr, clk_base + CPU_FINETRIM_DR); tegra114_clock_tune_cpu_trimmers_low(); } EXPORT_SYMBOL(tegra114_clock_tune_cpu_trimmers_init); /** * tegra114_clock_assert_dfll_dvco_reset - assert the DFLL's DVCO reset * * Assert the reset line of the DFLL's DVCO. No return value. */ void tegra114_clock_assert_dfll_dvco_reset(void) { u32 v; v = readl_relaxed(clk_base + RST_DFLL_DVCO); v |= (1 << DVFS_DFLL_RESET_SHIFT); writel_relaxed(v, clk_base + RST_DFLL_DVCO); tegra114_car_barrier(); } EXPORT_SYMBOL(tegra114_clock_assert_dfll_dvco_reset); /** * tegra114_clock_deassert_dfll_dvco_reset - deassert the DFLL's DVCO reset * * Deassert the reset line of the DFLL's DVCO, allowing the DVCO to * operate. No return value. */ void tegra114_clock_deassert_dfll_dvco_reset(void) { u32 v; v = readl_relaxed(clk_base + RST_DFLL_DVCO); v &= ~(1 << DVFS_DFLL_RESET_SHIFT); writel_relaxed(v, clk_base + RST_DFLL_DVCO); tegra114_car_barrier(); } EXPORT_SYMBOL(tegra114_clock_deassert_dfll_dvco_reset); static void __init tegra114_clock_init(struct device_node *np) { struct device_node *node; clk_base = of_iomap(np, 0); if (!clk_base) { pr_err("ioremap tegra114 CAR failed\n"); return; } node = of_find_matching_node(NULL, pmc_match); if (!node) { pr_err("Failed to find pmc node\n"); WARN_ON(1); return; } pmc_base = of_iomap(node, 0); of_node_put(node); if (!pmc_base) { pr_err("Can't map pmc registers\n"); WARN_ON(1); return; } clks = tegra_clk_init(clk_base, TEGRA114_CLK_CLK_MAX, TEGRA114_CLK_PERIPH_BANKS); if (!clks) return; if (tegra_osc_clk_init(clk_base, tegra114_clks, tegra114_input_freq, ARRAY_SIZE(tegra114_input_freq), 1, &osc_freq, &pll_ref_freq) < 0) return; tegra114_fixed_clk_init(clk_base); tegra114_pll_init(clk_base, pmc_base); tegra114_periph_clk_init(clk_base, pmc_base); tegra_audio_clk_init(clk_base, pmc_base, tegra114_clks, tegra114_audio_plls, ARRAY_SIZE(tegra114_audio_plls), 24000000); tegra_super_clk_gen4_init(clk_base, pmc_base, tegra114_clks, &pll_x_params); tegra_add_of_provider(np, of_clk_src_onecell_get); tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); tegra_clk_apply_init_table = tegra114_clock_apply_init_table; tegra_cpu_car_ops = &tegra114_cpu_car_ops; } CLK_OF_DECLARE(tegra114, "nvidia,tegra114-car", tegra114_clock_init);
linux-master
drivers/clk/tegra/clk-tegra114.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/clk-provider.h> #include <linux/slab.h> #include <linux/err.h> #include "clk.h" static unsigned long clk_sync_source_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_sync_source *sync = to_clk_sync_source(hw); return sync->rate; } static long clk_sync_source_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct tegra_clk_sync_source *sync = to_clk_sync_source(hw); if (rate > sync->max_rate) return -EINVAL; else return rate; } static int clk_sync_source_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_sync_source *sync = to_clk_sync_source(hw); sync->rate = rate; return 0; } const struct clk_ops tegra_clk_sync_source_ops = { .round_rate = clk_sync_source_round_rate, .set_rate = clk_sync_source_set_rate, .recalc_rate = clk_sync_source_recalc_rate, }; struct clk *tegra_clk_register_sync_source(const char *name, unsigned long max_rate) { struct tegra_clk_sync_source *sync; struct clk_init_data init; struct clk *clk; sync = kzalloc(sizeof(*sync), GFP_KERNEL); if (!sync) { pr_err("%s: could not allocate sync source clk\n", __func__); return ERR_PTR(-ENOMEM); } sync->max_rate = max_rate; init.ops = &tegra_clk_sync_source_ops; init.name = name; init.flags = 0; init.parent_names = NULL; init.num_parents = 0; /* Data in .init is copied by clk_register(), so stack variable OK */ sync->hw.init = &init; clk = clk_register(NULL, &sync->hw); if (IS_ERR(clk)) kfree(sync); return clk; }
linux-master
drivers/clk/tegra/clk-audio-sync.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012-2020 NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/clkdev.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/syscore_ops.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/mutex.h> #include <linux/clk/tegra.h> #include <dt-bindings/clock/tegra210-car.h> #include <dt-bindings/reset/tegra210-car.h> #include <linux/sizes.h> #include <soc/tegra/pmc.h> #include "clk.h" #include "clk-id.h" /* * TEGRA210_CAR_BANK_COUNT: the number of peripheral clock register * banks present in the Tegra210 CAR IP block. The banks are * identified by single letters, e.g.: L, H, U, V, W, X, Y. See * periph_regs[] in drivers/clk/tegra/clk.c */ #define TEGRA210_CAR_BANK_COUNT 7 #define CLK_SOURCE_CSITE 0x1d4 #define CLK_SOURCE_EMC 0x19c #define CLK_SOURCE_SOR1 0x410 #define CLK_SOURCE_SOR0 0x414 #define CLK_SOURCE_LA 0x1f8 #define CLK_SOURCE_SDMMC2 0x154 #define CLK_SOURCE_SDMMC4 0x164 #define CLK_SOURCE_EMC_DLL 0x664 #define PLLC_BASE 0x80 #define PLLC_OUT 0x84 #define PLLC_MISC0 0x88 #define PLLC_MISC1 0x8c #define PLLC_MISC2 0x5d0 #define PLLC_MISC3 0x5d4 #define PLLC2_BASE 0x4e8 #define PLLC2_MISC0 0x4ec #define PLLC2_MISC1 0x4f0 #define PLLC2_MISC2 0x4f4 #define PLLC2_MISC3 0x4f8 #define PLLC3_BASE 0x4fc #define PLLC3_MISC0 0x500 #define PLLC3_MISC1 0x504 #define PLLC3_MISC2 0x508 #define PLLC3_MISC3 0x50c #define PLLM_BASE 0x90 #define PLLM_MISC1 0x98 #define PLLM_MISC2 0x9c #define PLLP_BASE 0xa0 #define PLLP_MISC0 0xac #define PLLP_MISC1 0x680 #define PLLA_BASE 0xb0 #define PLLA_MISC0 0xbc #define PLLA_MISC1 0xb8 #define PLLA_MISC2 0x5d8 #define PLLD_BASE 0xd0 #define PLLD_MISC0 0xdc #define PLLD_MISC1 0xd8 #define PLLU_BASE 0xc0 #define PLLU_OUTA 0xc4 #define PLLU_MISC0 0xcc #define PLLU_MISC1 0xc8 #define PLLX_BASE 0xe0 #define PLLX_MISC0 0xe4 #define PLLX_MISC1 0x510 #define PLLX_MISC2 0x514 #define PLLX_MISC3 0x518 #define PLLX_MISC4 0x5f0 #define PLLX_MISC5 0x5f4 #define PLLE_BASE 0xe8 #define PLLE_MISC0 0xec #define PLLD2_BASE 0x4b8 #define PLLD2_MISC0 0x4bc #define PLLD2_MISC1 0x570 #define PLLD2_MISC2 0x574 #define PLLD2_MISC3 0x578 #define PLLE_AUX 0x48c #define PLLRE_BASE 0x4c4 #define PLLRE_MISC0 0x4c8 #define PLLRE_OUT1 0x4cc #define PLLDP_BASE 0x590 #define PLLDP_MISC 0x594 #define PLLC4_BASE 0x5a4 #define PLLC4_MISC0 0x5a8 #define PLLC4_OUT 0x5e4 #define PLLMB_BASE 0x5e8 #define PLLMB_MISC1 0x5ec #define PLLA1_BASE 0x6a4 #define PLLA1_MISC0 0x6a8 #define PLLA1_MISC1 0x6ac #define PLLA1_MISC2 0x6b0 #define PLLA1_MISC3 0x6b4 #define PLLU_IDDQ_BIT 31 #define PLLCX_IDDQ_BIT 27 #define PLLRE_IDDQ_BIT 24 #define PLLA_IDDQ_BIT 25 #define PLLD_IDDQ_BIT 20 #define PLLSS_IDDQ_BIT 18 #define PLLM_IDDQ_BIT 5 #define PLLMB_IDDQ_BIT 17 #define PLLXP_IDDQ_BIT 3 #define PLLCX_RESET_BIT 30 #define PLL_BASE_LOCK BIT(27) #define PLLCX_BASE_LOCK BIT(26) #define PLLE_MISC_LOCK BIT(11) #define PLLRE_MISC_LOCK BIT(27) #define PLL_MISC_LOCK_ENABLE 18 #define PLLC_MISC_LOCK_ENABLE 24 #define PLLDU_MISC_LOCK_ENABLE 22 #define PLLU_MISC_LOCK_ENABLE 29 #define PLLE_MISC_LOCK_ENABLE 9 #define PLLRE_MISC_LOCK_ENABLE 30 #define PLLSS_MISC_LOCK_ENABLE 30 #define PLLP_MISC_LOCK_ENABLE 18 #define PLLM_MISC_LOCK_ENABLE 4 #define PLLMB_MISC_LOCK_ENABLE 16 #define PLLA_MISC_LOCK_ENABLE 28 #define PLLU_MISC_LOCK_ENABLE 29 #define PLLD_MISC_LOCK_ENABLE 18 #define PLLA_SDM_DIN_MASK 0xffff #define PLLA_SDM_EN_MASK BIT(26) #define PLLD_SDM_EN_MASK BIT(16) #define PLLD2_SDM_EN_MASK BIT(31) #define PLLD2_SSC_EN_MASK 0 #define PLLDP_SS_CFG 0x598 #define PLLDP_SDM_EN_MASK BIT(31) #define PLLDP_SSC_EN_MASK BIT(30) #define PLLDP_SS_CTRL1 0x59c #define PLLDP_SS_CTRL2 0x5a0 #define PMC_PLLM_WB0_OVERRIDE 0x1dc #define PMC_PLLM_WB0_OVERRIDE_2 0x2b0 #define UTMIP_PLL_CFG2 0x488 #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6) #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP BIT(1) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP BIT(3) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERUP BIT(5) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN BIT(24) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP BIT(25) #define UTMIP_PLL_CFG1 0x484 #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP BIT(17) #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16) #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP BIT(15) #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14) #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12) #define SATA_PLL_CFG0 0x490 #define SATA_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0) #define SATA_PLL_CFG0_PADPLL_USE_LOCKDET BIT(2) #define SATA_PLL_CFG0_SATA_SEQ_IN_SWCTL BIT(4) #define SATA_PLL_CFG0_SATA_SEQ_RESET_INPUT_VALUE BIT(5) #define SATA_PLL_CFG0_SATA_SEQ_LANE_PD_INPUT_VALUE BIT(6) #define SATA_PLL_CFG0_SATA_SEQ_PADPLL_PD_INPUT_VALUE BIT(7) #define SATA_PLL_CFG0_PADPLL_SLEEP_IDDQ BIT(13) #define SATA_PLL_CFG0_SEQ_ENABLE BIT(24) #define XUSBIO_PLL_CFG0 0x51c #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0) #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL BIT(2) #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET BIT(6) #define XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ BIT(13) #define XUSBIO_PLL_CFG0_SEQ_ENABLE BIT(24) #define UTMIPLL_HW_PWRDN_CFG0 0x52c #define UTMIPLL_HW_PWRDN_CFG0_UTMIPLL_LOCK BIT(31) #define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE BIT(25) #define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24) #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(7) #define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET BIT(6) #define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE BIT(5) #define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL BIT(4) #define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2) #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE BIT(1) #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL BIT(0) #define PLLU_HW_PWRDN_CFG0 0x530 #define PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(28) #define PLLU_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24) #define PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT BIT(7) #define PLLU_HW_PWRDN_CFG0_USE_LOCKDET BIT(6) #define PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2) #define PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL BIT(0) #define XUSB_PLL_CFG0 0x534 #define XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY 0x3ff #define XUSB_PLL_CFG0_PLLU_LOCK_DLY_MASK (0x3ff << 14) #define SPARE_REG0 0x55c #define CLK_M_DIVISOR_SHIFT 2 #define CLK_M_DIVISOR_MASK 0x3 #define CLK_MASK_ARM 0x44 #define MISC_CLK_ENB 0x48 #define RST_DFLL_DVCO 0x2f4 #define DVFS_DFLL_RESET_SHIFT 0 #define CLK_RST_CONTROLLER_CLK_OUT_ENB_X_SET 0x284 #define CLK_RST_CONTROLLER_CLK_OUT_ENB_X_CLR 0x288 #define CLK_OUT_ENB_X_CLK_ENB_EMC_DLL BIT(14) #define CLK_RST_CONTROLLER_RST_DEV_Y_SET 0x2a8 #define CLK_RST_CONTROLLER_RST_DEV_Y_CLR 0x2ac #define CPU_SOFTRST_CTRL 0x380 #define LVL2_CLK_GATE_OVRA 0xf8 #define LVL2_CLK_GATE_OVRC 0x3a0 #define LVL2_CLK_GATE_OVRD 0x3a4 #define LVL2_CLK_GATE_OVRE 0x554 /* I2S registers to handle during APE MBIST WAR */ #define TEGRA210_I2S_BASE 0x1000 #define TEGRA210_I2S_SIZE 0x100 #define TEGRA210_I2S_CTRLS 5 #define TEGRA210_I2S_CG 0x88 #define TEGRA210_I2S_CTRL 0xa0 /* DISPA registers to handle during MBIST WAR */ #define DC_CMD_DISPLAY_COMMAND 0xc8 #define DC_COM_DSC_TOP_CTL 0xcf8 /* VIC register to handle during MBIST WAR */ #define NV_PVIC_THI_SLCG_OVERRIDE_LOW 0x8c /* APE, DISPA and VIC base addesses needed for MBIST WAR */ #define TEGRA210_AHUB_BASE 0x702d0000 #define TEGRA210_DISPA_BASE 0x54200000 #define TEGRA210_VIC_BASE 0x54340000 /* * SDM fractional divisor is 16-bit 2's complement signed number within * (-2^12 ... 2^12-1) range. Represented in PLL data structure as unsigned * 16-bit value, with "0" divisor mapped to 0xFFFF. Data "0" is used to * indicate that SDM is disabled. * * Effective ndiv value when SDM is enabled: ndiv + 1/2 + sdm_din/2^13 */ #define PLL_SDM_COEFF BIT(13) #define sdin_din_to_data(din) ((u16)((din) ? : 0xFFFFU)) #define sdin_data_to_din(dat) (((dat) == 0xFFFFU) ? 0 : (s16)dat) /* This macro returns ndiv effective scaled to SDM range */ #define sdin_get_n_eff(cfg) ((cfg)->n * PLL_SDM_COEFF + ((cfg)->sdm_data ? \ (PLL_SDM_COEFF/2 + sdin_data_to_din((cfg)->sdm_data)) : 0)) /* Tegra CPU clock and reset control regs */ #define CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470 #ifdef CONFIG_PM_SLEEP static struct cpu_clk_suspend_context { u32 clk_csite_src; } tegra210_cpu_clk_sctx; #endif struct tegra210_domain_mbist_war { void (*handle_lvl2_ovr)(struct tegra210_domain_mbist_war *mbist); const u32 lvl2_offset; const u32 lvl2_mask; const unsigned int num_clks; const unsigned int *clk_init_data; struct clk_bulk_data *clks; }; static struct clk **clks; static void __iomem *clk_base; static void __iomem *pmc_base; static void __iomem *ahub_base; static void __iomem *dispa_base; static void __iomem *vic_base; static unsigned long osc_freq; static unsigned long pll_ref_freq; static DEFINE_SPINLOCK(pll_d_lock); static DEFINE_SPINLOCK(pll_e_lock); static DEFINE_SPINLOCK(pll_re_lock); static DEFINE_SPINLOCK(pll_u_lock); static DEFINE_SPINLOCK(sor0_lock); static DEFINE_SPINLOCK(sor1_lock); static DEFINE_SPINLOCK(emc_lock); static DEFINE_MUTEX(lvl2_ovr_lock); /* possible OSC frequencies in Hz */ static unsigned long tegra210_input_freq[] = { [5] = 38400000, [8] = 12000000, }; #define PLL_ENABLE (1 << 30) #define PLLCX_MISC1_IDDQ (1 << 27) #define PLLCX_MISC0_RESET (1 << 30) #define PLLCX_MISC0_DEFAULT_VALUE 0x40080000 #define PLLCX_MISC0_WRITE_MASK 0x400ffffb #define PLLCX_MISC1_DEFAULT_VALUE 0x08000000 #define PLLCX_MISC1_WRITE_MASK 0x08003cff #define PLLCX_MISC2_DEFAULT_VALUE 0x1f720f05 #define PLLCX_MISC2_WRITE_MASK 0xffffff17 #define PLLCX_MISC3_DEFAULT_VALUE 0x000000c4 #define PLLCX_MISC3_WRITE_MASK 0x00ffffff /* PLLA */ #define PLLA_BASE_IDDQ (1 << 25) #define PLLA_BASE_LOCK (1 << 27) #define PLLA_MISC0_LOCK_ENABLE (1 << 28) #define PLLA_MISC0_LOCK_OVERRIDE (1 << 27) #define PLLA_MISC2_EN_SDM (1 << 26) #define PLLA_MISC2_EN_DYNRAMP (1 << 25) #define PLLA_MISC0_DEFAULT_VALUE 0x12000020 #define PLLA_MISC0_WRITE_MASK 0x7fffffff #define PLLA_MISC2_DEFAULT_VALUE 0x0 #define PLLA_MISC2_WRITE_MASK 0x06ffffff /* PLLD */ #define PLLD_BASE_CSI_CLKSOURCE (1 << 23) #define PLLD_MISC0_EN_SDM (1 << 16) #define PLLD_MISC0_LOCK_OVERRIDE (1 << 17) #define PLLD_MISC0_LOCK_ENABLE (1 << 18) #define PLLD_MISC0_IDDQ (1 << 20) #define PLLD_MISC0_DSI_CLKENABLE (1 << 21) #define PLLD_MISC0_DEFAULT_VALUE 0x00140000 #define PLLD_MISC0_WRITE_MASK 0x3ff7ffff #define PLLD_MISC1_DEFAULT_VALUE 0x20 #define PLLD_MISC1_WRITE_MASK 0x00ffffff /* PLLD2 and PLLDP and PLLC4 */ #define PLLDSS_BASE_LOCK (1 << 27) #define PLLDSS_BASE_LOCK_OVERRIDE (1 << 24) #define PLLDSS_BASE_IDDQ (1 << 18) #define PLLDSS_BASE_REF_SEL_SHIFT 25 #define PLLDSS_BASE_REF_SEL_MASK (0x3 << PLLDSS_BASE_REF_SEL_SHIFT) #define PLLDSS_MISC0_LOCK_ENABLE (1 << 30) #define PLLDSS_MISC1_CFG_EN_SDM (1 << 31) #define PLLDSS_MISC1_CFG_EN_SSC (1 << 30) #define PLLD2_MISC0_DEFAULT_VALUE 0x40000020 #define PLLD2_MISC1_CFG_DEFAULT_VALUE 0x10000000 #define PLLD2_MISC2_CTRL1_DEFAULT_VALUE 0x0 #define PLLD2_MISC3_CTRL2_DEFAULT_VALUE 0x0 #define PLLDP_MISC0_DEFAULT_VALUE 0x40000020 #define PLLDP_MISC1_CFG_DEFAULT_VALUE 0xc0000000 #define PLLDP_MISC2_CTRL1_DEFAULT_VALUE 0xf400f0da #define PLLDP_MISC3_CTRL2_DEFAULT_VALUE 0x2004f400 #define PLLDSS_MISC0_WRITE_MASK 0x47ffffff #define PLLDSS_MISC1_CFG_WRITE_MASK 0xf8000000 #define PLLDSS_MISC2_CTRL1_WRITE_MASK 0xffffffff #define PLLDSS_MISC3_CTRL2_WRITE_MASK 0xffffffff #define PLLC4_MISC0_DEFAULT_VALUE 0x40000000 /* PLLRE */ #define PLLRE_MISC0_LOCK_ENABLE (1 << 30) #define PLLRE_MISC0_LOCK_OVERRIDE (1 << 29) #define PLLRE_MISC0_LOCK (1 << 27) #define PLLRE_MISC0_IDDQ (1 << 24) #define PLLRE_BASE_DEFAULT_VALUE 0x0 #define PLLRE_MISC0_DEFAULT_VALUE 0x41000000 #define PLLRE_BASE_DEFAULT_MASK 0x1c000000 #define PLLRE_MISC0_WRITE_MASK 0x67ffffff /* PLLE */ #define PLLE_MISC_IDDQ_SW_CTRL (1 << 14) #define PLLE_AUX_USE_LOCKDET (1 << 3) #define PLLE_AUX_SS_SEQ_INCLUDE (1 << 31) #define PLLE_AUX_ENABLE_SWCTL (1 << 4) #define PLLE_AUX_SS_SWCTL (1 << 6) #define PLLE_AUX_SEQ_ENABLE (1 << 24) /* PLLX */ #define PLLX_USE_DYN_RAMP 1 #define PLLX_BASE_LOCK (1 << 27) #define PLLX_MISC0_FO_G_DISABLE (0x1 << 28) #define PLLX_MISC0_LOCK_ENABLE (0x1 << 18) #define PLLX_MISC2_DYNRAMP_STEPB_SHIFT 24 #define PLLX_MISC2_DYNRAMP_STEPB_MASK (0xFF << PLLX_MISC2_DYNRAMP_STEPB_SHIFT) #define PLLX_MISC2_DYNRAMP_STEPA_SHIFT 16 #define PLLX_MISC2_DYNRAMP_STEPA_MASK (0xFF << PLLX_MISC2_DYNRAMP_STEPA_SHIFT) #define PLLX_MISC2_NDIV_NEW_SHIFT 8 #define PLLX_MISC2_NDIV_NEW_MASK (0xFF << PLLX_MISC2_NDIV_NEW_SHIFT) #define PLLX_MISC2_LOCK_OVERRIDE (0x1 << 4) #define PLLX_MISC2_DYNRAMP_DONE (0x1 << 2) #define PLLX_MISC2_EN_DYNRAMP (0x1 << 0) #define PLLX_MISC3_IDDQ (0x1 << 3) #define PLLX_MISC0_DEFAULT_VALUE PLLX_MISC0_LOCK_ENABLE #define PLLX_MISC0_WRITE_MASK 0x10c40000 #define PLLX_MISC1_DEFAULT_VALUE 0x20 #define PLLX_MISC1_WRITE_MASK 0x00ffffff #define PLLX_MISC2_DEFAULT_VALUE 0x0 #define PLLX_MISC2_WRITE_MASK 0xffffff11 #define PLLX_MISC3_DEFAULT_VALUE PLLX_MISC3_IDDQ #define PLLX_MISC3_WRITE_MASK 0x01ff0f0f #define PLLX_MISC4_DEFAULT_VALUE 0x0 #define PLLX_MISC4_WRITE_MASK 0x8000ffff #define PLLX_MISC5_DEFAULT_VALUE 0x0 #define PLLX_MISC5_WRITE_MASK 0x0000ffff #define PLLX_HW_CTRL_CFG 0x548 #define PLLX_HW_CTRL_CFG_SWCTRL (0x1 << 0) /* PLLMB */ #define PLLMB_BASE_LOCK (1 << 27) #define PLLMB_MISC1_LOCK_OVERRIDE (1 << 18) #define PLLMB_MISC1_IDDQ (1 << 17) #define PLLMB_MISC1_LOCK_ENABLE (1 << 16) #define PLLMB_MISC1_DEFAULT_VALUE 0x00030000 #define PLLMB_MISC1_WRITE_MASK 0x0007ffff /* PLLP */ #define PLLP_BASE_OVERRIDE (1 << 28) #define PLLP_BASE_LOCK (1 << 27) #define PLLP_MISC0_LOCK_ENABLE (1 << 18) #define PLLP_MISC0_LOCK_OVERRIDE (1 << 17) #define PLLP_MISC0_IDDQ (1 << 3) #define PLLP_MISC1_HSIO_EN_SHIFT 29 #define PLLP_MISC1_HSIO_EN (1 << PLLP_MISC1_HSIO_EN_SHIFT) #define PLLP_MISC1_XUSB_EN_SHIFT 28 #define PLLP_MISC1_XUSB_EN (1 << PLLP_MISC1_XUSB_EN_SHIFT) #define PLLP_MISC0_DEFAULT_VALUE 0x00040008 #define PLLP_MISC1_DEFAULT_VALUE 0x0 #define PLLP_MISC0_WRITE_MASK 0xdc6000f #define PLLP_MISC1_WRITE_MASK 0x70ffffff /* PLLU */ #define PLLU_BASE_LOCK (1 << 27) #define PLLU_BASE_OVERRIDE (1 << 24) #define PLLU_BASE_CLKENABLE_USB (1 << 21) #define PLLU_BASE_CLKENABLE_HSIC (1 << 22) #define PLLU_BASE_CLKENABLE_ICUSB (1 << 23) #define PLLU_BASE_CLKENABLE_48M (1 << 25) #define PLLU_BASE_CLKENABLE_ALL (PLLU_BASE_CLKENABLE_USB |\ PLLU_BASE_CLKENABLE_HSIC |\ PLLU_BASE_CLKENABLE_ICUSB |\ PLLU_BASE_CLKENABLE_48M) #define PLLU_MISC0_IDDQ (1 << 31) #define PLLU_MISC0_LOCK_ENABLE (1 << 29) #define PLLU_MISC1_LOCK_OVERRIDE (1 << 0) #define PLLU_MISC0_DEFAULT_VALUE 0xa0000000 #define PLLU_MISC1_DEFAULT_VALUE 0x0 #define PLLU_MISC0_WRITE_MASK 0xbfffffff #define PLLU_MISC1_WRITE_MASK 0x00000007 bool tegra210_plle_hw_sequence_is_enabled(void) { u32 value; value = readl_relaxed(clk_base + PLLE_AUX); if (value & PLLE_AUX_SEQ_ENABLE) return true; return false; } EXPORT_SYMBOL_GPL(tegra210_plle_hw_sequence_is_enabled); int tegra210_plle_hw_sequence_start(void) { u32 value; if (tegra210_plle_hw_sequence_is_enabled()) return 0; /* skip if PLLE is not enabled yet */ value = readl_relaxed(clk_base + PLLE_MISC0); if (!(value & PLLE_MISC_LOCK)) return -EIO; value &= ~PLLE_MISC_IDDQ_SW_CTRL; writel_relaxed(value, clk_base + PLLE_MISC0); value = readl_relaxed(clk_base + PLLE_AUX); value |= (PLLE_AUX_USE_LOCKDET | PLLE_AUX_SS_SEQ_INCLUDE); value &= ~(PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL); writel_relaxed(value, clk_base + PLLE_AUX); fence_udelay(1, clk_base); value |= PLLE_AUX_SEQ_ENABLE; writel_relaxed(value, clk_base + PLLE_AUX); fence_udelay(1, clk_base); return 0; } EXPORT_SYMBOL_GPL(tegra210_plle_hw_sequence_start); void tegra210_xusb_pll_hw_control_enable(void) { u32 val; val = readl_relaxed(clk_base + XUSBIO_PLL_CFG0); val &= ~(XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL | XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL); val |= XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET | XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ; writel_relaxed(val, clk_base + XUSBIO_PLL_CFG0); } EXPORT_SYMBOL_GPL(tegra210_xusb_pll_hw_control_enable); void tegra210_xusb_pll_hw_sequence_start(void) { u32 val; val = readl_relaxed(clk_base + XUSBIO_PLL_CFG0); val |= XUSBIO_PLL_CFG0_SEQ_ENABLE; writel_relaxed(val, clk_base + XUSBIO_PLL_CFG0); } EXPORT_SYMBOL_GPL(tegra210_xusb_pll_hw_sequence_start); void tegra210_sata_pll_hw_control_enable(void) { u32 val; val = readl_relaxed(clk_base + SATA_PLL_CFG0); val &= ~SATA_PLL_CFG0_PADPLL_RESET_SWCTL; val |= SATA_PLL_CFG0_PADPLL_USE_LOCKDET | SATA_PLL_CFG0_PADPLL_SLEEP_IDDQ; writel_relaxed(val, clk_base + SATA_PLL_CFG0); } EXPORT_SYMBOL_GPL(tegra210_sata_pll_hw_control_enable); void tegra210_sata_pll_hw_sequence_start(void) { u32 val; val = readl_relaxed(clk_base + SATA_PLL_CFG0); val |= SATA_PLL_CFG0_SEQ_ENABLE; writel_relaxed(val, clk_base + SATA_PLL_CFG0); } EXPORT_SYMBOL_GPL(tegra210_sata_pll_hw_sequence_start); void tegra210_set_sata_pll_seq_sw(bool state) { u32 val; val = readl_relaxed(clk_base + SATA_PLL_CFG0); if (state) { val |= SATA_PLL_CFG0_SATA_SEQ_IN_SWCTL; val |= SATA_PLL_CFG0_SATA_SEQ_RESET_INPUT_VALUE; val |= SATA_PLL_CFG0_SATA_SEQ_LANE_PD_INPUT_VALUE; val |= SATA_PLL_CFG0_SATA_SEQ_PADPLL_PD_INPUT_VALUE; } else { val &= ~SATA_PLL_CFG0_SATA_SEQ_IN_SWCTL; val &= ~SATA_PLL_CFG0_SATA_SEQ_RESET_INPUT_VALUE; val &= ~SATA_PLL_CFG0_SATA_SEQ_LANE_PD_INPUT_VALUE; val &= ~SATA_PLL_CFG0_SATA_SEQ_PADPLL_PD_INPUT_VALUE; } writel_relaxed(val, clk_base + SATA_PLL_CFG0); } EXPORT_SYMBOL_GPL(tegra210_set_sata_pll_seq_sw); void tegra210_clk_emc_dll_enable(bool flag) { u32 offset = flag ? CLK_RST_CONTROLLER_CLK_OUT_ENB_X_SET : CLK_RST_CONTROLLER_CLK_OUT_ENB_X_CLR; writel_relaxed(CLK_OUT_ENB_X_CLK_ENB_EMC_DLL, clk_base + offset); } EXPORT_SYMBOL_GPL(tegra210_clk_emc_dll_enable); void tegra210_clk_emc_dll_update_setting(u32 emc_dll_src_value) { writel_relaxed(emc_dll_src_value, clk_base + CLK_SOURCE_EMC_DLL); } EXPORT_SYMBOL_GPL(tegra210_clk_emc_dll_update_setting); void tegra210_clk_emc_update_setting(u32 emc_src_value) { writel_relaxed(emc_src_value, clk_base + CLK_SOURCE_EMC); } EXPORT_SYMBOL_GPL(tegra210_clk_emc_update_setting); static void tegra210_generic_mbist_war(struct tegra210_domain_mbist_war *mbist) { u32 val; val = readl_relaxed(clk_base + mbist->lvl2_offset); writel_relaxed(val | mbist->lvl2_mask, clk_base + mbist->lvl2_offset); fence_udelay(1, clk_base); writel_relaxed(val, clk_base + mbist->lvl2_offset); fence_udelay(1, clk_base); } static void tegra210_venc_mbist_war(struct tegra210_domain_mbist_war *mbist) { u32 csi_src, ovra, ovre; unsigned long flags = 0; spin_lock_irqsave(&pll_d_lock, flags); csi_src = readl_relaxed(clk_base + PLLD_BASE); writel_relaxed(csi_src | PLLD_BASE_CSI_CLKSOURCE, clk_base + PLLD_BASE); fence_udelay(1, clk_base); ovra = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRA); writel_relaxed(ovra | BIT(15), clk_base + LVL2_CLK_GATE_OVRA); ovre = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRE); writel_relaxed(ovre | BIT(3), clk_base + LVL2_CLK_GATE_OVRE); fence_udelay(1, clk_base); writel_relaxed(ovra, clk_base + LVL2_CLK_GATE_OVRA); writel_relaxed(ovre, clk_base + LVL2_CLK_GATE_OVRE); writel_relaxed(csi_src, clk_base + PLLD_BASE); fence_udelay(1, clk_base); spin_unlock_irqrestore(&pll_d_lock, flags); } static void tegra210_disp_mbist_war(struct tegra210_domain_mbist_war *mbist) { u32 ovra, dsc_top_ctrl; ovra = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRA); writel_relaxed(ovra | BIT(1), clk_base + LVL2_CLK_GATE_OVRA); fence_udelay(1, clk_base); dsc_top_ctrl = readl_relaxed(dispa_base + DC_COM_DSC_TOP_CTL); writel_relaxed(dsc_top_ctrl | BIT(2), dispa_base + DC_COM_DSC_TOP_CTL); readl_relaxed(dispa_base + DC_CMD_DISPLAY_COMMAND); writel_relaxed(dsc_top_ctrl, dispa_base + DC_COM_DSC_TOP_CTL); readl_relaxed(dispa_base + DC_CMD_DISPLAY_COMMAND); writel_relaxed(ovra, clk_base + LVL2_CLK_GATE_OVRA); fence_udelay(1, clk_base); } static void tegra210_vic_mbist_war(struct tegra210_domain_mbist_war *mbist) { u32 ovre, val; ovre = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRE); writel_relaxed(ovre | BIT(5), clk_base + LVL2_CLK_GATE_OVRE); fence_udelay(1, clk_base); val = readl_relaxed(vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW); writel_relaxed(val | BIT(0) | GENMASK(7, 2) | BIT(24), vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW); fence_udelay(1, vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW); writel_relaxed(val, vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW); readl(vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW); writel_relaxed(ovre, clk_base + LVL2_CLK_GATE_OVRE); fence_udelay(1, clk_base); } static void tegra210_ape_mbist_war(struct tegra210_domain_mbist_war *mbist) { void __iomem *i2s_base; unsigned int i; u32 ovrc, ovre; ovrc = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRC); ovre = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRE); writel_relaxed(ovrc | BIT(1), clk_base + LVL2_CLK_GATE_OVRC); writel_relaxed(ovre | BIT(10) | BIT(11), clk_base + LVL2_CLK_GATE_OVRE); fence_udelay(1, clk_base); i2s_base = ahub_base + TEGRA210_I2S_BASE; for (i = 0; i < TEGRA210_I2S_CTRLS; i++) { u32 i2s_ctrl; i2s_ctrl = readl_relaxed(i2s_base + TEGRA210_I2S_CTRL); writel_relaxed(i2s_ctrl | BIT(10), i2s_base + TEGRA210_I2S_CTRL); writel_relaxed(0, i2s_base + TEGRA210_I2S_CG); readl(i2s_base + TEGRA210_I2S_CG); writel_relaxed(1, i2s_base + TEGRA210_I2S_CG); writel_relaxed(i2s_ctrl, i2s_base + TEGRA210_I2S_CTRL); readl(i2s_base + TEGRA210_I2S_CTRL); i2s_base += TEGRA210_I2S_SIZE; } writel_relaxed(ovrc, clk_base + LVL2_CLK_GATE_OVRC); writel_relaxed(ovre, clk_base + LVL2_CLK_GATE_OVRE); fence_udelay(1, clk_base); } static inline void _pll_misc_chk_default(void __iomem *base, struct tegra_clk_pll_params *params, u8 misc_num, u32 default_val, u32 mask) { u32 boot_val = readl_relaxed(base + params->ext_misc_reg[misc_num]); boot_val &= mask; default_val &= mask; if (boot_val != default_val) { pr_warn("boot misc%d 0x%x: expected 0x%x\n", misc_num, boot_val, default_val); pr_warn(" (comparison mask = 0x%x)\n", mask); params->defaults_set = false; } } /* * PLLCX: PLLC, PLLC2, PLLC3, PLLA1 * Hybrid PLLs with dynamic ramp. Dynamic ramp is allowed for any transition * that changes NDIV only, while PLL is already locked. */ static void pllcx_check_defaults(struct tegra_clk_pll_params *params) { u32 default_val; default_val = PLLCX_MISC0_DEFAULT_VALUE & (~PLLCX_MISC0_RESET); _pll_misc_chk_default(clk_base, params, 0, default_val, PLLCX_MISC0_WRITE_MASK); default_val = PLLCX_MISC1_DEFAULT_VALUE & (~PLLCX_MISC1_IDDQ); _pll_misc_chk_default(clk_base, params, 1, default_val, PLLCX_MISC1_WRITE_MASK); default_val = PLLCX_MISC2_DEFAULT_VALUE; _pll_misc_chk_default(clk_base, params, 2, default_val, PLLCX_MISC2_WRITE_MASK); default_val = PLLCX_MISC3_DEFAULT_VALUE; _pll_misc_chk_default(clk_base, params, 3, default_val, PLLCX_MISC3_WRITE_MASK); } static void tegra210_pllcx_set_defaults(const char *name, struct tegra_clk_pll *pllcx) { pllcx->params->defaults_set = true; if (readl_relaxed(clk_base + pllcx->params->base_reg) & PLL_ENABLE) { /* PLL is ON: only check if defaults already set */ pllcx_check_defaults(pllcx->params); if (!pllcx->params->defaults_set) pr_warn("%s already enabled. Postponing set full defaults\n", name); return; } /* Defaults assert PLL reset, and set IDDQ */ writel_relaxed(PLLCX_MISC0_DEFAULT_VALUE, clk_base + pllcx->params->ext_misc_reg[0]); writel_relaxed(PLLCX_MISC1_DEFAULT_VALUE, clk_base + pllcx->params->ext_misc_reg[1]); writel_relaxed(PLLCX_MISC2_DEFAULT_VALUE, clk_base + pllcx->params->ext_misc_reg[2]); writel_relaxed(PLLCX_MISC3_DEFAULT_VALUE, clk_base + pllcx->params->ext_misc_reg[3]); udelay(1); } static void _pllc_set_defaults(struct tegra_clk_pll *pllcx) { tegra210_pllcx_set_defaults("PLL_C", pllcx); } static void _pllc2_set_defaults(struct tegra_clk_pll *pllcx) { tegra210_pllcx_set_defaults("PLL_C2", pllcx); } static void _pllc3_set_defaults(struct tegra_clk_pll *pllcx) { tegra210_pllcx_set_defaults("PLL_C3", pllcx); } static void _plla1_set_defaults(struct tegra_clk_pll *pllcx) { tegra210_pllcx_set_defaults("PLL_A1", pllcx); } /* * PLLA * PLL with dynamic ramp and fractional SDM. Dynamic ramp is not used. * Fractional SDM is allowed to provide exact audio rates. */ static void tegra210_plla_set_defaults(struct tegra_clk_pll *plla) { u32 mask; u32 val = readl_relaxed(clk_base + plla->params->base_reg); plla->params->defaults_set = true; if (val & PLL_ENABLE) { /* * PLL is ON: check if defaults already set, then set those * that can be updated in flight. */ if (val & PLLA_BASE_IDDQ) { pr_warn("PLL_A boot enabled with IDDQ set\n"); plla->params->defaults_set = false; } pr_warn("PLL_A already enabled. Postponing set full defaults\n"); val = PLLA_MISC0_DEFAULT_VALUE; /* ignore lock enable */ mask = PLLA_MISC0_LOCK_ENABLE | PLLA_MISC0_LOCK_OVERRIDE; _pll_misc_chk_default(clk_base, plla->params, 0, val, ~mask & PLLA_MISC0_WRITE_MASK); val = PLLA_MISC2_DEFAULT_VALUE; /* ignore all but control bit */ _pll_misc_chk_default(clk_base, plla->params, 2, val, PLLA_MISC2_EN_DYNRAMP); /* Enable lock detect */ val = readl_relaxed(clk_base + plla->params->ext_misc_reg[0]); val &= ~mask; val |= PLLA_MISC0_DEFAULT_VALUE & mask; writel_relaxed(val, clk_base + plla->params->ext_misc_reg[0]); udelay(1); return; } /* set IDDQ, enable lock detect, disable dynamic ramp and SDM */ val |= PLLA_BASE_IDDQ; writel_relaxed(val, clk_base + plla->params->base_reg); writel_relaxed(PLLA_MISC0_DEFAULT_VALUE, clk_base + plla->params->ext_misc_reg[0]); writel_relaxed(PLLA_MISC2_DEFAULT_VALUE, clk_base + plla->params->ext_misc_reg[2]); udelay(1); } /* * PLLD * PLL with fractional SDM. */ static void tegra210_plld_set_defaults(struct tegra_clk_pll *plld) { u32 val; u32 mask = 0xffff; plld->params->defaults_set = true; if (readl_relaxed(clk_base + plld->params->base_reg) & PLL_ENABLE) { /* * PLL is ON: check if defaults already set, then set those * that can be updated in flight. */ val = PLLD_MISC1_DEFAULT_VALUE; _pll_misc_chk_default(clk_base, plld->params, 1, val, PLLD_MISC1_WRITE_MASK); /* ignore lock, DSI and SDM controls, make sure IDDQ not set */ val = PLLD_MISC0_DEFAULT_VALUE & (~PLLD_MISC0_IDDQ); mask |= PLLD_MISC0_DSI_CLKENABLE | PLLD_MISC0_LOCK_ENABLE | PLLD_MISC0_LOCK_OVERRIDE | PLLD_MISC0_EN_SDM; _pll_misc_chk_default(clk_base, plld->params, 0, val, ~mask & PLLD_MISC0_WRITE_MASK); if (!plld->params->defaults_set) pr_warn("PLL_D already enabled. Postponing set full defaults\n"); /* Enable lock detect */ mask = PLLD_MISC0_LOCK_ENABLE | PLLD_MISC0_LOCK_OVERRIDE; val = readl_relaxed(clk_base + plld->params->ext_misc_reg[0]); val &= ~mask; val |= PLLD_MISC0_DEFAULT_VALUE & mask; writel_relaxed(val, clk_base + plld->params->ext_misc_reg[0]); udelay(1); return; } val = readl_relaxed(clk_base + plld->params->ext_misc_reg[0]); val &= PLLD_MISC0_DSI_CLKENABLE; val |= PLLD_MISC0_DEFAULT_VALUE; /* set IDDQ, enable lock detect, disable SDM */ writel_relaxed(val, clk_base + plld->params->ext_misc_reg[0]); writel_relaxed(PLLD_MISC1_DEFAULT_VALUE, clk_base + plld->params->ext_misc_reg[1]); udelay(1); } /* * PLLD2, PLLDP * PLL with fractional SDM and Spread Spectrum (SDM is a must if SSC is used). */ static void plldss_defaults(const char *pll_name, struct tegra_clk_pll *plldss, u32 misc0_val, u32 misc1_val, u32 misc2_val, u32 misc3_val) { u32 default_val; u32 val = readl_relaxed(clk_base + plldss->params->base_reg); plldss->params->defaults_set = true; if (val & PLL_ENABLE) { /* * PLL is ON: check if defaults already set, then set those * that can be updated in flight. */ if (val & PLLDSS_BASE_IDDQ) { pr_warn("plldss boot enabled with IDDQ set\n"); plldss->params->defaults_set = false; } /* ignore lock enable */ default_val = misc0_val; _pll_misc_chk_default(clk_base, plldss->params, 0, default_val, PLLDSS_MISC0_WRITE_MASK & (~PLLDSS_MISC0_LOCK_ENABLE)); /* * If SSC is used, check all settings, otherwise just confirm * that SSC is not used on boot as well. Do nothing when using * this function for PLLC4 that has only MISC0. */ if (plldss->params->ssc_ctrl_en_mask) { default_val = misc1_val; _pll_misc_chk_default(clk_base, plldss->params, 1, default_val, PLLDSS_MISC1_CFG_WRITE_MASK); default_val = misc2_val; _pll_misc_chk_default(clk_base, plldss->params, 2, default_val, PLLDSS_MISC2_CTRL1_WRITE_MASK); default_val = misc3_val; _pll_misc_chk_default(clk_base, plldss->params, 3, default_val, PLLDSS_MISC3_CTRL2_WRITE_MASK); } else if (plldss->params->ext_misc_reg[1]) { default_val = misc1_val; _pll_misc_chk_default(clk_base, plldss->params, 1, default_val, PLLDSS_MISC1_CFG_WRITE_MASK & (~PLLDSS_MISC1_CFG_EN_SDM)); } if (!plldss->params->defaults_set) pr_warn("%s already enabled. Postponing set full defaults\n", pll_name); /* Enable lock detect */ if (val & PLLDSS_BASE_LOCK_OVERRIDE) { val &= ~PLLDSS_BASE_LOCK_OVERRIDE; writel_relaxed(val, clk_base + plldss->params->base_reg); } val = readl_relaxed(clk_base + plldss->params->ext_misc_reg[0]); val &= ~PLLDSS_MISC0_LOCK_ENABLE; val |= misc0_val & PLLDSS_MISC0_LOCK_ENABLE; writel_relaxed(val, clk_base + plldss->params->ext_misc_reg[0]); udelay(1); return; } /* set IDDQ, enable lock detect, configure SDM/SSC */ val |= PLLDSS_BASE_IDDQ; val &= ~PLLDSS_BASE_LOCK_OVERRIDE; writel_relaxed(val, clk_base + plldss->params->base_reg); /* When using this function for PLLC4 exit here */ if (!plldss->params->ext_misc_reg[1]) { writel_relaxed(misc0_val, clk_base + plldss->params->ext_misc_reg[0]); udelay(1); return; } writel_relaxed(misc0_val, clk_base + plldss->params->ext_misc_reg[0]); /* if SSC used set by 1st enable */ writel_relaxed(misc1_val & (~PLLDSS_MISC1_CFG_EN_SSC), clk_base + plldss->params->ext_misc_reg[1]); writel_relaxed(misc2_val, clk_base + plldss->params->ext_misc_reg[2]); writel_relaxed(misc3_val, clk_base + plldss->params->ext_misc_reg[3]); udelay(1); } static void tegra210_plld2_set_defaults(struct tegra_clk_pll *plld2) { plldss_defaults("PLL_D2", plld2, PLLD2_MISC0_DEFAULT_VALUE, PLLD2_MISC1_CFG_DEFAULT_VALUE, PLLD2_MISC2_CTRL1_DEFAULT_VALUE, PLLD2_MISC3_CTRL2_DEFAULT_VALUE); } static void tegra210_plldp_set_defaults(struct tegra_clk_pll *plldp) { plldss_defaults("PLL_DP", plldp, PLLDP_MISC0_DEFAULT_VALUE, PLLDP_MISC1_CFG_DEFAULT_VALUE, PLLDP_MISC2_CTRL1_DEFAULT_VALUE, PLLDP_MISC3_CTRL2_DEFAULT_VALUE); } /* * PLLC4 * Base and misc0 layout is the same as PLLD2/PLLDP, but no SDM/SSC support. * VCO is exposed to the clock tree via fixed 1/3 and 1/5 dividers. */ static void tegra210_pllc4_set_defaults(struct tegra_clk_pll *pllc4) { plldss_defaults("PLL_C4", pllc4, PLLC4_MISC0_DEFAULT_VALUE, 0, 0, 0); } /* * PLLRE * VCO is exposed to the clock tree directly along with post-divider output */ static void tegra210_pllre_set_defaults(struct tegra_clk_pll *pllre) { u32 mask; u32 val = readl_relaxed(clk_base + pllre->params->base_reg); pllre->params->defaults_set = true; if (val & PLL_ENABLE) { /* * PLL is ON: check if defaults already set, then set those * that can be updated in flight. */ val &= PLLRE_BASE_DEFAULT_MASK; if (val != PLLRE_BASE_DEFAULT_VALUE) { pr_warn("pllre boot base 0x%x : expected 0x%x\n", val, PLLRE_BASE_DEFAULT_VALUE); pr_warn("(comparison mask = 0x%x)\n", PLLRE_BASE_DEFAULT_MASK); pllre->params->defaults_set = false; } /* Ignore lock enable */ val = PLLRE_MISC0_DEFAULT_VALUE & (~PLLRE_MISC0_IDDQ); mask = PLLRE_MISC0_LOCK_ENABLE | PLLRE_MISC0_LOCK_OVERRIDE; _pll_misc_chk_default(clk_base, pllre->params, 0, val, ~mask & PLLRE_MISC0_WRITE_MASK); /* The PLL doesn't work if it's in IDDQ. */ val = readl_relaxed(clk_base + pllre->params->ext_misc_reg[0]); if (val & PLLRE_MISC0_IDDQ) pr_warn("unexpected IDDQ bit set for enabled clock\n"); /* Enable lock detect */ val &= ~mask; val |= PLLRE_MISC0_DEFAULT_VALUE & mask; writel_relaxed(val, clk_base + pllre->params->ext_misc_reg[0]); udelay(1); if (!pllre->params->defaults_set) pr_warn("PLL_RE already enabled. Postponing set full defaults\n"); return; } /* set IDDQ, enable lock detect */ val &= ~PLLRE_BASE_DEFAULT_MASK; val |= PLLRE_BASE_DEFAULT_VALUE & PLLRE_BASE_DEFAULT_MASK; writel_relaxed(val, clk_base + pllre->params->base_reg); writel_relaxed(PLLRE_MISC0_DEFAULT_VALUE, clk_base + pllre->params->ext_misc_reg[0]); udelay(1); } static void pllx_get_dyn_steps(struct clk_hw *hw, u32 *step_a, u32 *step_b) { unsigned long input_rate; /* cf rate */ if (!IS_ERR_OR_NULL(hw->clk)) input_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); else input_rate = 38400000; input_rate /= tegra_pll_get_fixed_mdiv(hw, input_rate); switch (input_rate) { case 12000000: case 12800000: case 13000000: *step_a = 0x2B; *step_b = 0x0B; return; case 19200000: *step_a = 0x12; *step_b = 0x08; return; case 38400000: *step_a = 0x04; *step_b = 0x05; return; default: pr_err("%s: Unexpected reference rate %lu\n", __func__, input_rate); BUG(); } } static void pllx_check_defaults(struct tegra_clk_pll *pll) { u32 default_val; default_val = PLLX_MISC0_DEFAULT_VALUE; /* ignore lock enable */ _pll_misc_chk_default(clk_base, pll->params, 0, default_val, PLLX_MISC0_WRITE_MASK & (~PLLX_MISC0_LOCK_ENABLE)); default_val = PLLX_MISC1_DEFAULT_VALUE; _pll_misc_chk_default(clk_base, pll->params, 1, default_val, PLLX_MISC1_WRITE_MASK); /* ignore all but control bit */ default_val = PLLX_MISC2_DEFAULT_VALUE; _pll_misc_chk_default(clk_base, pll->params, 2, default_val, PLLX_MISC2_EN_DYNRAMP); default_val = PLLX_MISC3_DEFAULT_VALUE & (~PLLX_MISC3_IDDQ); _pll_misc_chk_default(clk_base, pll->params, 3, default_val, PLLX_MISC3_WRITE_MASK); default_val = PLLX_MISC4_DEFAULT_VALUE; _pll_misc_chk_default(clk_base, pll->params, 4, default_val, PLLX_MISC4_WRITE_MASK); default_val = PLLX_MISC5_DEFAULT_VALUE; _pll_misc_chk_default(clk_base, pll->params, 5, default_val, PLLX_MISC5_WRITE_MASK); } static void tegra210_pllx_set_defaults(struct tegra_clk_pll *pllx) { u32 val; u32 step_a, step_b; pllx->params->defaults_set = true; /* Get ready dyn ramp state machine settings */ pllx_get_dyn_steps(&pllx->hw, &step_a, &step_b); val = PLLX_MISC2_DEFAULT_VALUE & (~PLLX_MISC2_DYNRAMP_STEPA_MASK) & (~PLLX_MISC2_DYNRAMP_STEPB_MASK); val |= step_a << PLLX_MISC2_DYNRAMP_STEPA_SHIFT; val |= step_b << PLLX_MISC2_DYNRAMP_STEPB_SHIFT; if (readl_relaxed(clk_base + pllx->params->base_reg) & PLL_ENABLE) { /* * PLL is ON: check if defaults already set, then set those * that can be updated in flight. */ pllx_check_defaults(pllx); if (!pllx->params->defaults_set) pr_warn("PLL_X already enabled. Postponing set full defaults\n"); /* Configure dyn ramp, disable lock override */ writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); /* Enable lock detect */ val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[0]); val &= ~PLLX_MISC0_LOCK_ENABLE; val |= PLLX_MISC0_DEFAULT_VALUE & PLLX_MISC0_LOCK_ENABLE; writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[0]); udelay(1); return; } /* Enable lock detect and CPU output */ writel_relaxed(PLLX_MISC0_DEFAULT_VALUE, clk_base + pllx->params->ext_misc_reg[0]); /* Setup */ writel_relaxed(PLLX_MISC1_DEFAULT_VALUE, clk_base + pllx->params->ext_misc_reg[1]); /* Configure dyn ramp state machine, disable lock override */ writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); /* Set IDDQ */ writel_relaxed(PLLX_MISC3_DEFAULT_VALUE, clk_base + pllx->params->ext_misc_reg[3]); /* Disable SDM */ writel_relaxed(PLLX_MISC4_DEFAULT_VALUE, clk_base + pllx->params->ext_misc_reg[4]); writel_relaxed(PLLX_MISC5_DEFAULT_VALUE, clk_base + pllx->params->ext_misc_reg[5]); udelay(1); } /* PLLMB */ static void tegra210_pllmb_set_defaults(struct tegra_clk_pll *pllmb) { u32 mask, val = readl_relaxed(clk_base + pllmb->params->base_reg); pllmb->params->defaults_set = true; if (val & PLL_ENABLE) { /* * PLL is ON: check if defaults already set, then set those * that can be updated in flight. */ val = PLLMB_MISC1_DEFAULT_VALUE & (~PLLMB_MISC1_IDDQ); mask = PLLMB_MISC1_LOCK_ENABLE | PLLMB_MISC1_LOCK_OVERRIDE; _pll_misc_chk_default(clk_base, pllmb->params, 0, val, ~mask & PLLMB_MISC1_WRITE_MASK); if (!pllmb->params->defaults_set) pr_warn("PLL_MB already enabled. Postponing set full defaults\n"); /* Enable lock detect */ val = readl_relaxed(clk_base + pllmb->params->ext_misc_reg[0]); val &= ~mask; val |= PLLMB_MISC1_DEFAULT_VALUE & mask; writel_relaxed(val, clk_base + pllmb->params->ext_misc_reg[0]); udelay(1); return; } /* set IDDQ, enable lock detect */ writel_relaxed(PLLMB_MISC1_DEFAULT_VALUE, clk_base + pllmb->params->ext_misc_reg[0]); udelay(1); } /* * PLLP * VCO is exposed to the clock tree directly along with post-divider output. * Both VCO and post-divider output rates are fixed at 408MHz and 204MHz, * respectively. */ static void pllp_check_defaults(struct tegra_clk_pll *pll, bool enabled) { u32 val, mask; /* Ignore lock enable (will be set), make sure not in IDDQ if enabled */ val = PLLP_MISC0_DEFAULT_VALUE & (~PLLP_MISC0_IDDQ); mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE; if (!enabled) mask |= PLLP_MISC0_IDDQ; _pll_misc_chk_default(clk_base, pll->params, 0, val, ~mask & PLLP_MISC0_WRITE_MASK); /* Ignore branch controls */ val = PLLP_MISC1_DEFAULT_VALUE; mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN; _pll_misc_chk_default(clk_base, pll->params, 1, val, ~mask & PLLP_MISC1_WRITE_MASK); } static void tegra210_pllp_set_defaults(struct tegra_clk_pll *pllp) { u32 mask; u32 val = readl_relaxed(clk_base + pllp->params->base_reg); pllp->params->defaults_set = true; if (val & PLL_ENABLE) { /* * PLL is ON: check if defaults already set, then set those * that can be updated in flight. */ pllp_check_defaults(pllp, true); if (!pllp->params->defaults_set) pr_warn("PLL_P already enabled. Postponing set full defaults\n"); /* Enable lock detect */ val = readl_relaxed(clk_base + pllp->params->ext_misc_reg[0]); mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE; val &= ~mask; val |= PLLP_MISC0_DEFAULT_VALUE & mask; writel_relaxed(val, clk_base + pllp->params->ext_misc_reg[0]); udelay(1); return; } /* set IDDQ, enable lock detect */ writel_relaxed(PLLP_MISC0_DEFAULT_VALUE, clk_base + pllp->params->ext_misc_reg[0]); /* Preserve branch control */ val = readl_relaxed(clk_base + pllp->params->ext_misc_reg[1]); mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN; val &= mask; val |= ~mask & PLLP_MISC1_DEFAULT_VALUE; writel_relaxed(val, clk_base + pllp->params->ext_misc_reg[1]); udelay(1); } /* * PLLU * VCO is exposed to the clock tree directly along with post-divider output. * Both VCO and post-divider output rates are fixed at 480MHz and 240MHz, * respectively. */ static void pllu_check_defaults(struct tegra_clk_pll_params *params, bool hw_control) { u32 val, mask; /* Ignore lock enable (will be set) and IDDQ if under h/w control */ val = PLLU_MISC0_DEFAULT_VALUE & (~PLLU_MISC0_IDDQ); mask = PLLU_MISC0_LOCK_ENABLE | (hw_control ? PLLU_MISC0_IDDQ : 0); _pll_misc_chk_default(clk_base, params, 0, val, ~mask & PLLU_MISC0_WRITE_MASK); val = PLLU_MISC1_DEFAULT_VALUE; mask = PLLU_MISC1_LOCK_OVERRIDE; _pll_misc_chk_default(clk_base, params, 1, val, ~mask & PLLU_MISC1_WRITE_MASK); } static void tegra210_pllu_set_defaults(struct tegra_clk_pll_params *pllu) { u32 val = readl_relaxed(clk_base + pllu->base_reg); pllu->defaults_set = true; if (val & PLL_ENABLE) { /* * PLL is ON: check if defaults already set, then set those * that can be updated in flight. */ pllu_check_defaults(pllu, false); if (!pllu->defaults_set) pr_warn("PLL_U already enabled. Postponing set full defaults\n"); /* Enable lock detect */ val = readl_relaxed(clk_base + pllu->ext_misc_reg[0]); val &= ~PLLU_MISC0_LOCK_ENABLE; val |= PLLU_MISC0_DEFAULT_VALUE & PLLU_MISC0_LOCK_ENABLE; writel_relaxed(val, clk_base + pllu->ext_misc_reg[0]); val = readl_relaxed(clk_base + pllu->ext_misc_reg[1]); val &= ~PLLU_MISC1_LOCK_OVERRIDE; val |= PLLU_MISC1_DEFAULT_VALUE & PLLU_MISC1_LOCK_OVERRIDE; writel_relaxed(val, clk_base + pllu->ext_misc_reg[1]); udelay(1); return; } /* set IDDQ, enable lock detect */ writel_relaxed(PLLU_MISC0_DEFAULT_VALUE, clk_base + pllu->ext_misc_reg[0]); writel_relaxed(PLLU_MISC1_DEFAULT_VALUE, clk_base + pllu->ext_misc_reg[1]); udelay(1); } #define mask(w) ((1 << (w)) - 1) #define divm_mask(p) mask(p->params->div_nmp->divm_width) #define divn_mask(p) mask(p->params->div_nmp->divn_width) #define divp_mask(p) (p->params->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :\ mask(p->params->div_nmp->divp_width)) #define divm_shift(p) ((p)->params->div_nmp->divm_shift) #define divn_shift(p) ((p)->params->div_nmp->divn_shift) #define divp_shift(p) ((p)->params->div_nmp->divp_shift) #define divm_mask_shifted(p) (divm_mask(p) << divm_shift(p)) #define divn_mask_shifted(p) (divn_mask(p) << divn_shift(p)) #define divp_mask_shifted(p) (divp_mask(p) << divp_shift(p)) #define PLL_LOCKDET_DELAY 2 /* Lock detection safety delays */ static int tegra210_wait_for_mask(struct tegra_clk_pll *pll, u32 reg, u32 mask) { int i; u32 val = 0; for (i = 0; i < pll->params->lock_delay / PLL_LOCKDET_DELAY + 1; i++) { udelay(PLL_LOCKDET_DELAY); val = readl_relaxed(clk_base + reg); if ((val & mask) == mask) { udelay(PLL_LOCKDET_DELAY); return 0; } } return -ETIMEDOUT; } static int tegra210_pllx_dyn_ramp(struct tegra_clk_pll *pllx, struct tegra_clk_pll_freq_table *cfg) { u32 val, base, ndiv_new_mask; ndiv_new_mask = (divn_mask(pllx) >> pllx->params->div_nmp->divn_shift) << PLLX_MISC2_NDIV_NEW_SHIFT; val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[2]); val &= (~ndiv_new_mask); val |= cfg->n << PLLX_MISC2_NDIV_NEW_SHIFT; writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); udelay(1); val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[2]); val |= PLLX_MISC2_EN_DYNRAMP; writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); udelay(1); tegra210_wait_for_mask(pllx, pllx->params->ext_misc_reg[2], PLLX_MISC2_DYNRAMP_DONE); base = readl_relaxed(clk_base + pllx->params->base_reg) & (~divn_mask_shifted(pllx)); base |= cfg->n << pllx->params->div_nmp->divn_shift; writel_relaxed(base, clk_base + pllx->params->base_reg); udelay(1); val &= ~PLLX_MISC2_EN_DYNRAMP; writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); udelay(1); pr_debug("%s: dynamic ramp to m = %u n = %u p = %u, Fout = %lu kHz\n", __clk_get_name(pllx->hw.clk), cfg->m, cfg->n, cfg->p, cfg->input_rate / cfg->m * cfg->n / pllx->params->pdiv_tohw[cfg->p].pdiv / 1000); return 0; } /* * Common configuration for PLLs with fixed input divider policy: * - always set fixed M-value based on the reference rate * - always set P-value value 1:1 for output rates above VCO minimum, and * choose minimum necessary P-value for output rates below VCO maximum * - calculate N-value based on selected M and P * - calculate SDM_DIN fractional part */ static int tegra210_pll_fixed_mdiv_cfg(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, unsigned long rate, unsigned long input_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_params *params = pll->params; int p; unsigned long cf, p_rate; u32 pdiv; if (!rate) return -EINVAL; if (!(params->flags & TEGRA_PLL_VCO_OUT)) { p = DIV_ROUND_UP(params->vco_min, rate); p = params->round_p_to_pdiv(p, &pdiv); } else { p = rate >= params->vco_min ? 1 : -EINVAL; } if (p < 0) return -EINVAL; cfg->m = tegra_pll_get_fixed_mdiv(hw, input_rate); cfg->p = p; /* Store P as HW value, as that is what is expected */ cfg->p = tegra_pll_p_div_to_hw(pll, cfg->p); p_rate = rate * p; if (p_rate > params->vco_max) p_rate = params->vco_max; cf = input_rate / cfg->m; cfg->n = p_rate / cf; cfg->sdm_data = 0; cfg->output_rate = input_rate; if (params->sdm_ctrl_reg) { unsigned long rem = p_rate - cf * cfg->n; /* If ssc is enabled SDM enabled as well, even for integer n */ if (rem || params->ssc_ctrl_reg) { u64 s = rem * PLL_SDM_COEFF; do_div(s, cf); s -= PLL_SDM_COEFF / 2; cfg->sdm_data = sdin_din_to_data(s); } cfg->output_rate *= sdin_get_n_eff(cfg); cfg->output_rate /= p * cfg->m * PLL_SDM_COEFF; } else { cfg->output_rate *= cfg->n; cfg->output_rate /= p * cfg->m; } cfg->input_rate = input_rate; return 0; } /* * clk_pll_set_gain - set gain to m, n to calculate correct VCO rate * * @cfg: struct tegra_clk_pll_freq_table * cfg * * For Normal mode: * Fvco = Fref * NDIV / MDIV * * For fractional mode: * Fvco = Fref * (NDIV + 0.5 + SDM_DIN / PLL_SDM_COEFF) / MDIV */ static void tegra210_clk_pll_set_gain(struct tegra_clk_pll_freq_table *cfg) { cfg->n = sdin_get_n_eff(cfg); cfg->m *= PLL_SDM_COEFF; } static unsigned long tegra210_clk_adjust_vco_min(struct tegra_clk_pll_params *params, unsigned long parent_rate) { unsigned long vco_min = params->vco_min; params->vco_min += DIV_ROUND_UP(parent_rate, PLL_SDM_COEFF); vco_min = min(vco_min, params->vco_min); return vco_min; } static struct div_nmp pllx_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 20, .divp_width = 5, }; /* * PLL post divider maps - two types: quasi-linear and exponential * post divider. */ #define PLL_QLIN_PDIV_MAX 16 static const struct pdiv_map pll_qlin_pdiv_to_hw[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 3, .hw_val = 2 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 5, .hw_val = 4 }, { .pdiv = 6, .hw_val = 5 }, { .pdiv = 8, .hw_val = 6 }, { .pdiv = 9, .hw_val = 7 }, { .pdiv = 10, .hw_val = 8 }, { .pdiv = 12, .hw_val = 9 }, { .pdiv = 15, .hw_val = 10 }, { .pdiv = 16, .hw_val = 11 }, { .pdiv = 18, .hw_val = 12 }, { .pdiv = 20, .hw_val = 13 }, { .pdiv = 24, .hw_val = 14 }, { .pdiv = 30, .hw_val = 15 }, { .pdiv = 32, .hw_val = 16 }, }; static u32 pll_qlin_p_to_pdiv(u32 p, u32 *pdiv) { int i; if (p) { for (i = 0; i <= PLL_QLIN_PDIV_MAX; i++) { if (p <= pll_qlin_pdiv_to_hw[i].pdiv) { if (pdiv) *pdiv = i; return pll_qlin_pdiv_to_hw[i].pdiv; } } } return -EINVAL; } #define PLL_EXPO_PDIV_MAX 7 static const struct pdiv_map pll_expo_pdiv_to_hw[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 4, .hw_val = 2 }, { .pdiv = 8, .hw_val = 3 }, { .pdiv = 16, .hw_val = 4 }, { .pdiv = 32, .hw_val = 5 }, { .pdiv = 64, .hw_val = 6 }, { .pdiv = 128, .hw_val = 7 }, }; static u32 pll_expo_p_to_pdiv(u32 p, u32 *pdiv) { if (p) { u32 i = fls(p); if (i == ffs(p)) i--; if (i <= PLL_EXPO_PDIV_MAX) { if (pdiv) *pdiv = i; return 1 << i; } } return -EINVAL; } static struct tegra_clk_pll_freq_table pll_x_freq_table[] = { /* 1 GHz */ { 12000000, 1000000000, 166, 1, 2, 0 }, /* actual: 996.0 MHz */ { 13000000, 1000000000, 153, 1, 2, 0 }, /* actual: 994.0 MHz */ { 38400000, 1000000000, 156, 3, 2, 0 }, /* actual: 998.4 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_x_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 38400000, .vco_min = 1350000000, .vco_max = 3000000000UL, .base_reg = PLLX_BASE, .misc_reg = PLLX_MISC0, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .ext_misc_reg[0] = PLLX_MISC0, .ext_misc_reg[1] = PLLX_MISC1, .ext_misc_reg[2] = PLLX_MISC2, .ext_misc_reg[3] = PLLX_MISC3, .ext_misc_reg[4] = PLLX_MISC4, .ext_misc_reg[5] = PLLX_MISC5, .iddq_reg = PLLX_MISC3, .iddq_bit_idx = PLLXP_IDDQ_BIT, .max_p = PLL_QLIN_PDIV_MAX, .mdiv_default = 2, .dyn_ramp_reg = PLLX_MISC2, .stepa_shift = 16, .stepb_shift = 24, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .div_nmp = &pllx_nmp, .freq_table = pll_x_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, .dyn_ramp = tegra210_pllx_dyn_ramp, .set_defaults = tegra210_pllx_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct div_nmp pllc_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 10, .divn_width = 8, .divp_shift = 20, .divp_width = 5, }; static struct tegra_clk_pll_freq_table pll_cx_freq_table[] = { { 12000000, 510000000, 85, 1, 2, 0 }, { 13000000, 510000000, 78, 1, 2, 0 }, /* actual: 507.0 MHz */ { 38400000, 510000000, 79, 3, 2, 0 }, /* actual: 505.6 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_c_params = { .input_min = 12000000, .input_max = 700000000, .cf_min = 12000000, .cf_max = 50000000, .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLC_BASE, .misc_reg = PLLC_MISC0, .lock_mask = PLL_BASE_LOCK, .lock_delay = 300, .iddq_reg = PLLC_MISC1, .iddq_bit_idx = PLLCX_IDDQ_BIT, .reset_reg = PLLC_MISC0, .reset_bit_idx = PLLCX_RESET_BIT, .max_p = PLL_QLIN_PDIV_MAX, .ext_misc_reg[0] = PLLC_MISC0, .ext_misc_reg[1] = PLLC_MISC1, .ext_misc_reg[2] = PLLC_MISC2, .ext_misc_reg[3] = PLLC_MISC3, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .mdiv_default = 3, .div_nmp = &pllc_nmp, .freq_table = pll_cx_freq_table, .flags = TEGRA_PLL_USE_LOCK, .set_defaults = _pllc_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct div_nmp pllcx_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 10, .divn_width = 8, .divp_shift = 20, .divp_width = 5, }; static struct tegra_clk_pll_params pll_c2_params = { .input_min = 12000000, .input_max = 700000000, .cf_min = 12000000, .cf_max = 50000000, .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLC2_BASE, .misc_reg = PLLC2_MISC0, .iddq_reg = PLLC2_MISC1, .iddq_bit_idx = PLLCX_IDDQ_BIT, .reset_reg = PLLC2_MISC0, .reset_bit_idx = PLLCX_RESET_BIT, .lock_mask = PLLCX_BASE_LOCK, .lock_delay = 300, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .mdiv_default = 3, .div_nmp = &pllcx_nmp, .max_p = PLL_QLIN_PDIV_MAX, .ext_misc_reg[0] = PLLC2_MISC0, .ext_misc_reg[1] = PLLC2_MISC1, .ext_misc_reg[2] = PLLC2_MISC2, .ext_misc_reg[3] = PLLC2_MISC3, .freq_table = pll_cx_freq_table, .flags = TEGRA_PLL_USE_LOCK, .set_defaults = _pllc2_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct tegra_clk_pll_params pll_c3_params = { .input_min = 12000000, .input_max = 700000000, .cf_min = 12000000, .cf_max = 50000000, .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLC3_BASE, .misc_reg = PLLC3_MISC0, .lock_mask = PLLCX_BASE_LOCK, .lock_delay = 300, .iddq_reg = PLLC3_MISC1, .iddq_bit_idx = PLLCX_IDDQ_BIT, .reset_reg = PLLC3_MISC0, .reset_bit_idx = PLLCX_RESET_BIT, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .mdiv_default = 3, .div_nmp = &pllcx_nmp, .max_p = PLL_QLIN_PDIV_MAX, .ext_misc_reg[0] = PLLC3_MISC0, .ext_misc_reg[1] = PLLC3_MISC1, .ext_misc_reg[2] = PLLC3_MISC2, .ext_misc_reg[3] = PLLC3_MISC3, .freq_table = pll_cx_freq_table, .flags = TEGRA_PLL_USE_LOCK, .set_defaults = _pllc3_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct div_nmp pllss_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 19, .divp_width = 5, }; static struct tegra_clk_pll_freq_table pll_c4_vco_freq_table[] = { { 12000000, 600000000, 50, 1, 1, 0 }, { 13000000, 600000000, 46, 1, 1, 0 }, /* actual: 598.0 MHz */ { 38400000, 600000000, 62, 4, 1, 0 }, /* actual: 595.2 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static const struct clk_div_table pll_vco_post_div_table[] = { { .val = 0, .div = 1 }, { .val = 1, .div = 2 }, { .val = 2, .div = 3 }, { .val = 3, .div = 4 }, { .val = 4, .div = 5 }, { .val = 5, .div = 6 }, { .val = 6, .div = 8 }, { .val = 7, .div = 10 }, { .val = 8, .div = 12 }, { .val = 9, .div = 16 }, { .val = 10, .div = 12 }, { .val = 11, .div = 16 }, { .val = 12, .div = 20 }, { .val = 13, .div = 24 }, { .val = 14, .div = 32 }, { .val = 0, .div = 0 }, }; static struct tegra_clk_pll_params pll_c4_vco_params = { .input_min = 9600000, .input_max = 800000000, .cf_min = 9600000, .cf_max = 19200000, .vco_min = 500000000, .vco_max = 1080000000, .base_reg = PLLC4_BASE, .misc_reg = PLLC4_MISC0, .lock_mask = PLL_BASE_LOCK, .lock_delay = 300, .max_p = PLL_QLIN_PDIV_MAX, .ext_misc_reg[0] = PLLC4_MISC0, .iddq_reg = PLLC4_BASE, .iddq_bit_idx = PLLSS_IDDQ_BIT, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .mdiv_default = 3, .div_nmp = &pllss_nmp, .freq_table = pll_c4_vco_freq_table, .set_defaults = tegra210_pllc4_set_defaults, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct tegra_clk_pll_freq_table pll_m_freq_table[] = { { 12000000, 800000000, 66, 1, 1, 0 }, /* actual: 792.0 MHz */ { 13000000, 800000000, 61, 1, 1, 0 }, /* actual: 793.0 MHz */ { 38400000, 297600000, 93, 4, 3, 0 }, { 38400000, 400000000, 125, 4, 3, 0 }, { 38400000, 532800000, 111, 4, 2, 0 }, { 38400000, 665600000, 104, 3, 2, 0 }, { 38400000, 800000000, 125, 3, 2, 0 }, { 38400000, 931200000, 97, 4, 1, 0 }, { 38400000, 1065600000, 111, 4, 1, 0 }, { 38400000, 1200000000, 125, 4, 1, 0 }, { 38400000, 1331200000, 104, 3, 1, 0 }, { 38400000, 1459200000, 76, 2, 1, 0 }, { 38400000, 1600000000, 125, 3, 1, 0 }, { 0, 0, 0, 0, 0, 0 }, }; static struct div_nmp pllm_nmp = { .divm_shift = 0, .divm_width = 8, .override_divm_shift = 0, .divn_shift = 8, .divn_width = 8, .override_divn_shift = 8, .divp_shift = 20, .divp_width = 5, .override_divp_shift = 27, }; static struct tegra_clk_pll_params pll_m_params = { .input_min = 9600000, .input_max = 500000000, .cf_min = 9600000, .cf_max = 19200000, .vco_min = 800000000, .vco_max = 1866000000, .base_reg = PLLM_BASE, .misc_reg = PLLM_MISC2, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLM_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLM_MISC2, .iddq_bit_idx = PLLM_IDDQ_BIT, .max_p = PLL_QLIN_PDIV_MAX, .ext_misc_reg[0] = PLLM_MISC2, .ext_misc_reg[1] = PLLM_MISC1, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .div_nmp = &pllm_nmp, .pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE, .pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE_2, .freq_table = pll_m_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct tegra_clk_pll_params pll_mb_params = { .input_min = 9600000, .input_max = 500000000, .cf_min = 9600000, .cf_max = 19200000, .vco_min = 800000000, .vco_max = 1866000000, .base_reg = PLLMB_BASE, .misc_reg = PLLMB_MISC1, .lock_mask = PLL_BASE_LOCK, .lock_delay = 300, .iddq_reg = PLLMB_MISC1, .iddq_bit_idx = PLLMB_IDDQ_BIT, .max_p = PLL_QLIN_PDIV_MAX, .ext_misc_reg[0] = PLLMB_MISC1, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .div_nmp = &pllm_nmp, .freq_table = pll_m_freq_table, .flags = TEGRA_PLL_USE_LOCK, .set_defaults = tegra210_pllmb_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct tegra_clk_pll_freq_table pll_e_freq_table[] = { /* PLLE special case: use cpcon field to store cml divider value */ { 672000000, 100000000, 125, 42, 0, 13 }, { 624000000, 100000000, 125, 39, 0, 13 }, { 336000000, 100000000, 125, 21, 0, 13 }, { 312000000, 100000000, 200, 26, 0, 14 }, { 38400000, 100000000, 125, 2, 0, 14 }, { 12000000, 100000000, 200, 1, 0, 14 }, { 0, 0, 0, 0, 0, 0 }, }; static struct div_nmp plle_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 24, .divp_width = 5, }; static struct tegra_clk_pll_params pll_e_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 38400000, .vco_min = 1600000000, .vco_max = 2500000000U, .base_reg = PLLE_BASE, .misc_reg = PLLE_MISC0, .aux_reg = PLLE_AUX, .lock_mask = PLLE_MISC_LOCK, .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE, .lock_delay = 300, .div_nmp = &plle_nmp, .freq_table = pll_e_freq_table, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, .fixed_rate = 100000000, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct tegra_clk_pll_freq_table pll_re_vco_freq_table[] = { { 12000000, 672000000, 56, 1, 1, 0 }, { 13000000, 672000000, 51, 1, 1, 0 }, /* actual: 663.0 MHz */ { 38400000, 672000000, 70, 4, 1, 0 }, { 0, 0, 0, 0, 0, 0 }, }; static struct div_nmp pllre_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 16, .divp_width = 5, }; static struct tegra_clk_pll_params pll_re_vco_params = { .input_min = 9600000, .input_max = 800000000, .cf_min = 9600000, .cf_max = 19200000, .vco_min = 350000000, .vco_max = 700000000, .base_reg = PLLRE_BASE, .misc_reg = PLLRE_MISC0, .lock_mask = PLLRE_MISC_LOCK, .lock_delay = 300, .max_p = PLL_QLIN_PDIV_MAX, .ext_misc_reg[0] = PLLRE_MISC0, .iddq_reg = PLLRE_MISC0, .iddq_bit_idx = PLLRE_IDDQ_BIT, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .div_nmp = &pllre_nmp, .freq_table = pll_re_vco_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_VCO_OUT, .set_defaults = tegra210_pllre_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct div_nmp pllp_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 10, .divn_width = 8, .divp_shift = 20, .divp_width = 5, }; static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { { 12000000, 408000000, 34, 1, 1, 0 }, { 38400000, 408000000, 85, 8, 1, 0 }, /* cf = 4.8MHz, allowed exception */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_p_params = { .input_min = 9600000, .input_max = 800000000, .cf_min = 9600000, .cf_max = 19200000, .vco_min = 350000000, .vco_max = 700000000, .base_reg = PLLP_BASE, .misc_reg = PLLP_MISC0, .lock_mask = PLL_BASE_LOCK, .lock_delay = 300, .iddq_reg = PLLP_MISC0, .iddq_bit_idx = PLLXP_IDDQ_BIT, .ext_misc_reg[0] = PLLP_MISC0, .ext_misc_reg[1] = PLLP_MISC1, .div_nmp = &pllp_nmp, .freq_table = pll_p_freq_table, .fixed_rate = 408000000, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT, .set_defaults = tegra210_pllp_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct tegra_clk_pll_params pll_a1_params = { .input_min = 12000000, .input_max = 700000000, .cf_min = 12000000, .cf_max = 50000000, .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLA1_BASE, .misc_reg = PLLA1_MISC0, .lock_mask = PLLCX_BASE_LOCK, .lock_delay = 300, .iddq_reg = PLLA1_MISC1, .iddq_bit_idx = PLLCX_IDDQ_BIT, .reset_reg = PLLA1_MISC0, .reset_bit_idx = PLLCX_RESET_BIT, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .div_nmp = &pllc_nmp, .ext_misc_reg[0] = PLLA1_MISC0, .ext_misc_reg[1] = PLLA1_MISC1, .ext_misc_reg[2] = PLLA1_MISC2, .ext_misc_reg[3] = PLLA1_MISC3, .freq_table = pll_cx_freq_table, .flags = TEGRA_PLL_USE_LOCK, .set_defaults = _plla1_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, }; static struct div_nmp plla_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 20, .divp_width = 5, }; static struct tegra_clk_pll_freq_table pll_a_freq_table[] = { { 12000000, 282240000, 47, 1, 2, 1, 0xf148 }, /* actual: 282240234 */ { 12000000, 368640000, 61, 1, 2, 1, 0xfe15 }, /* actual: 368640381 */ { 12000000, 240000000, 60, 1, 3, 1, 0 }, { 13000000, 282240000, 43, 1, 2, 1, 0xfd7d }, /* actual: 282239807 */ { 13000000, 368640000, 56, 1, 2, 1, 0x06d8 }, /* actual: 368640137 */ { 13000000, 240000000, 55, 1, 3, 1, 0 }, /* actual: 238.3 MHz */ { 38400000, 282240000, 44, 3, 2, 1, 0xf333 }, /* actual: 282239844 */ { 38400000, 368640000, 57, 3, 2, 1, 0x0333 }, /* actual: 368639844 */ { 38400000, 240000000, 75, 3, 3, 1, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_a_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 19200000, .vco_min = 500000000, .vco_max = 1000000000, .base_reg = PLLA_BASE, .misc_reg = PLLA_MISC0, .lock_mask = PLL_BASE_LOCK, .lock_delay = 300, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .iddq_reg = PLLA_BASE, .iddq_bit_idx = PLLA_IDDQ_BIT, .div_nmp = &plla_nmp, .sdm_din_reg = PLLA_MISC1, .sdm_din_mask = PLLA_SDM_DIN_MASK, .sdm_ctrl_reg = PLLA_MISC2, .sdm_ctrl_en_mask = PLLA_SDM_EN_MASK, .ext_misc_reg[0] = PLLA_MISC0, .ext_misc_reg[1] = PLLA_MISC1, .ext_misc_reg[2] = PLLA_MISC2, .freq_table = pll_a_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_MDIV_NEW, .set_defaults = tegra210_plla_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, .set_gain = tegra210_clk_pll_set_gain, .adjust_vco = tegra210_clk_adjust_vco_min, }; static struct div_nmp plld_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 11, .divn_width = 8, .divp_shift = 20, .divp_width = 3, }; static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { { 12000000, 594000000, 99, 1, 2, 0, 0 }, { 13000000, 594000000, 91, 1, 2, 0, 0xfc4f }, /* actual: 594000183 */ { 38400000, 594000000, 30, 1, 2, 0, 0x0e00 }, { 0, 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_d_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 38400000, .vco_min = 750000000, .vco_max = 1500000000, .base_reg = PLLD_BASE, .misc_reg = PLLD_MISC0, .lock_mask = PLL_BASE_LOCK, .lock_delay = 1000, .iddq_reg = PLLD_MISC0, .iddq_bit_idx = PLLD_IDDQ_BIT, .round_p_to_pdiv = pll_expo_p_to_pdiv, .pdiv_tohw = pll_expo_pdiv_to_hw, .div_nmp = &plld_nmp, .sdm_din_reg = PLLD_MISC0, .sdm_din_mask = PLLA_SDM_DIN_MASK, .sdm_ctrl_reg = PLLD_MISC0, .sdm_ctrl_en_mask = PLLD_SDM_EN_MASK, .ext_misc_reg[0] = PLLD_MISC0, .ext_misc_reg[1] = PLLD_MISC1, .freq_table = pll_d_freq_table, .flags = TEGRA_PLL_USE_LOCK, .mdiv_default = 1, .set_defaults = tegra210_plld_set_defaults, .calc_rate = tegra210_pll_fixed_mdiv_cfg, .set_gain = tegra210_clk_pll_set_gain, .adjust_vco = tegra210_clk_adjust_vco_min, }; static struct tegra_clk_pll_freq_table tegra210_pll_d2_freq_table[] = { { 12000000, 594000000, 99, 1, 2, 0, 0xf000 }, { 13000000, 594000000, 91, 1, 2, 0, 0xfc4f }, /* actual: 594000183 */ { 38400000, 594000000, 30, 1, 2, 0, 0x0e00 }, { 0, 0, 0, 0, 0, 0, 0 }, }; /* s/w policy, always tegra_pll_ref */ static struct tegra_clk_pll_params pll_d2_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 38400000, .vco_min = 750000000, .vco_max = 1500000000, .base_reg = PLLD2_BASE, .misc_reg = PLLD2_MISC0, .lock_mask = PLL_BASE_LOCK, .lock_delay = 300, .iddq_reg = PLLD2_BASE, .iddq_bit_idx = PLLSS_IDDQ_BIT, .sdm_din_reg = PLLD2_MISC3, .sdm_din_mask = PLLA_SDM_DIN_MASK, .sdm_ctrl_reg = PLLD2_MISC1, .sdm_ctrl_en_mask = PLLD2_SDM_EN_MASK, /* disable spread-spectrum for pll_d2 */ .ssc_ctrl_reg = 0, .ssc_ctrl_en_mask = 0, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .div_nmp = &pllss_nmp, .ext_misc_reg[0] = PLLD2_MISC0, .ext_misc_reg[1] = PLLD2_MISC1, .ext_misc_reg[2] = PLLD2_MISC2, .ext_misc_reg[3] = PLLD2_MISC3, .max_p = PLL_QLIN_PDIV_MAX, .mdiv_default = 1, .freq_table = tegra210_pll_d2_freq_table, .set_defaults = tegra210_plld2_set_defaults, .flags = TEGRA_PLL_USE_LOCK, .calc_rate = tegra210_pll_fixed_mdiv_cfg, .set_gain = tegra210_clk_pll_set_gain, .adjust_vco = tegra210_clk_adjust_vco_min, }; static struct tegra_clk_pll_freq_table pll_dp_freq_table[] = { { 12000000, 270000000, 90, 1, 4, 0, 0xf000 }, { 13000000, 270000000, 83, 1, 4, 0, 0xf000 }, /* actual: 269.8 MHz */ { 38400000, 270000000, 28, 1, 4, 0, 0xf400 }, { 0, 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_dp_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 38400000, .vco_min = 750000000, .vco_max = 1500000000, .base_reg = PLLDP_BASE, .misc_reg = PLLDP_MISC, .lock_mask = PLL_BASE_LOCK, .lock_delay = 300, .iddq_reg = PLLDP_BASE, .iddq_bit_idx = PLLSS_IDDQ_BIT, .sdm_din_reg = PLLDP_SS_CTRL2, .sdm_din_mask = PLLA_SDM_DIN_MASK, .sdm_ctrl_reg = PLLDP_SS_CFG, .sdm_ctrl_en_mask = PLLDP_SDM_EN_MASK, .ssc_ctrl_reg = PLLDP_SS_CFG, .ssc_ctrl_en_mask = PLLDP_SSC_EN_MASK, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .div_nmp = &pllss_nmp, .ext_misc_reg[0] = PLLDP_MISC, .ext_misc_reg[1] = PLLDP_SS_CFG, .ext_misc_reg[2] = PLLDP_SS_CTRL1, .ext_misc_reg[3] = PLLDP_SS_CTRL2, .max_p = PLL_QLIN_PDIV_MAX, .mdiv_default = 1, .freq_table = pll_dp_freq_table, .set_defaults = tegra210_plldp_set_defaults, .flags = TEGRA_PLL_USE_LOCK, .calc_rate = tegra210_pll_fixed_mdiv_cfg, .set_gain = tegra210_clk_pll_set_gain, .adjust_vco = tegra210_clk_adjust_vco_min, }; static struct div_nmp pllu_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 16, .divp_width = 5, }; static struct tegra_clk_pll_freq_table pll_u_freq_table[] = { { 12000000, 480000000, 40, 1, 1, 0 }, { 13000000, 480000000, 36, 1, 1, 0 }, /* actual: 468.0 MHz */ { 38400000, 480000000, 25, 2, 1, 0 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_u_vco_params = { .input_min = 9600000, .input_max = 800000000, .cf_min = 9600000, .cf_max = 19200000, .vco_min = 350000000, .vco_max = 700000000, .base_reg = PLLU_BASE, .misc_reg = PLLU_MISC0, .lock_mask = PLL_BASE_LOCK, .lock_delay = 1000, .iddq_reg = PLLU_MISC0, .iddq_bit_idx = PLLU_IDDQ_BIT, .ext_misc_reg[0] = PLLU_MISC0, .ext_misc_reg[1] = PLLU_MISC1, .round_p_to_pdiv = pll_qlin_p_to_pdiv, .pdiv_tohw = pll_qlin_pdiv_to_hw, .div_nmp = &pllu_nmp, .freq_table = pll_u_freq_table, .flags = TEGRA_PLLU | TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT, }; struct utmi_clk_param { /* Oscillator Frequency in KHz */ u32 osc_frequency; /* UTMIP PLL Enable Delay Count */ u8 enable_delay_count; /* UTMIP PLL Stable count */ u16 stable_count; /* UTMIP PLL Active delay count */ u8 active_delay_count; /* UTMIP PLL Xtal frequency count */ u16 xtal_freq_count; }; static const struct utmi_clk_param utmi_parameters[] = { { .osc_frequency = 38400000, .enable_delay_count = 0x0, .stable_count = 0x0, .active_delay_count = 0x6, .xtal_freq_count = 0x80 }, { .osc_frequency = 13000000, .enable_delay_count = 0x02, .stable_count = 0x33, .active_delay_count = 0x05, .xtal_freq_count = 0x7f }, { .osc_frequency = 19200000, .enable_delay_count = 0x03, .stable_count = 0x4b, .active_delay_count = 0x06, .xtal_freq_count = 0xbb }, { .osc_frequency = 12000000, .enable_delay_count = 0x02, .stable_count = 0x2f, .active_delay_count = 0x08, .xtal_freq_count = 0x76 }, { .osc_frequency = 26000000, .enable_delay_count = 0x04, .stable_count = 0x66, .active_delay_count = 0x09, .xtal_freq_count = 0xfe }, { .osc_frequency = 16800000, .enable_delay_count = 0x03, .stable_count = 0x41, .active_delay_count = 0x0a, .xtal_freq_count = 0xa4 }, }; static struct tegra_clk tegra210_clks[tegra_clk_max] __initdata = { [tegra_clk_ispb] = { .dt_id = TEGRA210_CLK_ISPB, .present = true }, [tegra_clk_rtc] = { .dt_id = TEGRA210_CLK_RTC, .present = true }, [tegra_clk_timer] = { .dt_id = TEGRA210_CLK_TIMER, .present = true }, [tegra_clk_uarta_8] = { .dt_id = TEGRA210_CLK_UARTA, .present = true }, [tegra_clk_i2s1] = { .dt_id = TEGRA210_CLK_I2S1, .present = true }, [tegra_clk_i2c1] = { .dt_id = TEGRA210_CLK_I2C1, .present = true }, [tegra_clk_sdmmc1_9] = { .dt_id = TEGRA210_CLK_SDMMC1, .present = true }, [tegra_clk_pwm] = { .dt_id = TEGRA210_CLK_PWM, .present = true }, [tegra_clk_i2s2] = { .dt_id = TEGRA210_CLK_I2S2, .present = true }, [tegra_clk_usbd] = { .dt_id = TEGRA210_CLK_USBD, .present = true }, [tegra_clk_isp_9] = { .dt_id = TEGRA210_CLK_ISP, .present = true }, [tegra_clk_disp2_8] = { .dt_id = TEGRA210_CLK_DISP2, .present = true }, [tegra_clk_disp1_8] = { .dt_id = TEGRA210_CLK_DISP1, .present = true }, [tegra_clk_host1x_9] = { .dt_id = TEGRA210_CLK_HOST1X, .present = true }, [tegra_clk_i2s0] = { .dt_id = TEGRA210_CLK_I2S0, .present = true }, [tegra_clk_apbdma] = { .dt_id = TEGRA210_CLK_APBDMA, .present = true }, [tegra_clk_kfuse] = { .dt_id = TEGRA210_CLK_KFUSE, .present = true }, [tegra_clk_sbc1_9] = { .dt_id = TEGRA210_CLK_SBC1, .present = true }, [tegra_clk_sbc2_9] = { .dt_id = TEGRA210_CLK_SBC2, .present = true }, [tegra_clk_sbc3_9] = { .dt_id = TEGRA210_CLK_SBC3, .present = true }, [tegra_clk_i2c5] = { .dt_id = TEGRA210_CLK_I2C5, .present = true }, [tegra_clk_csi] = { .dt_id = TEGRA210_CLK_CSI, .present = true }, [tegra_clk_i2c2] = { .dt_id = TEGRA210_CLK_I2C2, .present = true }, [tegra_clk_uartc_8] = { .dt_id = TEGRA210_CLK_UARTC, .present = true }, [tegra_clk_mipi_cal] = { .dt_id = TEGRA210_CLK_MIPI_CAL, .present = true }, [tegra_clk_usb2] = { .dt_id = TEGRA210_CLK_USB2, .present = true }, [tegra_clk_bsev] = { .dt_id = TEGRA210_CLK_BSEV, .present = true }, [tegra_clk_uartd_8] = { .dt_id = TEGRA210_CLK_UARTD, .present = true }, [tegra_clk_i2c3] = { .dt_id = TEGRA210_CLK_I2C3, .present = true }, [tegra_clk_sbc4_9] = { .dt_id = TEGRA210_CLK_SBC4, .present = true }, [tegra_clk_sdmmc3_9] = { .dt_id = TEGRA210_CLK_SDMMC3, .present = true }, [tegra_clk_pcie] = { .dt_id = TEGRA210_CLK_PCIE, .present = true }, [tegra_clk_owr_8] = { .dt_id = TEGRA210_CLK_OWR, .present = true }, [tegra_clk_afi] = { .dt_id = TEGRA210_CLK_AFI, .present = true }, [tegra_clk_csite_8] = { .dt_id = TEGRA210_CLK_CSITE, .present = true }, [tegra_clk_soc_therm_8] = { .dt_id = TEGRA210_CLK_SOC_THERM, .present = true }, [tegra_clk_dtv] = { .dt_id = TEGRA210_CLK_DTV, .present = true }, [tegra_clk_i2cslow] = { .dt_id = TEGRA210_CLK_I2CSLOW, .present = true }, [tegra_clk_tsec_8] = { .dt_id = TEGRA210_CLK_TSEC, .present = true }, [tegra_clk_xusb_host] = { .dt_id = TEGRA210_CLK_XUSB_HOST, .present = true }, [tegra_clk_csus] = { .dt_id = TEGRA210_CLK_CSUS, .present = true }, [tegra_clk_mselect] = { .dt_id = TEGRA210_CLK_MSELECT, .present = true }, [tegra_clk_tsensor] = { .dt_id = TEGRA210_CLK_TSENSOR, .present = true }, [tegra_clk_i2s3] = { .dt_id = TEGRA210_CLK_I2S3, .present = true }, [tegra_clk_i2s4] = { .dt_id = TEGRA210_CLK_I2S4, .present = true }, [tegra_clk_i2c4] = { .dt_id = TEGRA210_CLK_I2C4, .present = true }, [tegra_clk_d_audio] = { .dt_id = TEGRA210_CLK_D_AUDIO, .present = true }, [tegra_clk_hda2codec_2x_8] = { .dt_id = TEGRA210_CLK_HDA2CODEC_2X, .present = true }, [tegra_clk_spdif_2x] = { .dt_id = TEGRA210_CLK_SPDIF_2X, .present = true }, [tegra_clk_actmon] = { .dt_id = TEGRA210_CLK_ACTMON, .present = true }, [tegra_clk_extern1] = { .dt_id = TEGRA210_CLK_EXTERN1, .present = true }, [tegra_clk_extern2] = { .dt_id = TEGRA210_CLK_EXTERN2, .present = true }, [tegra_clk_extern3] = { .dt_id = TEGRA210_CLK_EXTERN3, .present = true }, [tegra_clk_sata_oob_8] = { .dt_id = TEGRA210_CLK_SATA_OOB, .present = true }, [tegra_clk_sata_8] = { .dt_id = TEGRA210_CLK_SATA, .present = true }, [tegra_clk_hda_8] = { .dt_id = TEGRA210_CLK_HDA, .present = true }, [tegra_clk_hda2hdmi] = { .dt_id = TEGRA210_CLK_HDA2HDMI, .present = true }, [tegra_clk_cilab] = { .dt_id = TEGRA210_CLK_CILAB, .present = true }, [tegra_clk_cilcd] = { .dt_id = TEGRA210_CLK_CILCD, .present = true }, [tegra_clk_cile] = { .dt_id = TEGRA210_CLK_CILE, .present = true }, [tegra_clk_dsialp] = { .dt_id = TEGRA210_CLK_DSIALP, .present = true }, [tegra_clk_dsiblp] = { .dt_id = TEGRA210_CLK_DSIBLP, .present = true }, [tegra_clk_entropy_8] = { .dt_id = TEGRA210_CLK_ENTROPY, .present = true }, [tegra_clk_xusb_ss] = { .dt_id = TEGRA210_CLK_XUSB_SS, .present = true }, [tegra_clk_i2c6] = { .dt_id = TEGRA210_CLK_I2C6, .present = true }, [tegra_clk_vim2_clk] = { .dt_id = TEGRA210_CLK_VIM2_CLK, .present = true }, [tegra_clk_clk72Mhz_8] = { .dt_id = TEGRA210_CLK_CLK72MHZ, .present = true }, [tegra_clk_vic03_8] = { .dt_id = TEGRA210_CLK_VIC03, .present = true }, [tegra_clk_dpaux] = { .dt_id = TEGRA210_CLK_DPAUX, .present = true }, [tegra_clk_dpaux1] = { .dt_id = TEGRA210_CLK_DPAUX1, .present = true }, [tegra_clk_sor0] = { .dt_id = TEGRA210_CLK_SOR0, .present = true }, [tegra_clk_sor0_out] = { .dt_id = TEGRA210_CLK_SOR0_OUT, .present = true }, [tegra_clk_sor1] = { .dt_id = TEGRA210_CLK_SOR1, .present = true }, [tegra_clk_sor1_out] = { .dt_id = TEGRA210_CLK_SOR1_OUT, .present = true }, [tegra_clk_gpu] = { .dt_id = TEGRA210_CLK_GPU, .present = true }, [tegra_clk_pll_g_ref] = { .dt_id = TEGRA210_CLK_PLL_G_REF, .present = true, }, [tegra_clk_uartb_8] = { .dt_id = TEGRA210_CLK_UARTB, .present = true }, [tegra_clk_spdif_in_8] = { .dt_id = TEGRA210_CLK_SPDIF_IN, .present = true }, [tegra_clk_spdif_out] = { .dt_id = TEGRA210_CLK_SPDIF_OUT, .present = true }, [tegra_clk_vi_10] = { .dt_id = TEGRA210_CLK_VI, .present = true }, [tegra_clk_vi_sensor_8] = { .dt_id = TEGRA210_CLK_VI_SENSOR, .present = true }, [tegra_clk_fuse] = { .dt_id = TEGRA210_CLK_FUSE, .present = true }, [tegra_clk_fuse_burn] = { .dt_id = TEGRA210_CLK_FUSE_BURN, .present = true }, [tegra_clk_clk_32k] = { .dt_id = TEGRA210_CLK_CLK_32K, .present = true }, [tegra_clk_clk_m] = { .dt_id = TEGRA210_CLK_CLK_M, .present = true }, [tegra_clk_osc] = { .dt_id = TEGRA210_CLK_OSC, .present = true }, [tegra_clk_osc_div2] = { .dt_id = TEGRA210_CLK_OSC_DIV2, .present = true }, [tegra_clk_osc_div4] = { .dt_id = TEGRA210_CLK_OSC_DIV4, .present = true }, [tegra_clk_pll_ref] = { .dt_id = TEGRA210_CLK_PLL_REF, .present = true }, [tegra_clk_pll_c] = { .dt_id = TEGRA210_CLK_PLL_C, .present = true }, [tegra_clk_pll_c_out1] = { .dt_id = TEGRA210_CLK_PLL_C_OUT1, .present = true }, [tegra_clk_pll_c2] = { .dt_id = TEGRA210_CLK_PLL_C2, .present = true }, [tegra_clk_pll_c3] = { .dt_id = TEGRA210_CLK_PLL_C3, .present = true }, [tegra_clk_pll_m] = { .dt_id = TEGRA210_CLK_PLL_M, .present = true }, [tegra_clk_pll_p] = { .dt_id = TEGRA210_CLK_PLL_P, .present = true }, [tegra_clk_pll_p_out1] = { .dt_id = TEGRA210_CLK_PLL_P_OUT1, .present = true }, [tegra_clk_pll_p_out3] = { .dt_id = TEGRA210_CLK_PLL_P_OUT3, .present = true }, [tegra_clk_pll_p_out4_cpu] = { .dt_id = TEGRA210_CLK_PLL_P_OUT4, .present = true }, [tegra_clk_pll_p_out_hsio] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_HSIO, .present = true }, [tegra_clk_pll_p_out_xusb] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_XUSB, .present = true }, [tegra_clk_pll_p_out_cpu] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_CPU, .present = true }, [tegra_clk_pll_p_out_adsp] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_ADSP, .present = true }, [tegra_clk_pll_a] = { .dt_id = TEGRA210_CLK_PLL_A, .present = true }, [tegra_clk_pll_a_out0] = { .dt_id = TEGRA210_CLK_PLL_A_OUT0, .present = true }, [tegra_clk_pll_d] = { .dt_id = TEGRA210_CLK_PLL_D, .present = true }, [tegra_clk_pll_d_out0] = { .dt_id = TEGRA210_CLK_PLL_D_OUT0, .present = true }, [tegra_clk_pll_d2] = { .dt_id = TEGRA210_CLK_PLL_D2, .present = true }, [tegra_clk_pll_d2_out0] = { .dt_id = TEGRA210_CLK_PLL_D2_OUT0, .present = true }, [tegra_clk_pll_u] = { .dt_id = TEGRA210_CLK_PLL_U, .present = true }, [tegra_clk_pll_u_out] = { .dt_id = TEGRA210_CLK_PLL_U_OUT, .present = true }, [tegra_clk_pll_u_out1] = { .dt_id = TEGRA210_CLK_PLL_U_OUT1, .present = true }, [tegra_clk_pll_u_out2] = { .dt_id = TEGRA210_CLK_PLL_U_OUT2, .present = true }, [tegra_clk_pll_u_480m] = { .dt_id = TEGRA210_CLK_PLL_U_480M, .present = true }, [tegra_clk_pll_u_60m] = { .dt_id = TEGRA210_CLK_PLL_U_60M, .present = true }, [tegra_clk_pll_u_48m] = { .dt_id = TEGRA210_CLK_PLL_U_48M, .present = true }, [tegra_clk_pll_x] = { .dt_id = TEGRA210_CLK_PLL_X, .present = true }, [tegra_clk_pll_x_out0] = { .dt_id = TEGRA210_CLK_PLL_X_OUT0, .present = true }, [tegra_clk_pll_re_vco] = { .dt_id = TEGRA210_CLK_PLL_RE_VCO, .present = true }, [tegra_clk_pll_re_out] = { .dt_id = TEGRA210_CLK_PLL_RE_OUT, .present = true }, [tegra_clk_spdif_in_sync] = { .dt_id = TEGRA210_CLK_SPDIF_IN_SYNC, .present = true }, [tegra_clk_i2s0_sync] = { .dt_id = TEGRA210_CLK_I2S0_SYNC, .present = true }, [tegra_clk_i2s1_sync] = { .dt_id = TEGRA210_CLK_I2S1_SYNC, .present = true }, [tegra_clk_i2s2_sync] = { .dt_id = TEGRA210_CLK_I2S2_SYNC, .present = true }, [tegra_clk_i2s3_sync] = { .dt_id = TEGRA210_CLK_I2S3_SYNC, .present = true }, [tegra_clk_i2s4_sync] = { .dt_id = TEGRA210_CLK_I2S4_SYNC, .present = true }, [tegra_clk_vimclk_sync] = { .dt_id = TEGRA210_CLK_VIMCLK_SYNC, .present = true }, [tegra_clk_audio0] = { .dt_id = TEGRA210_CLK_AUDIO0, .present = true }, [tegra_clk_audio1] = { .dt_id = TEGRA210_CLK_AUDIO1, .present = true }, [tegra_clk_audio2] = { .dt_id = TEGRA210_CLK_AUDIO2, .present = true }, [tegra_clk_audio3] = { .dt_id = TEGRA210_CLK_AUDIO3, .present = true }, [tegra_clk_audio4] = { .dt_id = TEGRA210_CLK_AUDIO4, .present = true }, [tegra_clk_spdif] = { .dt_id = TEGRA210_CLK_SPDIF, .present = true }, [tegra_clk_xusb_gate] = { .dt_id = TEGRA210_CLK_XUSB_GATE, .present = true }, [tegra_clk_xusb_host_src_8] = { .dt_id = TEGRA210_CLK_XUSB_HOST_SRC, .present = true }, [tegra_clk_xusb_falcon_src_8] = { .dt_id = TEGRA210_CLK_XUSB_FALCON_SRC, .present = true }, [tegra_clk_xusb_fs_src] = { .dt_id = TEGRA210_CLK_XUSB_FS_SRC, .present = true }, [tegra_clk_xusb_ss_src_8] = { .dt_id = TEGRA210_CLK_XUSB_SS_SRC, .present = true }, [tegra_clk_xusb_ss_div2] = { .dt_id = TEGRA210_CLK_XUSB_SS_DIV2, .present = true }, [tegra_clk_xusb_dev_src_8] = { .dt_id = TEGRA210_CLK_XUSB_DEV_SRC, .present = true }, [tegra_clk_xusb_dev] = { .dt_id = TEGRA210_CLK_XUSB_DEV, .present = true }, [tegra_clk_xusb_hs_src_4] = { .dt_id = TEGRA210_CLK_XUSB_HS_SRC, .present = true }, [tegra_clk_xusb_ssp_src] = { .dt_id = TEGRA210_CLK_XUSB_SSP_SRC, .present = true }, [tegra_clk_usb2_hsic_trk] = { .dt_id = TEGRA210_CLK_USB2_HSIC_TRK, .present = true }, [tegra_clk_hsic_trk] = { .dt_id = TEGRA210_CLK_HSIC_TRK, .present = true }, [tegra_clk_usb2_trk] = { .dt_id = TEGRA210_CLK_USB2_TRK, .present = true }, [tegra_clk_sclk] = { .dt_id = TEGRA210_CLK_SCLK, .present = true }, [tegra_clk_sclk_mux] = { .dt_id = TEGRA210_CLK_SCLK_MUX, .present = true }, [tegra_clk_hclk] = { .dt_id = TEGRA210_CLK_HCLK, .present = true }, [tegra_clk_pclk] = { .dt_id = TEGRA210_CLK_PCLK, .present = true }, [tegra_clk_cclk_g] = { .dt_id = TEGRA210_CLK_CCLK_G, .present = true }, [tegra_clk_cclk_lp] = { .dt_id = TEGRA210_CLK_CCLK_LP, .present = true }, [tegra_clk_dfll_ref] = { .dt_id = TEGRA210_CLK_DFLL_REF, .present = true }, [tegra_clk_dfll_soc] = { .dt_id = TEGRA210_CLK_DFLL_SOC, .present = true }, [tegra_clk_vi_sensor2_8] = { .dt_id = TEGRA210_CLK_VI_SENSOR2, .present = true }, [tegra_clk_pll_p_out5] = { .dt_id = TEGRA210_CLK_PLL_P_OUT5, .present = true }, [tegra_clk_pll_c4] = { .dt_id = TEGRA210_CLK_PLL_C4, .present = true }, [tegra_clk_pll_dp] = { .dt_id = TEGRA210_CLK_PLL_DP, .present = true }, [tegra_clk_audio0_mux] = { .dt_id = TEGRA210_CLK_AUDIO0_MUX, .present = true }, [tegra_clk_audio1_mux] = { .dt_id = TEGRA210_CLK_AUDIO1_MUX, .present = true }, [tegra_clk_audio2_mux] = { .dt_id = TEGRA210_CLK_AUDIO2_MUX, .present = true }, [tegra_clk_audio3_mux] = { .dt_id = TEGRA210_CLK_AUDIO3_MUX, .present = true }, [tegra_clk_audio4_mux] = { .dt_id = TEGRA210_CLK_AUDIO4_MUX, .present = true }, [tegra_clk_spdif_mux] = { .dt_id = TEGRA210_CLK_SPDIF_MUX, .present = true }, [tegra_clk_maud] = { .dt_id = TEGRA210_CLK_MAUD, .present = true }, [tegra_clk_mipibif] = { .dt_id = TEGRA210_CLK_MIPIBIF, .present = true }, [tegra_clk_qspi] = { .dt_id = TEGRA210_CLK_QSPI, .present = true }, [tegra_clk_sdmmc_legacy] = { .dt_id = TEGRA210_CLK_SDMMC_LEGACY, .present = true }, [tegra_clk_tsecb] = { .dt_id = TEGRA210_CLK_TSECB, .present = true }, [tegra_clk_uartape] = { .dt_id = TEGRA210_CLK_UARTAPE, .present = true }, [tegra_clk_vi_i2c] = { .dt_id = TEGRA210_CLK_VI_I2C, .present = true }, [tegra_clk_ape] = { .dt_id = TEGRA210_CLK_APE, .present = true }, [tegra_clk_dbgapb] = { .dt_id = TEGRA210_CLK_DBGAPB, .present = true }, [tegra_clk_nvdec] = { .dt_id = TEGRA210_CLK_NVDEC, .present = true }, [tegra_clk_nvenc] = { .dt_id = TEGRA210_CLK_NVENC, .present = true }, [tegra_clk_nvjpg] = { .dt_id = TEGRA210_CLK_NVJPG, .present = true }, [tegra_clk_pll_c4_out0] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT0, .present = true }, [tegra_clk_pll_c4_out1] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT1, .present = true }, [tegra_clk_pll_c4_out2] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT2, .present = true }, [tegra_clk_pll_c4_out3] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT3, .present = true }, [tegra_clk_apb2ape] = { .dt_id = TEGRA210_CLK_APB2APE, .present = true }, [tegra_clk_pll_a1] = { .dt_id = TEGRA210_CLK_PLL_A1, .present = true }, [tegra_clk_ispa] = { .dt_id = TEGRA210_CLK_ISPA, .present = true }, [tegra_clk_cec] = { .dt_id = TEGRA210_CLK_CEC, .present = true }, [tegra_clk_dmic1] = { .dt_id = TEGRA210_CLK_DMIC1, .present = true }, [tegra_clk_dmic2] = { .dt_id = TEGRA210_CLK_DMIC2, .present = true }, [tegra_clk_dmic3] = { .dt_id = TEGRA210_CLK_DMIC3, .present = true }, [tegra_clk_dmic1_sync_clk] = { .dt_id = TEGRA210_CLK_DMIC1_SYNC_CLK, .present = true }, [tegra_clk_dmic2_sync_clk] = { .dt_id = TEGRA210_CLK_DMIC2_SYNC_CLK, .present = true }, [tegra_clk_dmic3_sync_clk] = { .dt_id = TEGRA210_CLK_DMIC3_SYNC_CLK, .present = true }, [tegra_clk_dmic1_sync_clk_mux] = { .dt_id = TEGRA210_CLK_DMIC1_SYNC_CLK_MUX, .present = true }, [tegra_clk_dmic2_sync_clk_mux] = { .dt_id = TEGRA210_CLK_DMIC2_SYNC_CLK_MUX, .present = true }, [tegra_clk_dmic3_sync_clk_mux] = { .dt_id = TEGRA210_CLK_DMIC3_SYNC_CLK_MUX, .present = true }, [tegra_clk_dp2] = { .dt_id = TEGRA210_CLK_DP2, .present = true }, [tegra_clk_iqc1] = { .dt_id = TEGRA210_CLK_IQC1, .present = true }, [tegra_clk_iqc2] = { .dt_id = TEGRA210_CLK_IQC2, .present = true }, [tegra_clk_pll_a_out_adsp] = { .dt_id = TEGRA210_CLK_PLL_A_OUT_ADSP, .present = true }, [tegra_clk_pll_a_out0_out_adsp] = { .dt_id = TEGRA210_CLK_PLL_A_OUT0_OUT_ADSP, .present = true }, [tegra_clk_adsp] = { .dt_id = TEGRA210_CLK_ADSP, .present = true }, [tegra_clk_adsp_neon] = { .dt_id = TEGRA210_CLK_ADSP_NEON, .present = true }, }; static struct tegra_devclk devclks[] __initdata = { { .con_id = "clk_m", .dt_id = TEGRA210_CLK_CLK_M }, { .con_id = "pll_ref", .dt_id = TEGRA210_CLK_PLL_REF }, { .con_id = "clk_32k", .dt_id = TEGRA210_CLK_CLK_32K }, { .con_id = "osc", .dt_id = TEGRA210_CLK_OSC }, { .con_id = "osc_div2", .dt_id = TEGRA210_CLK_OSC_DIV2 }, { .con_id = "osc_div4", .dt_id = TEGRA210_CLK_OSC_DIV4 }, { .con_id = "pll_c", .dt_id = TEGRA210_CLK_PLL_C }, { .con_id = "pll_c_out1", .dt_id = TEGRA210_CLK_PLL_C_OUT1 }, { .con_id = "pll_c2", .dt_id = TEGRA210_CLK_PLL_C2 }, { .con_id = "pll_c3", .dt_id = TEGRA210_CLK_PLL_C3 }, { .con_id = "pll_p", .dt_id = TEGRA210_CLK_PLL_P }, { .con_id = "pll_p_out1", .dt_id = TEGRA210_CLK_PLL_P_OUT1 }, { .con_id = "pll_p_out2", .dt_id = TEGRA210_CLK_PLL_P_OUT2 }, { .con_id = "pll_p_out3", .dt_id = TEGRA210_CLK_PLL_P_OUT3 }, { .con_id = "pll_p_out4", .dt_id = TEGRA210_CLK_PLL_P_OUT4 }, { .con_id = "pll_m", .dt_id = TEGRA210_CLK_PLL_M }, { .con_id = "pll_x", .dt_id = TEGRA210_CLK_PLL_X }, { .con_id = "pll_x_out0", .dt_id = TEGRA210_CLK_PLL_X_OUT0 }, { .con_id = "pll_u", .dt_id = TEGRA210_CLK_PLL_U }, { .con_id = "pll_u_out", .dt_id = TEGRA210_CLK_PLL_U_OUT }, { .con_id = "pll_u_out1", .dt_id = TEGRA210_CLK_PLL_U_OUT1 }, { .con_id = "pll_u_out2", .dt_id = TEGRA210_CLK_PLL_U_OUT2 }, { .con_id = "pll_u_480M", .dt_id = TEGRA210_CLK_PLL_U_480M }, { .con_id = "pll_u_60M", .dt_id = TEGRA210_CLK_PLL_U_60M }, { .con_id = "pll_u_48M", .dt_id = TEGRA210_CLK_PLL_U_48M }, { .con_id = "pll_d", .dt_id = TEGRA210_CLK_PLL_D }, { .con_id = "pll_d_out0", .dt_id = TEGRA210_CLK_PLL_D_OUT0 }, { .con_id = "pll_d2", .dt_id = TEGRA210_CLK_PLL_D2 }, { .con_id = "pll_d2_out0", .dt_id = TEGRA210_CLK_PLL_D2_OUT0 }, { .con_id = "pll_a", .dt_id = TEGRA210_CLK_PLL_A }, { .con_id = "pll_a_out0", .dt_id = TEGRA210_CLK_PLL_A_OUT0 }, { .con_id = "pll_re_vco", .dt_id = TEGRA210_CLK_PLL_RE_VCO }, { .con_id = "pll_re_out", .dt_id = TEGRA210_CLK_PLL_RE_OUT }, { .con_id = "spdif_in_sync", .dt_id = TEGRA210_CLK_SPDIF_IN_SYNC }, { .con_id = "i2s0_sync", .dt_id = TEGRA210_CLK_I2S0_SYNC }, { .con_id = "i2s1_sync", .dt_id = TEGRA210_CLK_I2S1_SYNC }, { .con_id = "i2s2_sync", .dt_id = TEGRA210_CLK_I2S2_SYNC }, { .con_id = "i2s3_sync", .dt_id = TEGRA210_CLK_I2S3_SYNC }, { .con_id = "i2s4_sync", .dt_id = TEGRA210_CLK_I2S4_SYNC }, { .con_id = "vimclk_sync", .dt_id = TEGRA210_CLK_VIMCLK_SYNC }, { .con_id = "audio0", .dt_id = TEGRA210_CLK_AUDIO0 }, { .con_id = "audio1", .dt_id = TEGRA210_CLK_AUDIO1 }, { .con_id = "audio2", .dt_id = TEGRA210_CLK_AUDIO2 }, { .con_id = "audio3", .dt_id = TEGRA210_CLK_AUDIO3 }, { .con_id = "audio4", .dt_id = TEGRA210_CLK_AUDIO4 }, { .con_id = "spdif", .dt_id = TEGRA210_CLK_SPDIF }, { .con_id = "spdif_2x", .dt_id = TEGRA210_CLK_SPDIF_2X }, { .con_id = "extern1", .dt_id = TEGRA210_CLK_EXTERN1 }, { .con_id = "extern2", .dt_id = TEGRA210_CLK_EXTERN2 }, { .con_id = "extern3", .dt_id = TEGRA210_CLK_EXTERN3 }, { .con_id = "cclk_g", .dt_id = TEGRA210_CLK_CCLK_G }, { .con_id = "cclk_lp", .dt_id = TEGRA210_CLK_CCLK_LP }, { .con_id = "sclk", .dt_id = TEGRA210_CLK_SCLK }, { .con_id = "hclk", .dt_id = TEGRA210_CLK_HCLK }, { .con_id = "pclk", .dt_id = TEGRA210_CLK_PCLK }, { .con_id = "fuse", .dt_id = TEGRA210_CLK_FUSE }, { .dev_id = "rtc-tegra", .dt_id = TEGRA210_CLK_RTC }, { .dev_id = "timer", .dt_id = TEGRA210_CLK_TIMER }, { .con_id = "pll_c4_out0", .dt_id = TEGRA210_CLK_PLL_C4_OUT0 }, { .con_id = "pll_c4_out1", .dt_id = TEGRA210_CLK_PLL_C4_OUT1 }, { .con_id = "pll_c4_out2", .dt_id = TEGRA210_CLK_PLL_C4_OUT2 }, { .con_id = "pll_c4_out3", .dt_id = TEGRA210_CLK_PLL_C4_OUT3 }, { .con_id = "dpaux", .dt_id = TEGRA210_CLK_DPAUX }, }; static struct tegra_audio_clk_info tegra210_audio_plls[] = { { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_ref" }, { "pll_a1", &pll_a1_params, tegra_clk_pll_a1, "pll_ref" }, }; static const char * const aclk_parents[] = { "pll_a1", "pll_c", "pll_p", "pll_a_out0", "pll_c2", "pll_c3", "clk_m" }; static const unsigned int nvjpg_slcg_clkids[] = { TEGRA210_CLK_NVDEC }; static const unsigned int nvdec_slcg_clkids[] = { TEGRA210_CLK_NVJPG }; static const unsigned int sor_slcg_clkids[] = { TEGRA210_CLK_HDA2CODEC_2X, TEGRA210_CLK_HDA2HDMI, TEGRA210_CLK_DISP1, TEGRA210_CLK_DISP2 }; static const unsigned int disp_slcg_clkids[] = { TEGRA210_CLK_LA, TEGRA210_CLK_HOST1X}; static const unsigned int xusba_slcg_clkids[] = { TEGRA210_CLK_XUSB_HOST, TEGRA210_CLK_XUSB_DEV }; static const unsigned int xusbb_slcg_clkids[] = { TEGRA210_CLK_XUSB_HOST, TEGRA210_CLK_XUSB_SS }; static const unsigned int xusbc_slcg_clkids[] = { TEGRA210_CLK_XUSB_DEV, TEGRA210_CLK_XUSB_SS }; static const unsigned int venc_slcg_clkids[] = { TEGRA210_CLK_HOST1X, TEGRA210_CLK_PLL_D }; static const unsigned int ape_slcg_clkids[] = { TEGRA210_CLK_ACLK, TEGRA210_CLK_I2S0, TEGRA210_CLK_I2S1, TEGRA210_CLK_I2S2, TEGRA210_CLK_I2S3, TEGRA210_CLK_I2S4, TEGRA210_CLK_SPDIF_OUT, TEGRA210_CLK_D_AUDIO }; static const unsigned int vic_slcg_clkids[] = { TEGRA210_CLK_HOST1X }; static struct tegra210_domain_mbist_war tegra210_pg_mbist_war[] = { [TEGRA_POWERGATE_VENC] = { .handle_lvl2_ovr = tegra210_venc_mbist_war, .num_clks = ARRAY_SIZE(venc_slcg_clkids), .clk_init_data = venc_slcg_clkids, }, [TEGRA_POWERGATE_SATA] = { .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRC, .lvl2_mask = BIT(0) | BIT(17) | BIT(19), }, [TEGRA_POWERGATE_MPE] = { .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRE, .lvl2_mask = BIT(29), }, [TEGRA_POWERGATE_SOR] = { .handle_lvl2_ovr = tegra210_generic_mbist_war, .num_clks = ARRAY_SIZE(sor_slcg_clkids), .clk_init_data = sor_slcg_clkids, .lvl2_offset = LVL2_CLK_GATE_OVRA, .lvl2_mask = BIT(1) | BIT(2), }, [TEGRA_POWERGATE_DIS] = { .handle_lvl2_ovr = tegra210_disp_mbist_war, .num_clks = ARRAY_SIZE(disp_slcg_clkids), .clk_init_data = disp_slcg_clkids, }, [TEGRA_POWERGATE_DISB] = { .num_clks = ARRAY_SIZE(disp_slcg_clkids), .clk_init_data = disp_slcg_clkids, .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRA, .lvl2_mask = BIT(2), }, [TEGRA_POWERGATE_XUSBA] = { .num_clks = ARRAY_SIZE(xusba_slcg_clkids), .clk_init_data = xusba_slcg_clkids, .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRC, .lvl2_mask = BIT(30) | BIT(31), }, [TEGRA_POWERGATE_XUSBB] = { .num_clks = ARRAY_SIZE(xusbb_slcg_clkids), .clk_init_data = xusbb_slcg_clkids, .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRC, .lvl2_mask = BIT(30) | BIT(31), }, [TEGRA_POWERGATE_XUSBC] = { .num_clks = ARRAY_SIZE(xusbc_slcg_clkids), .clk_init_data = xusbc_slcg_clkids, .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRC, .lvl2_mask = BIT(30) | BIT(31), }, [TEGRA_POWERGATE_VIC] = { .num_clks = ARRAY_SIZE(vic_slcg_clkids), .clk_init_data = vic_slcg_clkids, .handle_lvl2_ovr = tegra210_vic_mbist_war, }, [TEGRA_POWERGATE_NVDEC] = { .num_clks = ARRAY_SIZE(nvdec_slcg_clkids), .clk_init_data = nvdec_slcg_clkids, .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRE, .lvl2_mask = BIT(9) | BIT(31), }, [TEGRA_POWERGATE_NVJPG] = { .num_clks = ARRAY_SIZE(nvjpg_slcg_clkids), .clk_init_data = nvjpg_slcg_clkids, .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRE, .lvl2_mask = BIT(9) | BIT(31), }, [TEGRA_POWERGATE_AUD] = { .num_clks = ARRAY_SIZE(ape_slcg_clkids), .clk_init_data = ape_slcg_clkids, .handle_lvl2_ovr = tegra210_ape_mbist_war, }, [TEGRA_POWERGATE_VE2] = { .handle_lvl2_ovr = tegra210_generic_mbist_war, .lvl2_offset = LVL2_CLK_GATE_OVRD, .lvl2_mask = BIT(22), }, }; int tegra210_clk_handle_mbist_war(unsigned int id) { int err; struct tegra210_domain_mbist_war *mbist_war; if (id >= ARRAY_SIZE(tegra210_pg_mbist_war)) { WARN(1, "unknown domain id in MBIST WAR handler\n"); return -EINVAL; } mbist_war = &tegra210_pg_mbist_war[id]; if (!mbist_war->handle_lvl2_ovr) return 0; if (mbist_war->num_clks && !mbist_war->clks) return -ENODEV; err = clk_bulk_prepare_enable(mbist_war->num_clks, mbist_war->clks); if (err < 0) return err; mutex_lock(&lvl2_ovr_lock); mbist_war->handle_lvl2_ovr(mbist_war); mutex_unlock(&lvl2_ovr_lock); clk_bulk_disable_unprepare(mbist_war->num_clks, mbist_war->clks); return 0; } void tegra210_put_utmipll_in_iddq(void) { u32 reg; reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); if (reg & UTMIPLL_HW_PWRDN_CFG0_UTMIPLL_LOCK) { pr_err("trying to assert IDDQ while UTMIPLL is locked\n"); return; } reg |= UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE; writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0); } EXPORT_SYMBOL_GPL(tegra210_put_utmipll_in_iddq); void tegra210_put_utmipll_out_iddq(void) { u32 reg; reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); reg &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE; writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0); } EXPORT_SYMBOL_GPL(tegra210_put_utmipll_out_iddq); static void tegra210_utmi_param_configure(void) { u32 reg; int i; for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) { if (osc_freq == utmi_parameters[i].osc_frequency) break; } if (i >= ARRAY_SIZE(utmi_parameters)) { pr_err("%s: Unexpected oscillator freq %lu\n", __func__, osc_freq); return; } reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); reg &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE; writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0); udelay(10); reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2); /* Program UTMIP PLL stable and active counts */ /* [FIXME] arclk_rst.h says WRONG! This should be 1ms -> 0x50 Check! */ reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0); reg |= UTMIP_PLL_CFG2_STABLE_COUNT(utmi_parameters[i].stable_count); reg &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0); reg |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(utmi_parameters[i].active_delay_count); writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2); /* Program UTMIP PLL delay and oscillator frequency counts */ reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1); reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0); reg |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(utmi_parameters[i].enable_delay_count); reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0); reg |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(utmi_parameters[i].xtal_freq_count); reg |= UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN; writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1); /* Remove power downs from UTMIP PLL control bits */ reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1); reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN; reg |= UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP; writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1); udelay(20); /* Enable samplers for SNPS, XUSB_HOST, XUSB_DEV */ reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2); reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP; reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP; reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP; reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN; reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN; reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN; writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2); /* Setup HW control of UTMIPLL */ reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1); reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN; reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP; writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1); reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); reg |= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET; reg &= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL; writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0); udelay(1); reg = readl_relaxed(clk_base + XUSB_PLL_CFG0); reg &= ~XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY; writel_relaxed(reg, clk_base + XUSB_PLL_CFG0); udelay(1); /* Enable HW control UTMIPLL */ reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); reg |= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE; writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0); } static int tegra210_enable_pllu(void) { struct tegra_clk_pll_freq_table *fentry; struct tegra_clk_pll pllu; u32 reg; int ret; for (fentry = pll_u_freq_table; fentry->input_rate; fentry++) { if (fentry->input_rate == pll_ref_freq) break; } if (!fentry->input_rate) { pr_err("Unknown PLL_U reference frequency %lu\n", pll_ref_freq); return -EINVAL; } /* clear IDDQ bit */ pllu.params = &pll_u_vco_params; reg = readl_relaxed(clk_base + pllu.params->ext_misc_reg[0]); reg &= ~BIT(pllu.params->iddq_bit_idx); writel_relaxed(reg, clk_base + pllu.params->ext_misc_reg[0]); fence_udelay(5, clk_base); reg = readl_relaxed(clk_base + PLLU_BASE); reg &= ~GENMASK(20, 0); reg |= fentry->m; reg |= fentry->n << 8; reg |= fentry->p << 16; writel(reg, clk_base + PLLU_BASE); fence_udelay(1, clk_base); reg |= PLL_ENABLE; writel(reg, clk_base + PLLU_BASE); /* * During clocks resume, same PLLU init and enable sequence get * executed. So, readx_poll_timeout_atomic can't be used here as it * uses ktime_get() and timekeeping resume doesn't happen by that * time. So, using tegra210_wait_for_mask for PLL LOCK. */ ret = tegra210_wait_for_mask(&pllu, PLLU_BASE, PLL_BASE_LOCK); if (ret) { pr_err("Timed out waiting for PLL_U to lock\n"); return -ETIMEDOUT; } return 0; } static int tegra210_init_pllu(void) { u32 reg; int err; tegra210_pllu_set_defaults(&pll_u_vco_params); /* skip initialization when pllu is in hw controlled mode */ reg = readl_relaxed(clk_base + PLLU_BASE); if (reg & PLLU_BASE_OVERRIDE) { if (!(reg & PLL_ENABLE)) { err = tegra210_enable_pllu(); if (err < 0) { WARN_ON(1); return err; } } /* enable hw controlled mode */ reg = readl_relaxed(clk_base + PLLU_BASE); reg &= ~PLLU_BASE_OVERRIDE; writel(reg, clk_base + PLLU_BASE); reg = readl_relaxed(clk_base + PLLU_HW_PWRDN_CFG0); reg |= PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE | PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT | PLLU_HW_PWRDN_CFG0_USE_LOCKDET; reg &= ~(PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL | PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL); writel_relaxed(reg, clk_base + PLLU_HW_PWRDN_CFG0); reg = readl_relaxed(clk_base + XUSB_PLL_CFG0); reg &= ~XUSB_PLL_CFG0_PLLU_LOCK_DLY_MASK; writel_relaxed(reg, clk_base + XUSB_PLL_CFG0); fence_udelay(1, clk_base); reg = readl_relaxed(clk_base + PLLU_HW_PWRDN_CFG0); reg |= PLLU_HW_PWRDN_CFG0_SEQ_ENABLE; writel_relaxed(reg, clk_base + PLLU_HW_PWRDN_CFG0); fence_udelay(1, clk_base); reg = readl_relaxed(clk_base + PLLU_BASE); reg &= ~PLLU_BASE_CLKENABLE_USB; writel_relaxed(reg, clk_base + PLLU_BASE); } /* enable UTMIPLL hw control if not yet done by the bootloader */ reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); if (!(reg & UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE)) tegra210_utmi_param_configure(); return 0; } /* * The SOR hardware blocks are driven by two clocks: a module clock that is * used to access registers and a pixel clock that is sourced from the same * pixel clock that also drives the head attached to the SOR. The module * clock is typically called sorX (with X being the SOR instance) and the * pixel clock is called sorX_out. The source for the SOR pixel clock is * referred to as the "parent" clock. * * On Tegra186 and newer, clocks are provided by the BPMP. Unfortunately the * BPMP implementation for the SOR clocks doesn't exactly match the above in * some aspects. For example, the SOR module is really clocked by the pad or * sor_safe clocks, but BPMP models the sorX clock as being sourced by the * pixel clocks. Conversely the sorX_out clock is sourced by the sor_safe or * pad clocks on BPMP. * * In order to allow the display driver to deal with all SoC generations in * a unified way, implement the BPMP semantics in this driver. */ static const char * const sor0_parents[] = { "pll_d_out0", }; static const char * const sor0_out_parents[] = { "sor_safe", "sor0_pad_clkout", }; static const char * const sor1_parents[] = { "pll_p", "pll_d_out0", "pll_d2_out0", "clk_m", }; static u32 sor1_parents_idx[] = { 0, 2, 5, 6 }; static const struct clk_div_table mc_div_table_tegra210[] = { { .val = 0, .div = 2 }, { .val = 1, .div = 4 }, { .val = 2, .div = 1 }, { .val = 3, .div = 2 }, { .val = 0, .div = 0 }, }; static void tegra210_clk_register_mc(const char *name, const char *parent_name) { struct clk *clk; clk = clk_register_divider_table(NULL, name, parent_name, CLK_IS_CRITICAL, clk_base + CLK_SOURCE_EMC, 15, 2, CLK_DIVIDER_READ_ONLY, mc_div_table_tegra210, &emc_lock); clks[TEGRA210_CLK_MC] = clk; } static const char * const sor1_out_parents[] = { /* * Bit 0 of the mux selects sor1_pad_clkout, irrespective of bit 1, so * the sor1_pad_clkout parent appears twice in the list below. This is * merely to support clk_get_parent() if firmware happened to set * these bits to 0b11. While not an invalid setting, code should * always set the bits to 0b01 to select sor1_pad_clkout. */ "sor_safe", "sor1_pad_clkout", "sor1_out", "sor1_pad_clkout", }; static struct tegra_periph_init_data tegra210_periph[] = { /* * On Tegra210, the sor0 clock doesn't have a mux it bitfield 31:29, * but it is hardwired to the pll_d_out0 clock. */ TEGRA_INIT_DATA_TABLE("sor0", NULL, NULL, sor0_parents, CLK_SOURCE_SOR0, 29, 0x0, 0, 0, 0, 0, 0, 182, 0, tegra_clk_sor0, NULL, 0, &sor0_lock), TEGRA_INIT_DATA_TABLE("sor0_out", NULL, NULL, sor0_out_parents, CLK_SOURCE_SOR0, 14, 0x1, 0, 0, 0, 0, 0, 0, TEGRA_PERIPH_NO_GATE, tegra_clk_sor0_out, NULL, 0, &sor0_lock), TEGRA_INIT_DATA_TABLE("sor1", NULL, NULL, sor1_parents, CLK_SOURCE_SOR1, 29, 0x7, 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, 183, 0, tegra_clk_sor1, sor1_parents_idx, 0, &sor1_lock), TEGRA_INIT_DATA_TABLE("sor1_out", NULL, NULL, sor1_out_parents, CLK_SOURCE_SOR1, 14, 0x3, 0, 0, 0, 0, 0, 0, TEGRA_PERIPH_NO_GATE, tegra_clk_sor1_out, NULL, 0, &sor1_lock), }; static const char * const la_parents[] = { "pll_p", "pll_c2", "pll_c", "pll_c3", "pll_re_out1", "pll_a1", "clk_m", "pll_c4_out0" }; static struct tegra_clk_periph tegra210_la = TEGRA_CLK_PERIPH(29, 7, 9, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, 76, 0, NULL, NULL); static __init void tegra210_periph_clk_init(struct device_node *np, void __iomem *clk_base, void __iomem *pmc_base) { struct clk *clk; unsigned int i; /* xusb_ss_div2 */ clk = clk_register_fixed_factor(NULL, "xusb_ss_div2", "xusb_ss_src", 0, 1, 2); clks[TEGRA210_CLK_XUSB_SS_DIV2] = clk; clk = tegra_clk_register_periph_fixed("sor_safe", "pll_p", 0, clk_base, 1, 17, 222); clks[TEGRA210_CLK_SOR_SAFE] = clk; clk = tegra_clk_register_periph_fixed("dpaux", "sor_safe", 0, clk_base, 1, 17, 181); clks[TEGRA210_CLK_DPAUX] = clk; clk = tegra_clk_register_periph_fixed("dpaux1", "sor_safe", 0, clk_base, 1, 17, 207); clks[TEGRA210_CLK_DPAUX1] = clk; /* pll_d_dsi_out */ clk = clk_register_gate(NULL, "pll_d_dsi_out", "pll_d_out0", 0, clk_base + PLLD_MISC0, 21, 0, &pll_d_lock); clks[TEGRA210_CLK_PLL_D_DSI_OUT] = clk; /* dsia */ clk = tegra_clk_register_periph_gate("dsia", "pll_d_dsi_out", 0, clk_base, 0, 48, periph_clk_enb_refcnt); clks[TEGRA210_CLK_DSIA] = clk; /* dsib */ clk = tegra_clk_register_periph_gate("dsib", "pll_d_dsi_out", 0, clk_base, 0, 82, periph_clk_enb_refcnt); clks[TEGRA210_CLK_DSIB] = clk; /* csi_tpg */ clk = clk_register_gate(NULL, "csi_tpg", "pll_d", CLK_SET_RATE_PARENT, clk_base + PLLD_BASE, 23, 0, &pll_d_lock); clk_register_clkdev(clk, "csi_tpg", NULL); clks[TEGRA210_CLK_CSI_TPG] = clk; /* la */ clk = tegra_clk_register_periph("la", la_parents, ARRAY_SIZE(la_parents), &tegra210_la, clk_base, CLK_SOURCE_LA, 0); clks[TEGRA210_CLK_LA] = clk; /* cml0 */ clk = clk_register_gate(NULL, "cml0", "pll_e", 0, clk_base + PLLE_AUX, 0, 0, &pll_e_lock); clk_register_clkdev(clk, "cml0", NULL); clks[TEGRA210_CLK_CML0] = clk; /* cml1 */ clk = clk_register_gate(NULL, "cml1", "pll_e", 0, clk_base + PLLE_AUX, 1, 0, &pll_e_lock); clk_register_clkdev(clk, "cml1", NULL); clks[TEGRA210_CLK_CML1] = clk; clk = tegra_clk_register_super_clk("aclk", aclk_parents, ARRAY_SIZE(aclk_parents), 0, clk_base + 0x6e0, 0, NULL); clks[TEGRA210_CLK_ACLK] = clk; clk = tegra_clk_register_sdmmc_mux_div("sdmmc2", clk_base, CLK_SOURCE_SDMMC2, 9, TEGRA_DIVIDER_ROUND_UP, 0, NULL); clks[TEGRA210_CLK_SDMMC2] = clk; clk = tegra_clk_register_sdmmc_mux_div("sdmmc4", clk_base, CLK_SOURCE_SDMMC4, 15, TEGRA_DIVIDER_ROUND_UP, 0, NULL); clks[TEGRA210_CLK_SDMMC4] = clk; for (i = 0; i < ARRAY_SIZE(tegra210_periph); i++) { struct tegra_periph_init_data *init = &tegra210_periph[i]; struct clk **clkp; clkp = tegra_lookup_dt_id(init->clk_id, tegra210_clks); if (!clkp) { pr_warn("clock %u not found\n", init->clk_id); continue; } clk = tegra_clk_register_periph_data(clk_base, init); *clkp = clk; } tegra_periph_clk_init(clk_base, pmc_base, tegra210_clks, &pll_p_params); /* emc */ clk = tegra210_clk_register_emc(np, clk_base); clks[TEGRA210_CLK_EMC] = clk; /* mc */ tegra210_clk_register_mc("mc", "emc"); } static void __init tegra210_pll_init(void __iomem *clk_base, void __iomem *pmc) { struct clk *clk; /* PLLC */ clk = tegra_clk_register_pllc_tegra210("pll_c", "pll_ref", clk_base, pmc, 0, &pll_c_params, NULL); if (!WARN_ON(IS_ERR(clk))) clk_register_clkdev(clk, "pll_c", NULL); clks[TEGRA210_CLK_PLL_C] = clk; /* PLLC_OUT1 */ clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c", clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div", clk_base + PLLC_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clk_register_clkdev(clk, "pll_c_out1", NULL); clks[TEGRA210_CLK_PLL_C_OUT1] = clk; /* PLLC_UD */ clk = clk_register_fixed_factor(NULL, "pll_c_ud", "pll_c", CLK_SET_RATE_PARENT, 1, 1); clk_register_clkdev(clk, "pll_c_ud", NULL); clks[TEGRA210_CLK_PLL_C_UD] = clk; /* PLLC2 */ clk = tegra_clk_register_pllc_tegra210("pll_c2", "pll_ref", clk_base, pmc, 0, &pll_c2_params, NULL); clk_register_clkdev(clk, "pll_c2", NULL); clks[TEGRA210_CLK_PLL_C2] = clk; /* PLLC3 */ clk = tegra_clk_register_pllc_tegra210("pll_c3", "pll_ref", clk_base, pmc, 0, &pll_c3_params, NULL); clk_register_clkdev(clk, "pll_c3", NULL); clks[TEGRA210_CLK_PLL_C3] = clk; /* PLLM */ clk = tegra_clk_register_pllm("pll_m", "osc", clk_base, pmc, CLK_SET_RATE_GATE, &pll_m_params, NULL); clk_register_clkdev(clk, "pll_m", NULL); clks[TEGRA210_CLK_PLL_M] = clk; /* PLLMB */ clk = tegra_clk_register_pllmb("pll_mb", "osc", clk_base, pmc, CLK_SET_RATE_GATE, &pll_mb_params, NULL); clk_register_clkdev(clk, "pll_mb", NULL); clks[TEGRA210_CLK_PLL_MB] = clk; /* PLLM_UD */ clk = clk_register_fixed_factor(NULL, "pll_m_ud", "pll_m", CLK_SET_RATE_PARENT, 1, 1); clk_register_clkdev(clk, "pll_m_ud", NULL); clks[TEGRA210_CLK_PLL_M_UD] = clk; /* PLLMB_UD */ clk = clk_register_fixed_factor(NULL, "pll_mb_ud", "pll_mb", CLK_SET_RATE_PARENT, 1, 1); clk_register_clkdev(clk, "pll_mb_ud", NULL); clks[TEGRA210_CLK_PLL_MB_UD] = clk; /* PLLP_UD */ clk = clk_register_fixed_factor(NULL, "pll_p_ud", "pll_p", 0, 1, 1); clks[TEGRA210_CLK_PLL_P_UD] = clk; /* PLLU_VCO */ if (!tegra210_init_pllu()) { clk = clk_register_fixed_rate(NULL, "pll_u_vco", "pll_ref", 0, 480*1000*1000); clk_register_clkdev(clk, "pll_u_vco", NULL); clks[TEGRA210_CLK_PLL_U] = clk; } /* PLLU_OUT */ clk = clk_register_divider_table(NULL, "pll_u_out", "pll_u_vco", 0, clk_base + PLLU_BASE, 16, 4, 0, pll_vco_post_div_table, NULL); clk_register_clkdev(clk, "pll_u_out", NULL); clks[TEGRA210_CLK_PLL_U_OUT] = clk; /* PLLU_OUT1 */ clk = tegra_clk_register_divider("pll_u_out1_div", "pll_u_out", clk_base + PLLU_OUTA, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, &pll_u_lock); clk = tegra_clk_register_pll_out("pll_u_out1", "pll_u_out1_div", clk_base + PLLU_OUTA, 1, 0, CLK_SET_RATE_PARENT, 0, &pll_u_lock); clk_register_clkdev(clk, "pll_u_out1", NULL); clks[TEGRA210_CLK_PLL_U_OUT1] = clk; /* PLLU_OUT2 */ clk = tegra_clk_register_divider("pll_u_out2_div", "pll_u_out", clk_base + PLLU_OUTA, 0, TEGRA_DIVIDER_ROUND_UP, 24, 8, 1, &pll_u_lock); clk = tegra_clk_register_pll_out("pll_u_out2", "pll_u_out2_div", clk_base + PLLU_OUTA, 17, 16, CLK_SET_RATE_PARENT, 0, &pll_u_lock); clk_register_clkdev(clk, "pll_u_out2", NULL); clks[TEGRA210_CLK_PLL_U_OUT2] = clk; /* PLLU_480M */ clk = clk_register_gate(NULL, "pll_u_480M", "pll_u_vco", CLK_SET_RATE_PARENT, clk_base + PLLU_BASE, 22, 0, &pll_u_lock); clk_register_clkdev(clk, "pll_u_480M", NULL); clks[TEGRA210_CLK_PLL_U_480M] = clk; /* PLLU_60M */ clk = clk_register_gate(NULL, "pll_u_60M", "pll_u_out2", CLK_SET_RATE_PARENT, clk_base + PLLU_BASE, 23, 0, &pll_u_lock); clk_register_clkdev(clk, "pll_u_60M", NULL); clks[TEGRA210_CLK_PLL_U_60M] = clk; /* PLLU_48M */ clk = clk_register_gate(NULL, "pll_u_48M", "pll_u_out1", CLK_SET_RATE_PARENT, clk_base + PLLU_BASE, 25, 0, &pll_u_lock); clk_register_clkdev(clk, "pll_u_48M", NULL); clks[TEGRA210_CLK_PLL_U_48M] = clk; /* PLLD */ clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc, 0, &pll_d_params, &pll_d_lock); clk_register_clkdev(clk, "pll_d", NULL); clks[TEGRA210_CLK_PLL_D] = clk; /* PLLD_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d", CLK_SET_RATE_PARENT, 1, 2); clk_register_clkdev(clk, "pll_d_out0", NULL); clks[TEGRA210_CLK_PLL_D_OUT0] = clk; /* PLLRE */ clk = tegra_clk_register_pllre_tegra210("pll_re_vco", "pll_ref", clk_base, pmc, 0, &pll_re_vco_params, &pll_re_lock, pll_ref_freq); clk_register_clkdev(clk, "pll_re_vco", NULL); clks[TEGRA210_CLK_PLL_RE_VCO] = clk; clk = clk_register_divider_table(NULL, "pll_re_out", "pll_re_vco", 0, clk_base + PLLRE_BASE, 16, 5, 0, pll_vco_post_div_table, &pll_re_lock); clk_register_clkdev(clk, "pll_re_out", NULL); clks[TEGRA210_CLK_PLL_RE_OUT] = clk; clk = tegra_clk_register_divider("pll_re_out1_div", "pll_re_vco", clk_base + PLLRE_OUT1, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_re_out1", "pll_re_out1_div", clk_base + PLLRE_OUT1, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clks[TEGRA210_CLK_PLL_RE_OUT1] = clk; /* PLLE */ clk = tegra_clk_register_plle_tegra210("pll_e", "pll_ref", clk_base, 0, &pll_e_params, NULL); clk_register_clkdev(clk, "pll_e", NULL); clks[TEGRA210_CLK_PLL_E] = clk; /* PLLC4 */ clk = tegra_clk_register_pllre("pll_c4_vco", "pll_ref", clk_base, pmc, 0, &pll_c4_vco_params, NULL, pll_ref_freq); clk_register_clkdev(clk, "pll_c4_vco", NULL); clks[TEGRA210_CLK_PLL_C4] = clk; /* PLLC4_OUT0 */ clk = clk_register_divider_table(NULL, "pll_c4_out0", "pll_c4_vco", 0, clk_base + PLLC4_BASE, 19, 4, 0, pll_vco_post_div_table, NULL); clk_register_clkdev(clk, "pll_c4_out0", NULL); clks[TEGRA210_CLK_PLL_C4_OUT0] = clk; /* PLLC4_OUT1 */ clk = clk_register_fixed_factor(NULL, "pll_c4_out1", "pll_c4_vco", CLK_SET_RATE_PARENT, 1, 3); clk_register_clkdev(clk, "pll_c4_out1", NULL); clks[TEGRA210_CLK_PLL_C4_OUT1] = clk; /* PLLC4_OUT2 */ clk = clk_register_fixed_factor(NULL, "pll_c4_out2", "pll_c4_vco", CLK_SET_RATE_PARENT, 1, 5); clk_register_clkdev(clk, "pll_c4_out2", NULL); clks[TEGRA210_CLK_PLL_C4_OUT2] = clk; /* PLLC4_OUT3 */ clk = tegra_clk_register_divider("pll_c4_out3_div", "pll_c4_out0", clk_base + PLLC4_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_c4_out3", "pll_c4_out3_div", clk_base + PLLC4_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clk_register_clkdev(clk, "pll_c4_out3", NULL); clks[TEGRA210_CLK_PLL_C4_OUT3] = clk; /* PLLDP */ clk = tegra_clk_register_pllss_tegra210("pll_dp", "pll_ref", clk_base, 0, &pll_dp_params, NULL); clk_register_clkdev(clk, "pll_dp", NULL); clks[TEGRA210_CLK_PLL_DP] = clk; /* PLLD2 */ clk = tegra_clk_register_pllss_tegra210("pll_d2", "pll_ref", clk_base, 0, &pll_d2_params, NULL); clk_register_clkdev(clk, "pll_d2", NULL); clks[TEGRA210_CLK_PLL_D2] = clk; /* PLLD2_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2", CLK_SET_RATE_PARENT, 1, 1); clk_register_clkdev(clk, "pll_d2_out0", NULL); clks[TEGRA210_CLK_PLL_D2_OUT0] = clk; /* PLLP_OUT2 */ clk = clk_register_fixed_factor(NULL, "pll_p_out2", "pll_p", CLK_SET_RATE_PARENT, 1, 2); clk_register_clkdev(clk, "pll_p_out2", NULL); clks[TEGRA210_CLK_PLL_P_OUT2] = clk; } /* Tegra210 CPU clock and reset control functions */ static void tegra210_wait_cpu_in_reset(u32 cpu) { unsigned int reg; do { reg = readl(clk_base + CLK_RST_CONTROLLER_CPU_CMPLX_STATUS); cpu_relax(); } while (!(reg & (1 << cpu))); /* check CPU been reset or not */ } static void tegra210_disable_cpu_clock(u32 cpu) { /* flow controller would take care in the power sequence. */ } #ifdef CONFIG_PM_SLEEP #define car_readl(_base, _off) readl_relaxed(clk_base + (_base) + ((_off) * 4)) #define car_writel(_val, _base, _off) \ writel_relaxed(_val, clk_base + (_base) + ((_off) * 4)) static u32 spare_reg_ctx, misc_clk_enb_ctx, clk_msk_arm_ctx; static u32 cpu_softrst_ctx[3]; static int tegra210_clk_suspend(void) { unsigned int i; clk_save_context(); /* * Save the bootloader configured clock registers SPARE_REG0, * MISC_CLK_ENB, CLK_MASK_ARM, CPU_SOFTRST_CTRL. */ spare_reg_ctx = readl_relaxed(clk_base + SPARE_REG0); misc_clk_enb_ctx = readl_relaxed(clk_base + MISC_CLK_ENB); clk_msk_arm_ctx = readl_relaxed(clk_base + CLK_MASK_ARM); for (i = 0; i < ARRAY_SIZE(cpu_softrst_ctx); i++) cpu_softrst_ctx[i] = car_readl(CPU_SOFTRST_CTRL, i); tegra_clk_periph_suspend(); return 0; } static void tegra210_clk_resume(void) { unsigned int i; tegra_clk_osc_resume(clk_base); /* * Restore the bootloader configured clock registers SPARE_REG0, * MISC_CLK_ENB, CLK_MASK_ARM, CPU_SOFTRST_CTRL from saved context. */ writel_relaxed(spare_reg_ctx, clk_base + SPARE_REG0); writel_relaxed(misc_clk_enb_ctx, clk_base + MISC_CLK_ENB); writel_relaxed(clk_msk_arm_ctx, clk_base + CLK_MASK_ARM); for (i = 0; i < ARRAY_SIZE(cpu_softrst_ctx); i++) car_writel(cpu_softrst_ctx[i], CPU_SOFTRST_CTRL, i); /* * Tegra clock programming sequence recommends peripheral clock to * be enabled prior to changing its clock source and divider to * prevent glitchless frequency switch. * So, enable all peripheral clocks before restoring their source * and dividers. */ writel_relaxed(TEGRA210_CLK_ENB_VLD_MSK_L, clk_base + CLK_OUT_ENB_L); writel_relaxed(TEGRA210_CLK_ENB_VLD_MSK_H, clk_base + CLK_OUT_ENB_H); writel_relaxed(TEGRA210_CLK_ENB_VLD_MSK_U, clk_base + CLK_OUT_ENB_U); writel_relaxed(TEGRA210_CLK_ENB_VLD_MSK_V, clk_base + CLK_OUT_ENB_V); writel_relaxed(TEGRA210_CLK_ENB_VLD_MSK_W, clk_base + CLK_OUT_ENB_W); writel_relaxed(TEGRA210_CLK_ENB_VLD_MSK_X, clk_base + CLK_OUT_ENB_X); writel_relaxed(TEGRA210_CLK_ENB_VLD_MSK_Y, clk_base + CLK_OUT_ENB_Y); /* wait for all writes to happen to have all the clocks enabled */ fence_udelay(2, clk_base); /* restore PLLs and all peripheral clock rates */ tegra210_init_pllu(); clk_restore_context(); /* restore saved context of peripheral clocks and reset state */ tegra_clk_periph_resume(); } static void tegra210_cpu_clock_suspend(void) { /* switch coresite to clk_m, save off original source */ tegra210_cpu_clk_sctx.clk_csite_src = readl(clk_base + CLK_SOURCE_CSITE); writel(3 << 30, clk_base + CLK_SOURCE_CSITE); } static void tegra210_cpu_clock_resume(void) { writel(tegra210_cpu_clk_sctx.clk_csite_src, clk_base + CLK_SOURCE_CSITE); } #endif static struct syscore_ops tegra_clk_syscore_ops = { #ifdef CONFIG_PM_SLEEP .suspend = tegra210_clk_suspend, .resume = tegra210_clk_resume, #endif }; static struct tegra_cpu_car_ops tegra210_cpu_car_ops = { .wait_for_reset = tegra210_wait_cpu_in_reset, .disable_clock = tegra210_disable_cpu_clock, #ifdef CONFIG_PM_SLEEP .suspend = tegra210_cpu_clock_suspend, .resume = tegra210_cpu_clock_resume, #endif }; static const struct of_device_id pmc_match[] __initconst = { { .compatible = "nvidia,tegra210-pmc" }, { }, }; static struct tegra_clk_init_table init_table[] __initdata = { { TEGRA210_CLK_UARTA, TEGRA210_CLK_PLL_P, 408000000, 0 }, { TEGRA210_CLK_UARTB, TEGRA210_CLK_PLL_P, 408000000, 0 }, { TEGRA210_CLK_UARTC, TEGRA210_CLK_PLL_P, 408000000, 0 }, { TEGRA210_CLK_UARTD, TEGRA210_CLK_PLL_P, 408000000, 0 }, { TEGRA210_CLK_PLL_A, TEGRA210_CLK_CLK_MAX, 564480000, 0 }, { TEGRA210_CLK_PLL_A_OUT0, TEGRA210_CLK_CLK_MAX, 11289600, 0 }, { TEGRA210_CLK_I2S0, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA210_CLK_I2S1, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA210_CLK_I2S2, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA210_CLK_I2S3, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA210_CLK_I2S4, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA210_CLK_HOST1X, TEGRA210_CLK_PLL_P, 136000000, 1 }, { TEGRA210_CLK_SCLK_MUX, TEGRA210_CLK_PLL_P, 0, 1 }, { TEGRA210_CLK_SCLK, TEGRA210_CLK_CLK_MAX, 102000000, 0 }, { TEGRA210_CLK_DFLL_SOC, TEGRA210_CLK_PLL_P, 51000000, 1 }, { TEGRA210_CLK_DFLL_REF, TEGRA210_CLK_PLL_P, 51000000, 1 }, { TEGRA210_CLK_SBC4, TEGRA210_CLK_PLL_P, 12000000, 1 }, { TEGRA210_CLK_PLL_U_OUT1, TEGRA210_CLK_CLK_MAX, 48000000, 1 }, { TEGRA210_CLK_XUSB_GATE, TEGRA210_CLK_CLK_MAX, 0, 1 }, { TEGRA210_CLK_XUSB_SS_SRC, TEGRA210_CLK_PLL_U_480M, 120000000, 0 }, { TEGRA210_CLK_XUSB_FS_SRC, TEGRA210_CLK_PLL_U_48M, 48000000, 0 }, { TEGRA210_CLK_XUSB_HS_SRC, TEGRA210_CLK_XUSB_SS_SRC, 120000000, 0 }, { TEGRA210_CLK_XUSB_SSP_SRC, TEGRA210_CLK_XUSB_SS_SRC, 120000000, 0 }, { TEGRA210_CLK_XUSB_FALCON_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 204000000, 0 }, { TEGRA210_CLK_XUSB_HOST_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 }, { TEGRA210_CLK_XUSB_DEV_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 }, { TEGRA210_CLK_SATA, TEGRA210_CLK_PLL_P, 104000000, 0 }, { TEGRA210_CLK_SATA_OOB, TEGRA210_CLK_PLL_P, 204000000, 0 }, { TEGRA210_CLK_MSELECT, TEGRA210_CLK_CLK_MAX, 0, 1 }, { TEGRA210_CLK_CSITE, TEGRA210_CLK_CLK_MAX, 0, 1 }, /* TODO find a way to enable this on-demand */ { TEGRA210_CLK_DBGAPB, TEGRA210_CLK_CLK_MAX, 0, 1 }, { TEGRA210_CLK_TSENSOR, TEGRA210_CLK_CLK_M, 400000, 0 }, { TEGRA210_CLK_I2C1, TEGRA210_CLK_PLL_P, 0, 0 }, { TEGRA210_CLK_I2C2, TEGRA210_CLK_PLL_P, 0, 0 }, { TEGRA210_CLK_I2C3, TEGRA210_CLK_PLL_P, 0, 0 }, { TEGRA210_CLK_I2C4, TEGRA210_CLK_PLL_P, 0, 0 }, { TEGRA210_CLK_I2C5, TEGRA210_CLK_PLL_P, 0, 0 }, { TEGRA210_CLK_I2C6, TEGRA210_CLK_PLL_P, 0, 0 }, { TEGRA210_CLK_PLL_DP, TEGRA210_CLK_CLK_MAX, 270000000, 0 }, { TEGRA210_CLK_SOC_THERM, TEGRA210_CLK_PLL_P, 51000000, 0 }, { TEGRA210_CLK_CCLK_G, TEGRA210_CLK_CLK_MAX, 0, 1 }, { TEGRA210_CLK_PLL_U_OUT2, TEGRA210_CLK_CLK_MAX, 60000000, 1 }, { TEGRA210_CLK_SPDIF_IN_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 }, { TEGRA210_CLK_I2S0_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 }, { TEGRA210_CLK_I2S1_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 }, { TEGRA210_CLK_I2S2_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 }, { TEGRA210_CLK_I2S3_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 }, { TEGRA210_CLK_I2S4_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 }, { TEGRA210_CLK_VIMCLK_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 }, { TEGRA210_CLK_HDA, TEGRA210_CLK_PLL_P, 51000000, 0 }, { TEGRA210_CLK_HDA2CODEC_2X, TEGRA210_CLK_PLL_P, 48000000, 0 }, { TEGRA210_CLK_PWM, TEGRA210_CLK_PLL_P, 48000000, 0 }, /* This MUST be the last entry. */ { TEGRA210_CLK_CLK_MAX, TEGRA210_CLK_CLK_MAX, 0, 0 }, }; /** * tegra210_clock_apply_init_table - initialize clocks on Tegra210 SoCs * * Program an initial clock rate and enable or disable clocks needed * by the rest of the kernel, for Tegra210 SoCs. It is intended to be * called by assigning a pointer to it to tegra_clk_apply_init_table - * this will be called as an arch_initcall. No return value. */ static void __init tegra210_clock_apply_init_table(void) { tegra_init_from_table(init_table, clks, TEGRA210_CLK_CLK_MAX); } /** * tegra210_car_barrier - wait for pending writes to the CAR to complete * * Wait for any outstanding writes to the CAR MMIO space from this CPU * to complete before continuing execution. No return value. */ static void tegra210_car_barrier(void) { readl_relaxed(clk_base + RST_DFLL_DVCO); } /** * tegra210_clock_assert_dfll_dvco_reset - assert the DFLL's DVCO reset * * Assert the reset line of the DFLL's DVCO. No return value. */ static void tegra210_clock_assert_dfll_dvco_reset(void) { u32 v; v = readl_relaxed(clk_base + RST_DFLL_DVCO); v |= (1 << DVFS_DFLL_RESET_SHIFT); writel_relaxed(v, clk_base + RST_DFLL_DVCO); tegra210_car_barrier(); } /** * tegra210_clock_deassert_dfll_dvco_reset - deassert the DFLL's DVCO reset * * Deassert the reset line of the DFLL's DVCO, allowing the DVCO to * operate. No return value. */ static void tegra210_clock_deassert_dfll_dvco_reset(void) { u32 v; v = readl_relaxed(clk_base + RST_DFLL_DVCO); v &= ~(1 << DVFS_DFLL_RESET_SHIFT); writel_relaxed(v, clk_base + RST_DFLL_DVCO); tegra210_car_barrier(); } static int tegra210_reset_assert(unsigned long id) { if (id == TEGRA210_RST_DFLL_DVCO) tegra210_clock_assert_dfll_dvco_reset(); else if (id == TEGRA210_RST_ADSP) writel(GENMASK(26, 21) | BIT(7), clk_base + CLK_RST_CONTROLLER_RST_DEV_Y_SET); else return -EINVAL; return 0; } static int tegra210_reset_deassert(unsigned long id) { if (id == TEGRA210_RST_DFLL_DVCO) tegra210_clock_deassert_dfll_dvco_reset(); else if (id == TEGRA210_RST_ADSP) { writel(BIT(21), clk_base + CLK_RST_CONTROLLER_RST_DEV_Y_CLR); /* * Considering adsp cpu clock (min: 12.5MHZ, max: 1GHz) * a delay of 5us ensures that it's at least * 6 * adsp_cpu_cycle_period long. */ udelay(5); writel(GENMASK(26, 22) | BIT(7), clk_base + CLK_RST_CONTROLLER_RST_DEV_Y_CLR); } else return -EINVAL; return 0; } static void tegra210_mbist_clk_init(void) { unsigned int i, j; for (i = 0; i < ARRAY_SIZE(tegra210_pg_mbist_war); i++) { unsigned int num_clks = tegra210_pg_mbist_war[i].num_clks; struct clk_bulk_data *clk_data; if (!num_clks) continue; clk_data = kmalloc_array(num_clks, sizeof(*clk_data), GFP_KERNEL); if (WARN_ON(!clk_data)) return; tegra210_pg_mbist_war[i].clks = clk_data; for (j = 0; j < num_clks; j++) { int clk_id = tegra210_pg_mbist_war[i].clk_init_data[j]; struct clk *clk = clks[clk_id]; if (WARN(IS_ERR(clk), "clk_id: %d\n", clk_id)) { kfree(clk_data); tegra210_pg_mbist_war[i].clks = NULL; break; } clk_data[j].clk = clk; } } } /** * tegra210_clock_init - Tegra210-specific clock initialization * @np: struct device_node * of the DT node for the SoC CAR IP block * * Register most SoC clocks for the Tegra210 system-on-chip. Intended * to be called by the OF init code when a DT node with the * "nvidia,tegra210-car" string is encountered, and declared with * CLK_OF_DECLARE. No return value. */ static void __init tegra210_clock_init(struct device_node *np) { struct device_node *node; u32 value, clk_m_div; clk_base = of_iomap(np, 0); if (!clk_base) { pr_err("ioremap tegra210 CAR failed\n"); return; } node = of_find_matching_node(NULL, pmc_match); if (!node) { pr_err("Failed to find pmc node\n"); WARN_ON(1); return; } pmc_base = of_iomap(node, 0); of_node_put(node); if (!pmc_base) { pr_err("Can't map pmc registers\n"); WARN_ON(1); return; } ahub_base = ioremap(TEGRA210_AHUB_BASE, SZ_64K); if (!ahub_base) { pr_err("ioremap tegra210 APE failed\n"); return; } dispa_base = ioremap(TEGRA210_DISPA_BASE, SZ_256K); if (!dispa_base) { pr_err("ioremap tegra210 DISPA failed\n"); return; } vic_base = ioremap(TEGRA210_VIC_BASE, SZ_256K); if (!vic_base) { pr_err("ioremap tegra210 VIC failed\n"); return; } clks = tegra_clk_init(clk_base, TEGRA210_CLK_CLK_MAX, TEGRA210_CAR_BANK_COUNT); if (!clks) return; value = readl(clk_base + SPARE_REG0) >> CLK_M_DIVISOR_SHIFT; clk_m_div = (value & CLK_M_DIVISOR_MASK) + 1; if (tegra_osc_clk_init(clk_base, tegra210_clks, tegra210_input_freq, ARRAY_SIZE(tegra210_input_freq), clk_m_div, &osc_freq, &pll_ref_freq) < 0) return; tegra_fixed_clk_init(tegra210_clks); tegra210_pll_init(clk_base, pmc_base); tegra210_periph_clk_init(np, clk_base, pmc_base); tegra_audio_clk_init(clk_base, pmc_base, tegra210_clks, tegra210_audio_plls, ARRAY_SIZE(tegra210_audio_plls), 24576000); /* For Tegra210, PLLD is the only source for DSIA & DSIB */ value = readl(clk_base + PLLD_BASE); value &= ~BIT(25); writel(value, clk_base + PLLD_BASE); tegra_clk_apply_init_table = tegra210_clock_apply_init_table; tegra_super_clk_gen5_init(clk_base, pmc_base, tegra210_clks, &pll_x_params); tegra_init_special_resets(2, tegra210_reset_assert, tegra210_reset_deassert); tegra_add_of_provider(np, of_clk_src_onecell_get); tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); tegra210_mbist_clk_init(); tegra_cpu_car_ops = &tegra210_cpu_car_ops; register_syscore_ops(&tegra_clk_syscore_ops); } CLK_OF_DECLARE(tegra210, "nvidia,tegra210-car", tegra210_clock_init);
linux-master
drivers/clk/tegra/clk-tegra210.c
// SPDX-License-Identifier: GPL-2.0-only /* * Tegra124 DFLL FCPU clock source driver * * Copyright (C) 2012-2019 NVIDIA Corporation. All rights reserved. * * Aleksandr Frid <[email protected]> * Paul Walmsley <[email protected]> */ #include <linux/cpu.h> #include <linux/err.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/regulator/consumer.h> #include <soc/tegra/fuse.h> #include "clk.h" #include "clk-dfll.h" #include "cvb.h" struct dfll_fcpu_data { const unsigned long *cpu_max_freq_table; unsigned int cpu_max_freq_table_size; const struct cvb_table *cpu_cvb_tables; unsigned int cpu_cvb_tables_size; }; /* Maximum CPU frequency, indexed by CPU speedo id */ static const unsigned long tegra124_cpu_max_freq_table[] = { [0] = 2014500000UL, [1] = 2320500000UL, [2] = 2116500000UL, [3] = 2524500000UL, }; static const struct cvb_table tegra124_cpu_cvb_tables[] = { { .speedo_id = -1, .process_id = -1, .min_millivolts = 900, .max_millivolts = 1260, .speedo_scale = 100, .voltage_scale = 1000, .entries = { { 204000000UL, { 1112619, -29295, 402 } }, { 306000000UL, { 1150460, -30585, 402 } }, { 408000000UL, { 1190122, -31865, 402 } }, { 510000000UL, { 1231606, -33155, 402 } }, { 612000000UL, { 1274912, -34435, 402 } }, { 714000000UL, { 1320040, -35725, 402 } }, { 816000000UL, { 1366990, -37005, 402 } }, { 918000000UL, { 1415762, -38295, 402 } }, { 1020000000UL, { 1466355, -39575, 402 } }, { 1122000000UL, { 1518771, -40865, 402 } }, { 1224000000UL, { 1573009, -42145, 402 } }, { 1326000000UL, { 1629068, -43435, 402 } }, { 1428000000UL, { 1686950, -44715, 402 } }, { 1530000000UL, { 1746653, -46005, 402 } }, { 1632000000UL, { 1808179, -47285, 402 } }, { 1734000000UL, { 1871526, -48575, 402 } }, { 1836000000UL, { 1936696, -49855, 402 } }, { 1938000000UL, { 2003687, -51145, 402 } }, { 2014500000UL, { 2054787, -52095, 402 } }, { 2116500000UL, { 2124957, -53385, 402 } }, { 2218500000UL, { 2196950, -54665, 402 } }, { 2320500000UL, { 2270765, -55955, 402 } }, { 2422500000UL, { 2346401, -57235, 402 } }, { 2524500000UL, { 2437299, -58535, 402 } }, { 0UL, { 0, 0, 0 } }, }, .cpu_dfll_data = { .tune0_low = 0x005020ff, .tune0_high = 0x005040ff, .tune1 = 0x00000060, } }, }; static const unsigned long tegra210_cpu_max_freq_table[] = { [0] = 1912500000UL, [1] = 1912500000UL, [2] = 2218500000UL, [3] = 1785000000UL, [4] = 1632000000UL, [5] = 1912500000UL, [6] = 2014500000UL, [7] = 1734000000UL, [8] = 1683000000UL, [9] = 1555500000UL, [10] = 1504500000UL, }; #define CPU_CVB_TABLE \ .speedo_scale = 100, \ .voltage_scale = 1000, \ .entries = { \ { 204000000UL, { 1007452, -23865, 370 } }, \ { 306000000UL, { 1052709, -24875, 370 } }, \ { 408000000UL, { 1099069, -25895, 370 } }, \ { 510000000UL, { 1146534, -26905, 370 } }, \ { 612000000UL, { 1195102, -27915, 370 } }, \ { 714000000UL, { 1244773, -28925, 370 } }, \ { 816000000UL, { 1295549, -29935, 370 } }, \ { 918000000UL, { 1347428, -30955, 370 } }, \ { 1020000000UL, { 1400411, -31965, 370 } }, \ { 1122000000UL, { 1454497, -32975, 370 } }, \ { 1224000000UL, { 1509687, -33985, 370 } }, \ { 1326000000UL, { 1565981, -35005, 370 } }, \ { 1428000000UL, { 1623379, -36015, 370 } }, \ { 1530000000UL, { 1681880, -37025, 370 } }, \ { 1632000000UL, { 1741485, -38035, 370 } }, \ { 1734000000UL, { 1802194, -39055, 370 } }, \ { 1836000000UL, { 1864006, -40065, 370 } }, \ { 1912500000UL, { 1910780, -40815, 370 } }, \ { 2014500000UL, { 1227000, 0, 0 } }, \ { 2218500000UL, { 1227000, 0, 0 } }, \ { 0UL, { 0, 0, 0 } }, \ } #define CPU_CVB_TABLE_XA \ .speedo_scale = 100, \ .voltage_scale = 1000, \ .entries = { \ { 204000000UL, { 1250024, -39785, 565 } }, \ { 306000000UL, { 1297556, -41145, 565 } }, \ { 408000000UL, { 1346718, -42505, 565 } }, \ { 510000000UL, { 1397511, -43855, 565 } }, \ { 612000000UL, { 1449933, -45215, 565 } }, \ { 714000000UL, { 1503986, -46575, 565 } }, \ { 816000000UL, { 1559669, -47935, 565 } }, \ { 918000000UL, { 1616982, -49295, 565 } }, \ { 1020000000UL, { 1675926, -50645, 565 } }, \ { 1122000000UL, { 1736500, -52005, 565 } }, \ { 1224000000UL, { 1798704, -53365, 565 } }, \ { 1326000000UL, { 1862538, -54725, 565 } }, \ { 1428000000UL, { 1928003, -56085, 565 } }, \ { 1530000000UL, { 1995097, -57435, 565 } }, \ { 1606500000UL, { 2046149, -58445, 565 } }, \ { 1632000000UL, { 2063822, -58795, 565 } }, \ { 0UL, { 0, 0, 0 } }, \ } #define CPU_CVB_TABLE_EUCM1 \ .speedo_scale = 100, \ .voltage_scale = 1000, \ .entries = { \ { 204000000UL, { 734429, 0, 0 } }, \ { 306000000UL, { 768191, 0, 0 } }, \ { 408000000UL, { 801953, 0, 0 } }, \ { 510000000UL, { 835715, 0, 0 } }, \ { 612000000UL, { 869477, 0, 0 } }, \ { 714000000UL, { 903239, 0, 0 } }, \ { 816000000UL, { 937001, 0, 0 } }, \ { 918000000UL, { 970763, 0, 0 } }, \ { 1020000000UL, { 1004525, 0, 0 } }, \ { 1122000000UL, { 1038287, 0, 0 } }, \ { 1224000000UL, { 1072049, 0, 0 } }, \ { 1326000000UL, { 1105811, 0, 0 } }, \ { 1428000000UL, { 1130000, 0, 0 } }, \ { 1555500000UL, { 1130000, 0, 0 } }, \ { 1632000000UL, { 1170000, 0, 0 } }, \ { 1734000000UL, { 1227500, 0, 0 } }, \ { 0UL, { 0, 0, 0 } }, \ } #define CPU_CVB_TABLE_EUCM2 \ .speedo_scale = 100, \ .voltage_scale = 1000, \ .entries = { \ { 204000000UL, { 742283, 0, 0 } }, \ { 306000000UL, { 776249, 0, 0 } }, \ { 408000000UL, { 810215, 0, 0 } }, \ { 510000000UL, { 844181, 0, 0 } }, \ { 612000000UL, { 878147, 0, 0 } }, \ { 714000000UL, { 912113, 0, 0 } }, \ { 816000000UL, { 946079, 0, 0 } }, \ { 918000000UL, { 980045, 0, 0 } }, \ { 1020000000UL, { 1014011, 0, 0 } }, \ { 1122000000UL, { 1047977, 0, 0 } }, \ { 1224000000UL, { 1081943, 0, 0 } }, \ { 1326000000UL, { 1090000, 0, 0 } }, \ { 1479000000UL, { 1090000, 0, 0 } }, \ { 1555500000UL, { 1162000, 0, 0 } }, \ { 1683000000UL, { 1195000, 0, 0 } }, \ { 0UL, { 0, 0, 0 } }, \ } #define CPU_CVB_TABLE_EUCM2_JOINT_RAIL \ .speedo_scale = 100, \ .voltage_scale = 1000, \ .entries = { \ { 204000000UL, { 742283, 0, 0 } }, \ { 306000000UL, { 776249, 0, 0 } }, \ { 408000000UL, { 810215, 0, 0 } }, \ { 510000000UL, { 844181, 0, 0 } }, \ { 612000000UL, { 878147, 0, 0 } }, \ { 714000000UL, { 912113, 0, 0 } }, \ { 816000000UL, { 946079, 0, 0 } }, \ { 918000000UL, { 980045, 0, 0 } }, \ { 1020000000UL, { 1014011, 0, 0 } }, \ { 1122000000UL, { 1047977, 0, 0 } }, \ { 1224000000UL, { 1081943, 0, 0 } }, \ { 1326000000UL, { 1090000, 0, 0 } }, \ { 1479000000UL, { 1090000, 0, 0 } }, \ { 1504500000UL, { 1120000, 0, 0 } }, \ { 0UL, { 0, 0, 0 } }, \ } #define CPU_CVB_TABLE_ODN \ .speedo_scale = 100, \ .voltage_scale = 1000, \ .entries = { \ { 204000000UL, { 721094, 0, 0 } }, \ { 306000000UL, { 754040, 0, 0 } }, \ { 408000000UL, { 786986, 0, 0 } }, \ { 510000000UL, { 819932, 0, 0 } }, \ { 612000000UL, { 852878, 0, 0 } }, \ { 714000000UL, { 885824, 0, 0 } }, \ { 816000000UL, { 918770, 0, 0 } }, \ { 918000000UL, { 915716, 0, 0 } }, \ { 1020000000UL, { 984662, 0, 0 } }, \ { 1122000000UL, { 1017608, 0, 0 } }, \ { 1224000000UL, { 1050554, 0, 0 } }, \ { 1326000000UL, { 1083500, 0, 0 } }, \ { 1428000000UL, { 1116446, 0, 0 } }, \ { 1581000000UL, { 1130000, 0, 0 } }, \ { 1683000000UL, { 1168000, 0, 0 } }, \ { 1785000000UL, { 1227500, 0, 0 } }, \ { 0UL, { 0, 0, 0 } }, \ } static struct cvb_table tegra210_cpu_cvb_tables[] = { { .speedo_id = 10, .process_id = 0, .min_millivolts = 840, .max_millivolts = 1120, CPU_CVB_TABLE_EUCM2_JOINT_RAIL, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, .tune_high_min_millivolts = 864, } }, { .speedo_id = 10, .process_id = 1, .min_millivolts = 840, .max_millivolts = 1120, CPU_CVB_TABLE_EUCM2_JOINT_RAIL, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, .tune_high_min_millivolts = 864, } }, { .speedo_id = 9, .process_id = 0, .min_millivolts = 900, .max_millivolts = 1162, CPU_CVB_TABLE_EUCM2, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, } }, { .speedo_id = 9, .process_id = 1, .min_millivolts = 900, .max_millivolts = 1162, CPU_CVB_TABLE_EUCM2, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, } }, { .speedo_id = 8, .process_id = 0, .min_millivolts = 900, .max_millivolts = 1195, CPU_CVB_TABLE_EUCM2, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, } }, { .speedo_id = 8, .process_id = 1, .min_millivolts = 900, .max_millivolts = 1195, CPU_CVB_TABLE_EUCM2, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, } }, { .speedo_id = 7, .process_id = 0, .min_millivolts = 841, .max_millivolts = 1227, CPU_CVB_TABLE_EUCM1, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, .tune_high_min_millivolts = 864, } }, { .speedo_id = 7, .process_id = 1, .min_millivolts = 841, .max_millivolts = 1227, CPU_CVB_TABLE_EUCM1, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, .tune_high_min_millivolts = 864, } }, { .speedo_id = 6, .process_id = 0, .min_millivolts = 870, .max_millivolts = 1150, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune1 = 0x20091d9, } }, { .speedo_id = 6, .process_id = 1, .min_millivolts = 870, .max_millivolts = 1150, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune1 = 0x25501d0, } }, { .speedo_id = 5, .process_id = 0, .min_millivolts = 818, .max_millivolts = 1227, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, .tune_high_min_millivolts = 864, } }, { .speedo_id = 5, .process_id = 1, .min_millivolts = 818, .max_millivolts = 1227, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x25501d0, .tune_high_min_millivolts = 864, } }, { .speedo_id = 4, .process_id = -1, .min_millivolts = 918, .max_millivolts = 1113, CPU_CVB_TABLE_XA, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune1 = 0x17711BD, } }, { .speedo_id = 3, .process_id = 0, .min_millivolts = 825, .max_millivolts = 1227, CPU_CVB_TABLE_ODN, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, .tune_high_min_millivolts = 864, } }, { .speedo_id = 3, .process_id = 1, .min_millivolts = 825, .max_millivolts = 1227, CPU_CVB_TABLE_ODN, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x25501d0, .tune_high_min_millivolts = 864, } }, { .speedo_id = 2, .process_id = 0, .min_millivolts = 870, .max_millivolts = 1227, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune1 = 0x20091d9, } }, { .speedo_id = 2, .process_id = 1, .min_millivolts = 870, .max_millivolts = 1227, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune1 = 0x25501d0, } }, { .speedo_id = 1, .process_id = 0, .min_millivolts = 837, .max_millivolts = 1227, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, .tune_high_min_millivolts = 864, } }, { .speedo_id = 1, .process_id = 1, .min_millivolts = 837, .max_millivolts = 1227, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x25501d0, .tune_high_min_millivolts = 864, } }, { .speedo_id = 0, .process_id = 0, .min_millivolts = 850, .max_millivolts = 1170, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x20091d9, .tune_high_min_millivolts = 864, } }, { .speedo_id = 0, .process_id = 1, .min_millivolts = 850, .max_millivolts = 1170, CPU_CVB_TABLE, .cpu_dfll_data = { .tune0_low = 0xffead0ff, .tune0_high = 0xffead0ff, .tune1 = 0x25501d0, .tune_high_min_millivolts = 864, } }, }; static const struct dfll_fcpu_data tegra124_dfll_fcpu_data = { .cpu_max_freq_table = tegra124_cpu_max_freq_table, .cpu_max_freq_table_size = ARRAY_SIZE(tegra124_cpu_max_freq_table), .cpu_cvb_tables = tegra124_cpu_cvb_tables, .cpu_cvb_tables_size = ARRAY_SIZE(tegra124_cpu_cvb_tables) }; static const struct dfll_fcpu_data tegra210_dfll_fcpu_data = { .cpu_max_freq_table = tegra210_cpu_max_freq_table, .cpu_max_freq_table_size = ARRAY_SIZE(tegra210_cpu_max_freq_table), .cpu_cvb_tables = tegra210_cpu_cvb_tables, .cpu_cvb_tables_size = ARRAY_SIZE(tegra210_cpu_cvb_tables), }; static const struct of_device_id tegra124_dfll_fcpu_of_match[] = { { .compatible = "nvidia,tegra124-dfll", .data = &tegra124_dfll_fcpu_data, }, { .compatible = "nvidia,tegra210-dfll", .data = &tegra210_dfll_fcpu_data }, { }, }; static void get_alignment_from_dt(struct device *dev, struct rail_alignment *align) { if (of_property_read_u32(dev->of_node, "nvidia,pwm-voltage-step-microvolts", &align->step_uv)) align->step_uv = 0; if (of_property_read_u32(dev->of_node, "nvidia,pwm-min-microvolts", &align->offset_uv)) align->offset_uv = 0; } static int get_alignment_from_regulator(struct device *dev, struct rail_alignment *align) { struct regulator *reg = regulator_get(dev, "vdd-cpu"); if (IS_ERR(reg)) return PTR_ERR(reg); align->offset_uv = regulator_list_voltage(reg, 0); align->step_uv = regulator_get_linear_step(reg); regulator_put(reg); return 0; } static int tegra124_dfll_fcpu_probe(struct platform_device *pdev) { int process_id, speedo_id, speedo_value, err; struct tegra_dfll_soc_data *soc; const struct dfll_fcpu_data *fcpu_data; struct rail_alignment align; fcpu_data = of_device_get_match_data(&pdev->dev); if (!fcpu_data) return -ENODEV; process_id = tegra_sku_info.cpu_process_id; speedo_id = tegra_sku_info.cpu_speedo_id; speedo_value = tegra_sku_info.cpu_speedo_value; if (speedo_id >= fcpu_data->cpu_max_freq_table_size) { dev_err(&pdev->dev, "unknown max CPU freq for speedo_id=%d\n", speedo_id); return -ENODEV; } soc = devm_kzalloc(&pdev->dev, sizeof(*soc), GFP_KERNEL); if (!soc) return -ENOMEM; soc->dev = get_cpu_device(0); if (!soc->dev) { dev_err(&pdev->dev, "no CPU0 device\n"); return -ENODEV; } if (of_property_read_bool(pdev->dev.of_node, "nvidia,pwm-to-pmic")) { get_alignment_from_dt(&pdev->dev, &align); } else { err = get_alignment_from_regulator(&pdev->dev, &align); if (err) return err; } soc->max_freq = fcpu_data->cpu_max_freq_table[speedo_id]; soc->cvb = tegra_cvb_add_opp_table(soc->dev, fcpu_data->cpu_cvb_tables, fcpu_data->cpu_cvb_tables_size, &align, process_id, speedo_id, speedo_value, soc->max_freq); soc->alignment = align; if (IS_ERR(soc->cvb)) { dev_err(&pdev->dev, "couldn't add OPP table: %ld\n", PTR_ERR(soc->cvb)); return PTR_ERR(soc->cvb); } err = tegra_dfll_register(pdev, soc); if (err < 0) { tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq); return err; } return 0; } static void tegra124_dfll_fcpu_remove(struct platform_device *pdev) { struct tegra_dfll_soc_data *soc; /* * Note that exiting early here is dangerous as after this function * returns *soc is freed. */ soc = tegra_dfll_unregister(pdev); if (IS_ERR(soc)) return; tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq); } static const struct dev_pm_ops tegra124_dfll_pm_ops = { SET_RUNTIME_PM_OPS(tegra_dfll_runtime_suspend, tegra_dfll_runtime_resume, NULL) SET_SYSTEM_SLEEP_PM_OPS(tegra_dfll_suspend, tegra_dfll_resume) }; static struct platform_driver tegra124_dfll_fcpu_driver = { .probe = tegra124_dfll_fcpu_probe, .remove_new = tegra124_dfll_fcpu_remove, .driver = { .name = "tegra124-dfll", .of_match_table = tegra124_dfll_fcpu_of_match, .pm = &tegra124_dfll_pm_ops, }, }; builtin_platform_driver(tegra124_dfll_fcpu_driver);
linux-master
drivers/clk/tegra/clk-tegra124-dfll-fcpu.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved. */ #include <linux/slab.h> #include <linux/io.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/clk.h> #include <linux/clk-provider.h> #include "clk.h" #define PLL_BASE_BYPASS BIT(31) #define PLL_BASE_ENABLE BIT(30) #define PLL_BASE_REF_ENABLE BIT(29) #define PLL_BASE_OVERRIDE BIT(28) #define PLL_BASE_DIVP_SHIFT 20 #define PLL_BASE_DIVP_WIDTH 3 #define PLL_BASE_DIVN_SHIFT 8 #define PLL_BASE_DIVN_WIDTH 10 #define PLL_BASE_DIVM_SHIFT 0 #define PLL_BASE_DIVM_WIDTH 5 #define PLLU_POST_DIVP_MASK 0x1 #define PLL_MISC_DCCON_SHIFT 20 #define PLL_MISC_CPCON_SHIFT 8 #define PLL_MISC_CPCON_WIDTH 4 #define PLL_MISC_CPCON_MASK ((1 << PLL_MISC_CPCON_WIDTH) - 1) #define PLL_MISC_LFCON_SHIFT 4 #define PLL_MISC_LFCON_WIDTH 4 #define PLL_MISC_LFCON_MASK ((1 << PLL_MISC_LFCON_WIDTH) - 1) #define PLL_MISC_VCOCON_SHIFT 0 #define PLL_MISC_VCOCON_WIDTH 4 #define PLL_MISC_VCOCON_MASK ((1 << PLL_MISC_VCOCON_WIDTH) - 1) #define OUT_OF_TABLE_CPCON 8 #define PMC_PLLP_WB0_OVERRIDE 0xf8 #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE BIT(12) #define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE BIT(11) #define PLL_POST_LOCK_DELAY 50 #define PLLDU_LFCON_SET_DIVN 600 #define PLLE_BASE_DIVCML_SHIFT 24 #define PLLE_BASE_DIVCML_MASK 0xf #define PLLE_BASE_DIVP_SHIFT 16 #define PLLE_BASE_DIVP_WIDTH 6 #define PLLE_BASE_DIVN_SHIFT 8 #define PLLE_BASE_DIVN_WIDTH 8 #define PLLE_BASE_DIVM_SHIFT 0 #define PLLE_BASE_DIVM_WIDTH 8 #define PLLE_BASE_ENABLE BIT(31) #define PLLE_MISC_SETUP_BASE_SHIFT 16 #define PLLE_MISC_SETUP_BASE_MASK (0xffff << PLLE_MISC_SETUP_BASE_SHIFT) #define PLLE_MISC_LOCK_ENABLE BIT(9) #define PLLE_MISC_READY BIT(15) #define PLLE_MISC_SETUP_EX_SHIFT 2 #define PLLE_MISC_SETUP_EX_MASK (3 << PLLE_MISC_SETUP_EX_SHIFT) #define PLLE_MISC_SETUP_MASK (PLLE_MISC_SETUP_BASE_MASK | \ PLLE_MISC_SETUP_EX_MASK) #define PLLE_MISC_SETUP_VALUE (7 << PLLE_MISC_SETUP_BASE_SHIFT) #define PLLE_SS_CTRL 0x68 #define PLLE_SS_CNTL_BYPASS_SS BIT(10) #define PLLE_SS_CNTL_INTERP_RESET BIT(11) #define PLLE_SS_CNTL_SSC_BYP BIT(12) #define PLLE_SS_CNTL_CENTER BIT(14) #define PLLE_SS_CNTL_INVERT BIT(15) #define PLLE_SS_DISABLE (PLLE_SS_CNTL_BYPASS_SS | PLLE_SS_CNTL_INTERP_RESET |\ PLLE_SS_CNTL_SSC_BYP) #define PLLE_SS_MAX_MASK 0x1ff #define PLLE_SS_MAX_VAL_TEGRA114 0x25 #define PLLE_SS_MAX_VAL_TEGRA210 0x21 #define PLLE_SS_INC_MASK (0xff << 16) #define PLLE_SS_INC_VAL (0x1 << 16) #define PLLE_SS_INCINTRV_MASK (0x3f << 24) #define PLLE_SS_INCINTRV_VAL_TEGRA114 (0x20 << 24) #define PLLE_SS_INCINTRV_VAL_TEGRA210 (0x23 << 24) #define PLLE_SS_COEFFICIENTS_MASK \ (PLLE_SS_MAX_MASK | PLLE_SS_INC_MASK | PLLE_SS_INCINTRV_MASK) #define PLLE_SS_COEFFICIENTS_VAL_TEGRA114 \ (PLLE_SS_MAX_VAL_TEGRA114 | PLLE_SS_INC_VAL |\ PLLE_SS_INCINTRV_VAL_TEGRA114) #define PLLE_SS_COEFFICIENTS_VAL_TEGRA210 \ (PLLE_SS_MAX_VAL_TEGRA210 | PLLE_SS_INC_VAL |\ PLLE_SS_INCINTRV_VAL_TEGRA210) #define PLLE_AUX_PLLP_SEL BIT(2) #define PLLE_AUX_USE_LOCKDET BIT(3) #define PLLE_AUX_ENABLE_SWCTL BIT(4) #define PLLE_AUX_SS_SWCTL BIT(6) #define PLLE_AUX_SEQ_ENABLE BIT(24) #define PLLE_AUX_SEQ_START_STATE BIT(25) #define PLLE_AUX_PLLRE_SEL BIT(28) #define PLLE_AUX_SS_SEQ_INCLUDE BIT(31) #define XUSBIO_PLL_CFG0 0x51c #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0) #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL BIT(2) #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET BIT(6) #define XUSBIO_PLL_CFG0_SEQ_ENABLE BIT(24) #define XUSBIO_PLL_CFG0_SEQ_START_STATE BIT(25) #define SATA_PLL_CFG0 0x490 #define SATA_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0) #define SATA_PLL_CFG0_PADPLL_USE_LOCKDET BIT(2) #define SATA_PLL_CFG0_SEQ_ENABLE BIT(24) #define SATA_PLL_CFG0_SEQ_START_STATE BIT(25) #define PLLE_MISC_PLLE_PTS BIT(8) #define PLLE_MISC_IDDQ_SW_VALUE BIT(13) #define PLLE_MISC_IDDQ_SW_CTRL BIT(14) #define PLLE_MISC_VREG_BG_CTRL_SHIFT 4 #define PLLE_MISC_VREG_BG_CTRL_MASK (3 << PLLE_MISC_VREG_BG_CTRL_SHIFT) #define PLLE_MISC_VREG_CTRL_SHIFT 2 #define PLLE_MISC_VREG_CTRL_MASK (2 << PLLE_MISC_VREG_CTRL_SHIFT) #define PLLCX_MISC_STROBE BIT(31) #define PLLCX_MISC_RESET BIT(30) #define PLLCX_MISC_SDM_DIV_SHIFT 28 #define PLLCX_MISC_SDM_DIV_MASK (0x3 << PLLCX_MISC_SDM_DIV_SHIFT) #define PLLCX_MISC_FILT_DIV_SHIFT 26 #define PLLCX_MISC_FILT_DIV_MASK (0x3 << PLLCX_MISC_FILT_DIV_SHIFT) #define PLLCX_MISC_ALPHA_SHIFT 18 #define PLLCX_MISC_DIV_LOW_RANGE \ ((0x1 << PLLCX_MISC_SDM_DIV_SHIFT) | \ (0x1 << PLLCX_MISC_FILT_DIV_SHIFT)) #define PLLCX_MISC_DIV_HIGH_RANGE \ ((0x2 << PLLCX_MISC_SDM_DIV_SHIFT) | \ (0x2 << PLLCX_MISC_FILT_DIV_SHIFT)) #define PLLCX_MISC_COEF_LOW_RANGE \ ((0x14 << PLLCX_MISC_KA_SHIFT) | (0x38 << PLLCX_MISC_KB_SHIFT)) #define PLLCX_MISC_KA_SHIFT 2 #define PLLCX_MISC_KB_SHIFT 9 #define PLLCX_MISC_DEFAULT (PLLCX_MISC_COEF_LOW_RANGE | \ (0x19 << PLLCX_MISC_ALPHA_SHIFT) | \ PLLCX_MISC_DIV_LOW_RANGE | \ PLLCX_MISC_RESET) #define PLLCX_MISC1_DEFAULT 0x000d2308 #define PLLCX_MISC2_DEFAULT 0x30211200 #define PLLCX_MISC3_DEFAULT 0x200 #define PMC_SATA_PWRGT 0x1ac #define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE BIT(5) #define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL BIT(4) #define PLLSS_MISC_KCP 0 #define PLLSS_MISC_KVCO 0 #define PLLSS_MISC_SETUP 0 #define PLLSS_EN_SDM 0 #define PLLSS_EN_SSC 0 #define PLLSS_EN_DITHER2 0 #define PLLSS_EN_DITHER 1 #define PLLSS_SDM_RESET 0 #define PLLSS_CLAMP 0 #define PLLSS_SDM_SSC_MAX 0 #define PLLSS_SDM_SSC_MIN 0 #define PLLSS_SDM_SSC_STEP 0 #define PLLSS_SDM_DIN 0 #define PLLSS_MISC_DEFAULT ((PLLSS_MISC_KCP << 25) | \ (PLLSS_MISC_KVCO << 24) | \ PLLSS_MISC_SETUP) #define PLLSS_CFG_DEFAULT ((PLLSS_EN_SDM << 31) | \ (PLLSS_EN_SSC << 30) | \ (PLLSS_EN_DITHER2 << 29) | \ (PLLSS_EN_DITHER << 28) | \ (PLLSS_SDM_RESET) << 27 | \ (PLLSS_CLAMP << 22)) #define PLLSS_CTRL1_DEFAULT \ ((PLLSS_SDM_SSC_MAX << 16) | PLLSS_SDM_SSC_MIN) #define PLLSS_CTRL2_DEFAULT \ ((PLLSS_SDM_SSC_STEP << 16) | PLLSS_SDM_DIN) #define PLLSS_LOCK_OVERRIDE BIT(24) #define PLLSS_REF_SRC_SEL_SHIFT 25 #define PLLSS_REF_SRC_SEL_MASK (3 << PLLSS_REF_SRC_SEL_SHIFT) #define UTMIP_PLL_CFG1 0x484 #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12) #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14) #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP BIT(15) #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16) #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP BIT(17) #define UTMIP_PLL_CFG2 0x488 #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6) #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP BIT(1) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP BIT(3) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERUP BIT(5) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN BIT(24) #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP BIT(25) #define UTMIP_PLL_CFG2_PHY_XTAL_CLOCKEN BIT(30) #define UTMIPLL_HW_PWRDN_CFG0 0x52c #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL BIT(0) #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE BIT(1) #define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2) #define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL BIT(4) #define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE BIT(5) #define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET BIT(6) #define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24) #define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE BIT(25) #define PLLU_HW_PWRDN_CFG0 0x530 #define PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL BIT(0) #define PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2) #define PLLU_HW_PWRDN_CFG0_USE_LOCKDET BIT(6) #define PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT BIT(7) #define PLLU_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24) #define PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(28) #define XUSB_PLL_CFG0 0x534 #define XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY 0x3ff #define XUSB_PLL_CFG0_PLLU_LOCK_DLY (0x3ff << 14) #define PLLU_BASE_CLKENABLE_USB BIT(21) #define PLLU_BASE_OVERRIDE BIT(24) #define pll_readl(offset, p) readl_relaxed(p->clk_base + offset) #define pll_readl_base(p) pll_readl(p->params->base_reg, p) #define pll_readl_misc(p) pll_readl(p->params->misc_reg, p) #define pll_override_readl(offset, p) readl_relaxed(p->pmc + offset) #define pll_readl_sdm_din(p) pll_readl(p->params->sdm_din_reg, p) #define pll_readl_sdm_ctrl(p) pll_readl(p->params->sdm_ctrl_reg, p) #define pll_writel(val, offset, p) writel_relaxed(val, p->clk_base + offset) #define pll_writel_base(val, p) pll_writel(val, p->params->base_reg, p) #define pll_writel_misc(val, p) pll_writel(val, p->params->misc_reg, p) #define pll_override_writel(val, offset, p) writel(val, p->pmc + offset) #define pll_writel_sdm_din(val, p) pll_writel(val, p->params->sdm_din_reg, p) #define pll_writel_sdm_ctrl(val, p) pll_writel(val, p->params->sdm_ctrl_reg, p) #define mask(w) ((1 << (w)) - 1) #define divm_mask(p) mask(p->params->div_nmp->divm_width) #define divn_mask(p) mask(p->params->div_nmp->divn_width) #define divp_mask(p) (p->params->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :\ mask(p->params->div_nmp->divp_width)) #define sdm_din_mask(p) p->params->sdm_din_mask #define sdm_en_mask(p) p->params->sdm_ctrl_en_mask #define divm_shift(p) (p)->params->div_nmp->divm_shift #define divn_shift(p) (p)->params->div_nmp->divn_shift #define divp_shift(p) (p)->params->div_nmp->divp_shift #define divm_mask_shifted(p) (divm_mask(p) << divm_shift(p)) #define divn_mask_shifted(p) (divn_mask(p) << divn_shift(p)) #define divp_mask_shifted(p) (divp_mask(p) << divp_shift(p)) #define divm_max(p) (divm_mask(p)) #define divn_max(p) (divn_mask(p)) #define divp_max(p) (1 << (divp_mask(p))) #define sdin_din_to_data(din) ((u16)((din) ? : 0xFFFFU)) #define sdin_data_to_din(dat) (((dat) == 0xFFFFU) ? 0 : (s16)dat) static struct div_nmp default_nmp = { .divn_shift = PLL_BASE_DIVN_SHIFT, .divn_width = PLL_BASE_DIVN_WIDTH, .divm_shift = PLL_BASE_DIVM_SHIFT, .divm_width = PLL_BASE_DIVM_WIDTH, .divp_shift = PLL_BASE_DIVP_SHIFT, .divp_width = PLL_BASE_DIVP_WIDTH, }; static void clk_pll_enable_lock(struct tegra_clk_pll *pll) { u32 val; if (!(pll->params->flags & TEGRA_PLL_USE_LOCK)) return; if (!(pll->params->flags & TEGRA_PLL_HAS_LOCK_ENABLE)) return; val = pll_readl_misc(pll); val |= BIT(pll->params->lock_enable_bit_idx); pll_writel_misc(val, pll); } static int clk_pll_wait_for_lock(struct tegra_clk_pll *pll) { int i; u32 val, lock_mask; void __iomem *lock_addr; if (!(pll->params->flags & TEGRA_PLL_USE_LOCK)) { udelay(pll->params->lock_delay); return 0; } lock_addr = pll->clk_base; if (pll->params->flags & TEGRA_PLL_LOCK_MISC) lock_addr += pll->params->misc_reg; else lock_addr += pll->params->base_reg; lock_mask = pll->params->lock_mask; for (i = 0; i < pll->params->lock_delay; i++) { val = readl_relaxed(lock_addr); if ((val & lock_mask) == lock_mask) { udelay(PLL_POST_LOCK_DELAY); return 0; } udelay(2); /* timeout = 2 * lock time */ } pr_err("%s: Timed out waiting for pll %s lock\n", __func__, clk_hw_get_name(&pll->hw)); return -1; } int tegra_pll_wait_for_lock(struct tegra_clk_pll *pll) { return clk_pll_wait_for_lock(pll); } static bool pllm_clk_is_gated_by_pmc(struct tegra_clk_pll *pll) { u32 val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE); return (val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE) && !(val & PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE); } static int clk_pll_is_enabled(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); u32 val; /* * Power Management Controller (PMC) can override the PLLM clock * settings, including the enable-state. The PLLM is enabled when * PLLM's CaR state is ON and when PLLM isn't gated by PMC. */ if ((pll->params->flags & TEGRA_PLLM) && pllm_clk_is_gated_by_pmc(pll)) return 0; val = pll_readl_base(pll); return val & PLL_BASE_ENABLE ? 1 : 0; } static void _clk_pll_enable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); u32 val; if (pll->params->iddq_reg) { val = pll_readl(pll->params->iddq_reg, pll); val &= ~BIT(pll->params->iddq_bit_idx); pll_writel(val, pll->params->iddq_reg, pll); udelay(5); } if (pll->params->reset_reg) { val = pll_readl(pll->params->reset_reg, pll); val &= ~BIT(pll->params->reset_bit_idx); pll_writel(val, pll->params->reset_reg, pll); } clk_pll_enable_lock(pll); val = pll_readl_base(pll); if (pll->params->flags & TEGRA_PLL_BYPASS) val &= ~PLL_BASE_BYPASS; val |= PLL_BASE_ENABLE; pll_writel_base(val, pll); if (pll->params->flags & TEGRA_PLLM) { val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE); val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE; writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE); } } static void _clk_pll_disable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); u32 val; val = pll_readl_base(pll); if (pll->params->flags & TEGRA_PLL_BYPASS) val &= ~PLL_BASE_BYPASS; val &= ~PLL_BASE_ENABLE; pll_writel_base(val, pll); if (pll->params->flags & TEGRA_PLLM) { val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE); val &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE; writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE); } if (pll->params->reset_reg) { val = pll_readl(pll->params->reset_reg, pll); val |= BIT(pll->params->reset_bit_idx); pll_writel(val, pll->params->reset_reg, pll); } if (pll->params->iddq_reg) { val = pll_readl(pll->params->iddq_reg, pll); val |= BIT(pll->params->iddq_bit_idx); pll_writel(val, pll->params->iddq_reg, pll); udelay(2); } } static void pll_clk_start_ss(struct tegra_clk_pll *pll) { if (pll->params->defaults_set && pll->params->ssc_ctrl_reg) { u32 val = pll_readl(pll->params->ssc_ctrl_reg, pll); val |= pll->params->ssc_ctrl_en_mask; pll_writel(val, pll->params->ssc_ctrl_reg, pll); } } static void pll_clk_stop_ss(struct tegra_clk_pll *pll) { if (pll->params->defaults_set && pll->params->ssc_ctrl_reg) { u32 val = pll_readl(pll->params->ssc_ctrl_reg, pll); val &= ~pll->params->ssc_ctrl_en_mask; pll_writel(val, pll->params->ssc_ctrl_reg, pll); } } static int clk_pll_enable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned long flags = 0; int ret; if (clk_pll_is_enabled(hw)) return 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); _clk_pll_enable(hw); ret = clk_pll_wait_for_lock(pll); pll_clk_start_ss(pll); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static void clk_pll_disable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned long flags = 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); pll_clk_stop_ss(pll); _clk_pll_disable(hw); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); } static int _p_div_to_hw(struct clk_hw *hw, u8 p_div) { struct tegra_clk_pll *pll = to_clk_pll(hw); const struct pdiv_map *p_tohw = pll->params->pdiv_tohw; if (p_tohw) { while (p_tohw->pdiv) { if (p_div <= p_tohw->pdiv) return p_tohw->hw_val; p_tohw++; } return -EINVAL; } return -EINVAL; } int tegra_pll_p_div_to_hw(struct tegra_clk_pll *pll, u8 p_div) { return _p_div_to_hw(&pll->hw, p_div); } static int _hw_to_p_div(struct clk_hw *hw, u8 p_div_hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); const struct pdiv_map *p_tohw = pll->params->pdiv_tohw; if (p_tohw) { while (p_tohw->pdiv) { if (p_div_hw == p_tohw->hw_val) return p_tohw->pdiv; p_tohw++; } return -EINVAL; } return 1 << p_div_hw; } static int _get_table_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table *sel; int p; for (sel = pll->params->freq_table; sel->input_rate != 0; sel++) if (sel->input_rate == parent_rate && sel->output_rate == rate) break; if (sel->input_rate == 0) return -EINVAL; if (pll->params->pdiv_tohw) { p = _p_div_to_hw(hw, sel->p); if (p < 0) return p; } else { p = ilog2(sel->p); } cfg->input_rate = sel->input_rate; cfg->output_rate = sel->output_rate; cfg->m = sel->m; cfg->n = sel->n; cfg->p = p; cfg->cpcon = sel->cpcon; cfg->sdm_data = sel->sdm_data; return 0; } static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned long cfreq; u32 p_div = 0; int ret; if (!rate) return -EINVAL; switch (parent_rate) { case 12000000: case 26000000: cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000; break; case 13000000: cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000; break; case 16800000: case 19200000: cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000; break; case 9600000: case 28800000: /* * PLL_P_OUT1 rate is not listed in PLLA table */ cfreq = parent_rate / (parent_rate / 1000000); break; default: pr_err("%s Unexpected reference rate %lu\n", __func__, parent_rate); BUG(); } /* Raise VCO to guarantee 0.5% accuracy */ for (cfg->output_rate = rate; cfg->output_rate < 200 * cfreq; cfg->output_rate <<= 1) p_div++; cfg->m = parent_rate / cfreq; cfg->n = cfg->output_rate / cfreq; cfg->cpcon = OUT_OF_TABLE_CPCON; if (cfg->m == 0 || cfg->m > divm_max(pll) || cfg->n > divn_max(pll) || (1 << p_div) > divp_max(pll) || cfg->output_rate > pll->params->vco_max) { return -EINVAL; } cfg->output_rate = cfg->n * DIV_ROUND_UP(parent_rate, cfg->m); cfg->output_rate >>= p_div; if (pll->params->pdiv_tohw) { ret = _p_div_to_hw(hw, 1 << p_div); if (ret < 0) return ret; else cfg->p = ret; } else cfg->p = p_div; return 0; } /* * SDM (Sigma Delta Modulator) divisor is 16-bit 2's complement signed number * within (-2^12 ... 2^12-1) range. Represented in PLL data structure as * unsigned 16-bit value, with "0" divisor mapped to 0xFFFF. Data "0" is used * to indicate that SDM is disabled. * * Effective ndiv value when SDM is enabled: ndiv + 1/2 + sdm_din/2^13 */ static void clk_pll_set_sdm_data(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg) { struct tegra_clk_pll *pll = to_clk_pll(hw); u32 val; bool enabled; if (!pll->params->sdm_din_reg) return; if (cfg->sdm_data) { val = pll_readl_sdm_din(pll) & (~sdm_din_mask(pll)); val |= sdin_data_to_din(cfg->sdm_data) & sdm_din_mask(pll); pll_writel_sdm_din(val, pll); } val = pll_readl_sdm_ctrl(pll); enabled = (val & sdm_en_mask(pll)); if (cfg->sdm_data == 0 && enabled) val &= ~pll->params->sdm_ctrl_en_mask; if (cfg->sdm_data != 0 && !enabled) val |= pll->params->sdm_ctrl_en_mask; pll_writel_sdm_ctrl(val, pll); } static void _update_pll_mnp(struct tegra_clk_pll *pll, struct tegra_clk_pll_freq_table *cfg) { u32 val; struct tegra_clk_pll_params *params = pll->params; struct div_nmp *div_nmp = params->div_nmp; if ((params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) && (pll_override_readl(PMC_PLLP_WB0_OVERRIDE, pll) & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)) { val = pll_override_readl(params->pmc_divp_reg, pll); val &= ~(divp_mask(pll) << div_nmp->override_divp_shift); val |= cfg->p << div_nmp->override_divp_shift; pll_override_writel(val, params->pmc_divp_reg, pll); val = pll_override_readl(params->pmc_divnm_reg, pll); val &= ~((divm_mask(pll) << div_nmp->override_divm_shift) | (divn_mask(pll) << div_nmp->override_divn_shift)); val |= (cfg->m << div_nmp->override_divm_shift) | (cfg->n << div_nmp->override_divn_shift); pll_override_writel(val, params->pmc_divnm_reg, pll); } else { val = pll_readl_base(pll); val &= ~(divm_mask_shifted(pll) | divn_mask_shifted(pll) | divp_mask_shifted(pll)); val |= (cfg->m << divm_shift(pll)) | (cfg->n << divn_shift(pll)) | (cfg->p << divp_shift(pll)); pll_writel_base(val, pll); clk_pll_set_sdm_data(&pll->hw, cfg); } } static void _get_pll_mnp(struct tegra_clk_pll *pll, struct tegra_clk_pll_freq_table *cfg) { u32 val; struct tegra_clk_pll_params *params = pll->params; struct div_nmp *div_nmp = params->div_nmp; *cfg = (struct tegra_clk_pll_freq_table) { }; if ((params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) && (pll_override_readl(PMC_PLLP_WB0_OVERRIDE, pll) & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)) { val = pll_override_readl(params->pmc_divp_reg, pll); cfg->p = (val >> div_nmp->override_divp_shift) & divp_mask(pll); val = pll_override_readl(params->pmc_divnm_reg, pll); cfg->m = (val >> div_nmp->override_divm_shift) & divm_mask(pll); cfg->n = (val >> div_nmp->override_divn_shift) & divn_mask(pll); } else { val = pll_readl_base(pll); cfg->m = (val >> div_nmp->divm_shift) & divm_mask(pll); cfg->n = (val >> div_nmp->divn_shift) & divn_mask(pll); cfg->p = (val >> div_nmp->divp_shift) & divp_mask(pll); if (pll->params->sdm_din_reg) { if (sdm_en_mask(pll) & pll_readl_sdm_ctrl(pll)) { val = pll_readl_sdm_din(pll); val &= sdm_din_mask(pll); cfg->sdm_data = sdin_din_to_data(val); } } } } static void _update_pll_cpcon(struct tegra_clk_pll *pll, struct tegra_clk_pll_freq_table *cfg, unsigned long rate) { u32 val; val = pll_readl_misc(pll); val &= ~(PLL_MISC_CPCON_MASK << PLL_MISC_CPCON_SHIFT); val |= cfg->cpcon << PLL_MISC_CPCON_SHIFT; if (pll->params->flags & TEGRA_PLL_SET_LFCON) { val &= ~(PLL_MISC_LFCON_MASK << PLL_MISC_LFCON_SHIFT); if (cfg->n >= PLLDU_LFCON_SET_DIVN) val |= 1 << PLL_MISC_LFCON_SHIFT; } else if (pll->params->flags & TEGRA_PLL_SET_DCCON) { val &= ~(1 << PLL_MISC_DCCON_SHIFT); if (rate >= (pll->params->vco_max >> 1)) val |= 1 << PLL_MISC_DCCON_SHIFT; } pll_writel_misc(val, pll); } static int _program_pll(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, unsigned long rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table old_cfg; int state, ret = 0; state = clk_pll_is_enabled(hw); if (state && pll->params->pre_rate_change) { ret = pll->params->pre_rate_change(); if (WARN_ON(ret)) return ret; } _get_pll_mnp(pll, &old_cfg); if (state && pll->params->defaults_set && pll->params->dyn_ramp && (cfg->m == old_cfg.m) && (cfg->p == old_cfg.p)) { ret = pll->params->dyn_ramp(pll, cfg); if (!ret) goto done; } if (state) { pll_clk_stop_ss(pll); _clk_pll_disable(hw); } if (!pll->params->defaults_set && pll->params->set_defaults) pll->params->set_defaults(pll); _update_pll_mnp(pll, cfg); if (pll->params->flags & TEGRA_PLL_HAS_CPCON) _update_pll_cpcon(pll, cfg, rate); if (state) { _clk_pll_enable(hw); ret = clk_pll_wait_for_lock(pll); pll_clk_start_ss(pll); } done: if (state && pll->params->post_rate_change) pll->params->post_rate_change(); return ret; } static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table cfg, old_cfg; unsigned long flags = 0; int ret = 0; if (pll->params->flags & TEGRA_PLL_FIXED) { if (rate != pll->params->fixed_rate) { pr_err("%s: Can not change %s fixed rate %lu to %lu\n", __func__, clk_hw_get_name(hw), pll->params->fixed_rate, rate); return -EINVAL; } return 0; } if (_get_table_rate(hw, &cfg, rate, parent_rate) && pll->params->calc_rate(hw, &cfg, rate, parent_rate)) { pr_err("%s: Failed to set %s rate %lu\n", __func__, clk_hw_get_name(hw), rate); WARN_ON(1); return -EINVAL; } if (pll->lock) spin_lock_irqsave(pll->lock, flags); _get_pll_mnp(pll, &old_cfg); if (pll->params->flags & TEGRA_PLL_VCO_OUT) cfg.p = old_cfg.p; if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p || old_cfg.sdm_data != cfg.sdm_data) ret = _program_pll(hw, &cfg, rate); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table cfg; if (pll->params->flags & TEGRA_PLL_FIXED) { /* PLLM/MB are used for memory; we do not change rate */ if (pll->params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) return clk_hw_get_rate(hw); return pll->params->fixed_rate; } if (_get_table_rate(hw, &cfg, rate, *prate) && pll->params->calc_rate(hw, &cfg, rate, *prate)) return -EINVAL; return cfg.output_rate; } static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table cfg; u32 val; u64 rate = parent_rate; int pdiv; val = pll_readl_base(pll); if ((pll->params->flags & TEGRA_PLL_BYPASS) && (val & PLL_BASE_BYPASS)) return parent_rate; if ((pll->params->flags & TEGRA_PLL_FIXED) && !(pll->params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) && !(val & PLL_BASE_OVERRIDE)) { struct tegra_clk_pll_freq_table sel; if (_get_table_rate(hw, &sel, pll->params->fixed_rate, parent_rate)) { pr_err("Clock %s has unknown fixed frequency\n", clk_hw_get_name(hw)); BUG(); } return pll->params->fixed_rate; } _get_pll_mnp(pll, &cfg); if (pll->params->flags & TEGRA_PLL_VCO_OUT) { pdiv = 1; } else { pdiv = _hw_to_p_div(hw, cfg.p); if (pdiv < 0) { WARN(1, "Clock %s has invalid pdiv value : 0x%x\n", clk_hw_get_name(hw), cfg.p); pdiv = 1; } } if (pll->params->set_gain) pll->params->set_gain(&cfg); cfg.m *= pdiv; rate *= cfg.n; do_div(rate, cfg.m); return rate; } static int clk_plle_training(struct tegra_clk_pll *pll) { u32 val; unsigned long timeout; if (!pll->pmc) return -ENOSYS; /* * PLLE is already disabled, and setup cleared; * create falling edge on PLLE IDDQ input. */ val = readl(pll->pmc + PMC_SATA_PWRGT); val |= PMC_SATA_PWRGT_PLLE_IDDQ_VALUE; writel(val, pll->pmc + PMC_SATA_PWRGT); val = readl(pll->pmc + PMC_SATA_PWRGT); val |= PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL; writel(val, pll->pmc + PMC_SATA_PWRGT); val = readl(pll->pmc + PMC_SATA_PWRGT); val &= ~PMC_SATA_PWRGT_PLLE_IDDQ_VALUE; writel(val, pll->pmc + PMC_SATA_PWRGT); val = pll_readl_misc(pll); timeout = jiffies + msecs_to_jiffies(100); while (1) { val = pll_readl_misc(pll); if (val & PLLE_MISC_READY) break; if (time_after(jiffies, timeout)) { pr_err("%s: timeout waiting for PLLE\n", __func__); return -EBUSY; } udelay(300); } return 0; } static int clk_plle_enable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table sel; unsigned long input_rate; u32 val; int err; if (clk_pll_is_enabled(hw)) return 0; input_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate)) return -EINVAL; clk_pll_disable(hw); val = pll_readl_misc(pll); val &= ~(PLLE_MISC_LOCK_ENABLE | PLLE_MISC_SETUP_MASK); pll_writel_misc(val, pll); val = pll_readl_misc(pll); if (!(val & PLLE_MISC_READY)) { err = clk_plle_training(pll); if (err) return err; } if (pll->params->flags & TEGRA_PLLE_CONFIGURE) { /* configure dividers */ val = pll_readl_base(pll); val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) | divm_mask_shifted(pll)); val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT); val |= sel.m << divm_shift(pll); val |= sel.n << divn_shift(pll); val |= sel.p << divp_shift(pll); val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT; pll_writel_base(val, pll); } val = pll_readl_misc(pll); val |= PLLE_MISC_SETUP_VALUE; val |= PLLE_MISC_LOCK_ENABLE; pll_writel_misc(val, pll); val = readl(pll->clk_base + PLLE_SS_CTRL); val &= ~PLLE_SS_COEFFICIENTS_MASK; val |= PLLE_SS_DISABLE; writel(val, pll->clk_base + PLLE_SS_CTRL); val = pll_readl_base(pll); val |= (PLL_BASE_BYPASS | PLL_BASE_ENABLE); pll_writel_base(val, pll); clk_pll_wait_for_lock(pll); return 0; } static unsigned long clk_plle_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); u32 val = pll_readl_base(pll); u32 divn = 0, divm = 0, divp = 0; u64 rate = parent_rate; divp = (val >> pll->params->div_nmp->divp_shift) & (divp_mask(pll)); divn = (val >> pll->params->div_nmp->divn_shift) & (divn_mask(pll)); divm = (val >> pll->params->div_nmp->divm_shift) & (divm_mask(pll)); divm *= divp; rate *= divn; do_div(rate, divm); return rate; } static void tegra_clk_pll_restore_context(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct clk_hw *parent = clk_hw_get_parent(hw); unsigned long parent_rate = clk_hw_get_rate(parent); unsigned long rate = clk_hw_get_rate(hw); if (clk_pll_is_enabled(hw)) return; if (pll->params->set_defaults) pll->params->set_defaults(pll); clk_pll_set_rate(hw, rate, parent_rate); if (!__clk_get_enable_count(hw->clk)) clk_pll_disable(hw); else clk_pll_enable(hw); } const struct clk_ops tegra_clk_pll_ops = { .is_enabled = clk_pll_is_enabled, .enable = clk_pll_enable, .disable = clk_pll_disable, .recalc_rate = clk_pll_recalc_rate, .round_rate = clk_pll_round_rate, .set_rate = clk_pll_set_rate, .restore_context = tegra_clk_pll_restore_context, }; const struct clk_ops tegra_clk_plle_ops = { .recalc_rate = clk_plle_recalc_rate, .is_enabled = clk_pll_is_enabled, .disable = clk_pll_disable, .enable = clk_plle_enable, }; /* * Structure defining the fields for USB UTMI clocks Parameters. */ struct utmi_clk_param { /* Oscillator Frequency in Hz */ u32 osc_frequency; /* UTMIP PLL Enable Delay Count */ u8 enable_delay_count; /* UTMIP PLL Stable count */ u8 stable_count; /* UTMIP PLL Active delay count */ u8 active_delay_count; /* UTMIP PLL Xtal frequency count */ u8 xtal_freq_count; }; static const struct utmi_clk_param utmi_parameters[] = { { .osc_frequency = 13000000, .enable_delay_count = 0x02, .stable_count = 0x33, .active_delay_count = 0x05, .xtal_freq_count = 0x7f }, { .osc_frequency = 19200000, .enable_delay_count = 0x03, .stable_count = 0x4b, .active_delay_count = 0x06, .xtal_freq_count = 0xbb }, { .osc_frequency = 12000000, .enable_delay_count = 0x02, .stable_count = 0x2f, .active_delay_count = 0x04, .xtal_freq_count = 0x76 }, { .osc_frequency = 26000000, .enable_delay_count = 0x04, .stable_count = 0x66, .active_delay_count = 0x09, .xtal_freq_count = 0xfe }, { .osc_frequency = 16800000, .enable_delay_count = 0x03, .stable_count = 0x41, .active_delay_count = 0x0a, .xtal_freq_count = 0xa4 }, { .osc_frequency = 38400000, .enable_delay_count = 0x0, .stable_count = 0x0, .active_delay_count = 0x6, .xtal_freq_count = 0x80 }, }; static int clk_pllu_enable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct clk_hw *pll_ref = clk_hw_get_parent(hw); struct clk_hw *osc = clk_hw_get_parent(pll_ref); const struct utmi_clk_param *params = NULL; unsigned long flags = 0, input_rate; unsigned int i; int ret = 0; u32 value; if (!osc) { pr_err("%s: failed to get OSC clock\n", __func__); return -EINVAL; } input_rate = clk_hw_get_rate(osc); if (pll->lock) spin_lock_irqsave(pll->lock, flags); if (!clk_pll_is_enabled(hw)) _clk_pll_enable(hw); ret = clk_pll_wait_for_lock(pll); if (ret < 0) goto out; for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) { if (input_rate == utmi_parameters[i].osc_frequency) { params = &utmi_parameters[i]; break; } } if (!params) { pr_err("%s: unexpected input rate %lu Hz\n", __func__, input_rate); ret = -EINVAL; goto out; } value = pll_readl_base(pll); value &= ~PLLU_BASE_OVERRIDE; pll_writel_base(value, pll); value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG2); /* Program UTMIP PLL stable and active counts */ value &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0); value |= UTMIP_PLL_CFG2_STABLE_COUNT(params->stable_count); value &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0); value |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(params->active_delay_count); /* Remove power downs from UTMIP PLL control bits */ value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN; value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN; value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN; writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG2); value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG1); /* Program UTMIP PLL delay and oscillator frequency counts */ value &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0); value |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(params->enable_delay_count); value &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0); value |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(params->xtal_freq_count); /* Remove power downs from UTMIP PLL control bits */ value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN; value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN; value &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN; writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG1); out: if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static const struct clk_ops tegra_clk_pllu_ops = { .is_enabled = clk_pll_is_enabled, .enable = clk_pllu_enable, .disable = clk_pll_disable, .recalc_rate = clk_pll_recalc_rate, .round_rate = clk_pll_round_rate, .set_rate = clk_pll_set_rate, }; static int _pll_fixed_mdiv(struct tegra_clk_pll_params *pll_params, unsigned long parent_rate) { u16 mdiv = parent_rate / pll_params->cf_min; if (pll_params->flags & TEGRA_MDIV_NEW) return (!pll_params->mdiv_default ? mdiv : min(mdiv, pll_params->mdiv_default)); if (pll_params->mdiv_default) return pll_params->mdiv_default; if (parent_rate > pll_params->cf_max) return 2; else return 1; } static int _calc_dynamic_ramp_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned int p; int p_div; if (!rate) return -EINVAL; p = DIV_ROUND_UP(pll->params->vco_min, rate); cfg->m = _pll_fixed_mdiv(pll->params, parent_rate); cfg->output_rate = rate * p; cfg->n = cfg->output_rate * cfg->m / parent_rate; cfg->input_rate = parent_rate; p_div = _p_div_to_hw(hw, p); if (p_div < 0) return p_div; cfg->p = p_div; if (cfg->n > divn_max(pll) || cfg->output_rate > pll->params->vco_max) return -EINVAL; return 0; } #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \ defined(CONFIG_ARCH_TEGRA_124_SOC) || \ defined(CONFIG_ARCH_TEGRA_132_SOC) || \ defined(CONFIG_ARCH_TEGRA_210_SOC) u16 tegra_pll_get_fixed_mdiv(struct clk_hw *hw, unsigned long input_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); return (u16)_pll_fixed_mdiv(pll->params, input_rate); } static unsigned long _clip_vco_min(unsigned long vco_min, unsigned long parent_rate) { return DIV_ROUND_UP(vco_min, parent_rate) * parent_rate; } static int _setup_dynamic_ramp(struct tegra_clk_pll_params *pll_params, void __iomem *clk_base, unsigned long parent_rate) { u32 val; u32 step_a, step_b; switch (parent_rate) { case 12000000: case 13000000: case 26000000: step_a = 0x2B; step_b = 0x0B; break; case 16800000: step_a = 0x1A; step_b = 0x09; break; case 19200000: step_a = 0x12; step_b = 0x08; break; default: pr_err("%s: Unexpected reference rate %lu\n", __func__, parent_rate); WARN_ON(1); return -EINVAL; } val = step_a << pll_params->stepa_shift; val |= step_b << pll_params->stepb_shift; writel_relaxed(val, clk_base + pll_params->dyn_ramp_reg); return 0; } static int _pll_ramp_calc_pll(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); int err = 0; err = _get_table_rate(hw, cfg, rate, parent_rate); if (err < 0) err = _calc_dynamic_ramp_rate(hw, cfg, rate, parent_rate); else { if (cfg->m != _pll_fixed_mdiv(pll->params, parent_rate)) { WARN_ON(1); err = -EINVAL; goto out; } } if (cfg->p > pll->params->max_p) err = -EINVAL; out: return err; } static int clk_pllxc_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table cfg, old_cfg; unsigned long flags = 0; int ret; ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate); if (ret < 0) return ret; if (pll->lock) spin_lock_irqsave(pll->lock, flags); _get_pll_mnp(pll, &old_cfg); if (pll->params->flags & TEGRA_PLL_VCO_OUT) cfg.p = old_cfg.p; if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p) ret = _program_pll(hw, &cfg, rate); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static long clk_pll_ramp_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table cfg; int ret, p_div; u64 output_rate = *prate; ret = _pll_ramp_calc_pll(hw, &cfg, rate, *prate); if (ret < 0) return ret; p_div = _hw_to_p_div(hw, cfg.p); if (p_div < 0) return p_div; if (pll->params->set_gain) pll->params->set_gain(&cfg); output_rate *= cfg.n; do_div(output_rate, cfg.m * p_div); return output_rate; } static void _pllcx_strobe(struct tegra_clk_pll *pll) { u32 val; val = pll_readl_misc(pll); val |= PLLCX_MISC_STROBE; pll_writel_misc(val, pll); udelay(2); val &= ~PLLCX_MISC_STROBE; pll_writel_misc(val, pll); } static int clk_pllc_enable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); u32 val; int ret; unsigned long flags = 0; if (clk_pll_is_enabled(hw)) return 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); _clk_pll_enable(hw); udelay(2); val = pll_readl_misc(pll); val &= ~PLLCX_MISC_RESET; pll_writel_misc(val, pll); udelay(2); _pllcx_strobe(pll); ret = clk_pll_wait_for_lock(pll); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static void _clk_pllc_disable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); u32 val; _clk_pll_disable(hw); val = pll_readl_misc(pll); val |= PLLCX_MISC_RESET; pll_writel_misc(val, pll); udelay(2); } static void clk_pllc_disable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned long flags = 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); _clk_pllc_disable(hw); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); } static int _pllcx_update_dynamic_coef(struct tegra_clk_pll *pll, unsigned long input_rate, u32 n) { u32 val, n_threshold; switch (input_rate) { case 12000000: n_threshold = 70; break; case 13000000: case 26000000: n_threshold = 71; break; case 16800000: n_threshold = 55; break; case 19200000: n_threshold = 48; break; default: pr_err("%s: Unexpected reference rate %lu\n", __func__, input_rate); return -EINVAL; } val = pll_readl_misc(pll); val &= ~(PLLCX_MISC_SDM_DIV_MASK | PLLCX_MISC_FILT_DIV_MASK); val |= n <= n_threshold ? PLLCX_MISC_DIV_LOW_RANGE : PLLCX_MISC_DIV_HIGH_RANGE; pll_writel_misc(val, pll); return 0; } static int clk_pllc_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_pll_freq_table cfg, old_cfg; struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned long flags = 0; int state, ret = 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate); if (ret < 0) goto out; _get_pll_mnp(pll, &old_cfg); if (cfg.m != old_cfg.m) { WARN_ON(1); goto out; } if (old_cfg.n == cfg.n && old_cfg.p == cfg.p) goto out; state = clk_pll_is_enabled(hw); if (state) _clk_pllc_disable(hw); ret = _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n); if (ret < 0) goto out; _update_pll_mnp(pll, &cfg); if (state) ret = clk_pllc_enable(hw); out: if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static long _pllre_calc_rate(struct tegra_clk_pll *pll, struct tegra_clk_pll_freq_table *cfg, unsigned long rate, unsigned long parent_rate) { u16 m, n; u64 output_rate = parent_rate; m = _pll_fixed_mdiv(pll->params, parent_rate); n = rate * m / parent_rate; output_rate *= n; do_div(output_rate, m); if (cfg) { cfg->m = m; cfg->n = n; } return output_rate; } static int clk_pllre_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_pll_freq_table cfg, old_cfg; struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned long flags = 0; int state, ret = 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); _pllre_calc_rate(pll, &cfg, rate, parent_rate); _get_pll_mnp(pll, &old_cfg); cfg.p = old_cfg.p; if (cfg.m != old_cfg.m || cfg.n != old_cfg.n) { state = clk_pll_is_enabled(hw); if (state) _clk_pll_disable(hw); _update_pll_mnp(pll, &cfg); if (state) { _clk_pll_enable(hw); ret = clk_pll_wait_for_lock(pll); } } if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static unsigned long clk_pllre_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_pll_freq_table cfg; struct tegra_clk_pll *pll = to_clk_pll(hw); u64 rate = parent_rate; _get_pll_mnp(pll, &cfg); rate *= cfg.n; do_div(rate, cfg.m); return rate; } static long clk_pllre_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct tegra_clk_pll *pll = to_clk_pll(hw); return _pllre_calc_rate(pll, NULL, rate, *prate); } static int clk_plle_tegra114_enable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table sel; u32 val; int ret; unsigned long flags = 0; unsigned long input_rate; input_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate)) return -EINVAL; if (pll->lock) spin_lock_irqsave(pll->lock, flags); val = pll_readl_base(pll); val &= ~BIT(29); /* Disable lock override */ pll_writel_base(val, pll); val = pll_readl(pll->params->aux_reg, pll); val |= PLLE_AUX_ENABLE_SWCTL; val &= ~PLLE_AUX_SEQ_ENABLE; pll_writel(val, pll->params->aux_reg, pll); udelay(1); val = pll_readl_misc(pll); val |= PLLE_MISC_LOCK_ENABLE; val |= PLLE_MISC_IDDQ_SW_CTRL; val &= ~PLLE_MISC_IDDQ_SW_VALUE; val |= PLLE_MISC_PLLE_PTS; val &= ~(PLLE_MISC_VREG_BG_CTRL_MASK | PLLE_MISC_VREG_CTRL_MASK); pll_writel_misc(val, pll); udelay(5); val = pll_readl(PLLE_SS_CTRL, pll); val |= PLLE_SS_DISABLE; pll_writel(val, PLLE_SS_CTRL, pll); val = pll_readl_base(pll); val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) | divm_mask_shifted(pll)); val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT); val |= sel.m << divm_shift(pll); val |= sel.n << divn_shift(pll); val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT; pll_writel_base(val, pll); udelay(1); _clk_pll_enable(hw); ret = clk_pll_wait_for_lock(pll); if (ret < 0) goto out; val = pll_readl(PLLE_SS_CTRL, pll); val &= ~(PLLE_SS_CNTL_CENTER | PLLE_SS_CNTL_INVERT); val &= ~PLLE_SS_COEFFICIENTS_MASK; val |= PLLE_SS_COEFFICIENTS_VAL_TEGRA114; pll_writel(val, PLLE_SS_CTRL, pll); val &= ~(PLLE_SS_CNTL_SSC_BYP | PLLE_SS_CNTL_BYPASS_SS); pll_writel(val, PLLE_SS_CTRL, pll); udelay(1); val &= ~PLLE_SS_CNTL_INTERP_RESET; pll_writel(val, PLLE_SS_CTRL, pll); udelay(1); /* Enable HW control of XUSB brick PLL */ val = pll_readl_misc(pll); val &= ~PLLE_MISC_IDDQ_SW_CTRL; pll_writel_misc(val, pll); val = pll_readl(pll->params->aux_reg, pll); val |= (PLLE_AUX_USE_LOCKDET | PLLE_AUX_SEQ_START_STATE); val &= ~(PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL); pll_writel(val, pll->params->aux_reg, pll); udelay(1); val |= PLLE_AUX_SEQ_ENABLE; pll_writel(val, pll->params->aux_reg, pll); val = pll_readl(XUSBIO_PLL_CFG0, pll); val |= (XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET | XUSBIO_PLL_CFG0_SEQ_START_STATE); val &= ~(XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL | XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL); pll_writel(val, XUSBIO_PLL_CFG0, pll); udelay(1); val |= XUSBIO_PLL_CFG0_SEQ_ENABLE; pll_writel(val, XUSBIO_PLL_CFG0, pll); /* Enable HW control of SATA PLL */ val = pll_readl(SATA_PLL_CFG0, pll); val &= ~SATA_PLL_CFG0_PADPLL_RESET_SWCTL; val |= SATA_PLL_CFG0_PADPLL_USE_LOCKDET; val |= SATA_PLL_CFG0_SEQ_START_STATE; pll_writel(val, SATA_PLL_CFG0, pll); udelay(1); val = pll_readl(SATA_PLL_CFG0, pll); val |= SATA_PLL_CFG0_SEQ_ENABLE; pll_writel(val, SATA_PLL_CFG0, pll); out: if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static void clk_plle_tegra114_disable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned long flags = 0; u32 val; if (pll->lock) spin_lock_irqsave(pll->lock, flags); _clk_pll_disable(hw); val = pll_readl_misc(pll); val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE; pll_writel_misc(val, pll); udelay(1); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); } static int clk_pllu_tegra114_enable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); const struct utmi_clk_param *params = NULL; struct clk *osc = __clk_lookup("osc"); unsigned long flags = 0, input_rate; unsigned int i; int ret = 0; u32 value; if (!osc) { pr_err("%s: failed to get OSC clock\n", __func__); return -EINVAL; } input_rate = clk_hw_get_rate(__clk_get_hw(osc)); if (pll->lock) spin_lock_irqsave(pll->lock, flags); if (!clk_pll_is_enabled(hw)) _clk_pll_enable(hw); ret = clk_pll_wait_for_lock(pll); if (ret < 0) goto out; for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) { if (input_rate == utmi_parameters[i].osc_frequency) { params = &utmi_parameters[i]; break; } } if (!params) { pr_err("%s: unexpected input rate %lu Hz\n", __func__, input_rate); ret = -EINVAL; goto out; } value = pll_readl_base(pll); value &= ~PLLU_BASE_OVERRIDE; pll_writel_base(value, pll); value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG2); /* Program UTMIP PLL stable and active counts */ value &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0); value |= UTMIP_PLL_CFG2_STABLE_COUNT(params->stable_count); value &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0); value |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(params->active_delay_count); /* Remove power downs from UTMIP PLL control bits */ value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN; value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN; value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN; writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG2); value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG1); /* Program UTMIP PLL delay and oscillator frequency counts */ value &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0); value |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(params->enable_delay_count); value &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0); value |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(params->xtal_freq_count); /* Remove power downs from UTMIP PLL control bits */ value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN; value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN; value &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP; value &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN; writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG1); /* Setup HW control of UTMIPLL */ value = readl_relaxed(pll->clk_base + UTMIPLL_HW_PWRDN_CFG0); value |= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET; value &= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL; value |= UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE; writel_relaxed(value, pll->clk_base + UTMIPLL_HW_PWRDN_CFG0); value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG1); value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP; value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN; writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG1); udelay(1); /* * Setup SW override of UTMIPLL assuming USB2.0 ports are assigned * to USB2 */ value = readl_relaxed(pll->clk_base + UTMIPLL_HW_PWRDN_CFG0); value |= UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL; value &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE; writel_relaxed(value, pll->clk_base + UTMIPLL_HW_PWRDN_CFG0); udelay(1); /* Enable HW control of UTMIPLL */ value = readl_relaxed(pll->clk_base + UTMIPLL_HW_PWRDN_CFG0); value |= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE; writel_relaxed(value, pll->clk_base + UTMIPLL_HW_PWRDN_CFG0); out: if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static void _clk_plle_tegra_init_parent(struct tegra_clk_pll *pll) { u32 val, val_aux; /* ensure parent is set to pll_ref */ val = pll_readl_base(pll); val_aux = pll_readl(pll->params->aux_reg, pll); if (val & PLL_BASE_ENABLE) { if ((val_aux & PLLE_AUX_PLLRE_SEL) || (val_aux & PLLE_AUX_PLLP_SEL)) WARN(1, "pll_e enabled with unsupported parent %s\n", (val_aux & PLLE_AUX_PLLP_SEL) ? "pllp_out0" : "pll_re_vco"); } else { val_aux &= ~(PLLE_AUX_PLLRE_SEL | PLLE_AUX_PLLP_SEL); pll_writel(val_aux, pll->params->aux_reg, pll); fence_udelay(1, pll->clk_base); } } #endif static struct tegra_clk_pll *_tegra_init_pll(void __iomem *clk_base, void __iomem *pmc, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; pll = kzalloc(sizeof(*pll), GFP_KERNEL); if (!pll) return ERR_PTR(-ENOMEM); pll->clk_base = clk_base; pll->pmc = pmc; pll->params = pll_params; pll->lock = lock; if (!pll_params->div_nmp) pll_params->div_nmp = &default_nmp; return pll; } static struct clk *_tegra_clk_register_pll(struct tegra_clk_pll *pll, const char *name, const char *parent_name, unsigned long flags, const struct clk_ops *ops) { struct clk_init_data init; init.name = name; init.ops = ops; init.flags = flags; init.parent_names = (parent_name ? &parent_name : NULL); init.num_parents = (parent_name ? 1 : 0); /* Default to _calc_rate if unspecified */ if (!pll->params->calc_rate) { if (pll->params->flags & TEGRA_PLLM) pll->params->calc_rate = _calc_dynamic_ramp_rate; else pll->params->calc_rate = _calc_rate; } if (pll->params->set_defaults) pll->params->set_defaults(pll); /* Data in .init is copied by clk_register(), so stack variable OK */ pll->hw.init = &init; return tegra_clk_dev_register(&pll->hw); } struct clk *tegra_clk_register_pll(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk; pll_params->flags |= TEGRA_PLL_BYPASS; pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pll_ops); if (IS_ERR(clk)) kfree(pll); return clk; } static struct div_nmp pll_e_nmp = { .divn_shift = PLLE_BASE_DIVN_SHIFT, .divn_width = PLLE_BASE_DIVN_WIDTH, .divm_shift = PLLE_BASE_DIVM_SHIFT, .divm_width = PLLE_BASE_DIVM_WIDTH, .divp_shift = PLLE_BASE_DIVP_SHIFT, .divp_width = PLLE_BASE_DIVP_WIDTH, }; struct clk *tegra_clk_register_plle(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk; pll_params->flags |= TEGRA_PLL_BYPASS; if (!pll_params->div_nmp) pll_params->div_nmp = &pll_e_nmp; pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_plle_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk *tegra_clk_register_pllu(const char *name, const char *parent_name, void __iomem *clk_base, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk; pll_params->flags |= TEGRA_PLLU; pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pllu_ops); if (IS_ERR(clk)) kfree(pll); return clk; } #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \ defined(CONFIG_ARCH_TEGRA_124_SOC) || \ defined(CONFIG_ARCH_TEGRA_132_SOC) || \ defined(CONFIG_ARCH_TEGRA_210_SOC) static const struct clk_ops tegra_clk_pllxc_ops = { .is_enabled = clk_pll_is_enabled, .enable = clk_pll_enable, .disable = clk_pll_disable, .recalc_rate = clk_pll_recalc_rate, .round_rate = clk_pll_ramp_round_rate, .set_rate = clk_pllxc_set_rate, }; static const struct clk_ops tegra_clk_pllc_ops = { .is_enabled = clk_pll_is_enabled, .enable = clk_pllc_enable, .disable = clk_pllc_disable, .recalc_rate = clk_pll_recalc_rate, .round_rate = clk_pll_ramp_round_rate, .set_rate = clk_pllc_set_rate, }; static const struct clk_ops tegra_clk_pllre_ops = { .is_enabled = clk_pll_is_enabled, .enable = clk_pll_enable, .disable = clk_pll_disable, .recalc_rate = clk_pllre_recalc_rate, .round_rate = clk_pllre_round_rate, .set_rate = clk_pllre_set_rate, }; static const struct clk_ops tegra_clk_plle_tegra114_ops = { .is_enabled = clk_pll_is_enabled, .enable = clk_plle_tegra114_enable, .disable = clk_plle_tegra114_disable, .recalc_rate = clk_pll_recalc_rate, }; static const struct clk_ops tegra_clk_pllu_tegra114_ops = { .is_enabled = clk_pll_is_enabled, .enable = clk_pllu_tegra114_enable, .disable = clk_pll_disable, .recalc_rate = clk_pll_recalc_rate, }; struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk, *parent; unsigned long parent_rate; u32 val, val_iddq; parent = __clk_lookup(parent_name); if (!parent) { WARN(1, "parent clk %s of %s must be registered first\n", parent_name, name); return ERR_PTR(-EINVAL); } if (!pll_params->pdiv_tohw) return ERR_PTR(-EINVAL); parent_rate = clk_get_rate(parent); pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); if (pll_params->adjust_vco) pll_params->vco_min = pll_params->adjust_vco(pll_params, parent_rate); /* * If the pll has a set_defaults callback, it will take care of * configuring dynamic ramping and setting IDDQ in that path. */ if (!pll_params->set_defaults) { int err; err = _setup_dynamic_ramp(pll_params, clk_base, parent_rate); if (err) return ERR_PTR(err); val = readl_relaxed(clk_base + pll_params->base_reg); val_iddq = readl_relaxed(clk_base + pll_params->iddq_reg); if (val & PLL_BASE_ENABLE) WARN_ON(val_iddq & BIT(pll_params->iddq_bit_idx)); else { val_iddq |= BIT(pll_params->iddq_bit_idx); writel_relaxed(val_iddq, clk_base + pll_params->iddq_reg); } } pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pllxc_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock, unsigned long parent_rate) { u32 val; struct tegra_clk_pll *pll; struct clk *clk; pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); if (pll_params->adjust_vco) pll_params->vco_min = pll_params->adjust_vco(pll_params, parent_rate); pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); /* program minimum rate by default */ val = pll_readl_base(pll); if (val & PLL_BASE_ENABLE) WARN_ON(readl_relaxed(clk_base + pll_params->iddq_reg) & BIT(pll_params->iddq_bit_idx)); else { int m; m = _pll_fixed_mdiv(pll_params, parent_rate); val = m << divm_shift(pll); val |= (pll_params->vco_min / parent_rate) << divn_shift(pll); pll_writel_base(val, pll); } /* disable lock override */ val = pll_readl_misc(pll); val &= ~BIT(29); pll_writel_misc(val, pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pllre_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk, *parent; unsigned long parent_rate; if (!pll_params->pdiv_tohw) return ERR_PTR(-EINVAL); parent = __clk_lookup(parent_name); if (!parent) { WARN(1, "parent clk %s of %s must be registered first\n", parent_name, name); return ERR_PTR(-EINVAL); } parent_rate = clk_get_rate(parent); pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); if (pll_params->adjust_vco) pll_params->vco_min = pll_params->adjust_vco(pll_params, parent_rate); pll_params->flags |= TEGRA_PLL_BYPASS; pll_params->flags |= TEGRA_PLLM; pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pll_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct clk *parent, *clk; const struct pdiv_map *p_tohw = pll_params->pdiv_tohw; struct tegra_clk_pll *pll; struct tegra_clk_pll_freq_table cfg; unsigned long parent_rate; if (!p_tohw) return ERR_PTR(-EINVAL); parent = __clk_lookup(parent_name); if (!parent) { WARN(1, "parent clk %s of %s must be registered first\n", parent_name, name); return ERR_PTR(-EINVAL); } parent_rate = clk_get_rate(parent); pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); pll_params->flags |= TEGRA_PLL_BYPASS; pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); /* * Most of PLLC register fields are shadowed, and can not be read * directly from PLL h/w. Hence, actual PLLC boot state is unknown. * Initialize PLL to default state: disabled, reset; shadow registers * loaded with default parameters; dividers are preset for half of * minimum VCO rate (the latter assured that shadowed divider settings * are within supported range). */ cfg.m = _pll_fixed_mdiv(pll_params, parent_rate); cfg.n = cfg.m * pll_params->vco_min / parent_rate; while (p_tohw->pdiv) { if (p_tohw->pdiv == 2) { cfg.p = p_tohw->hw_val; break; } p_tohw++; } if (!p_tohw->pdiv) { WARN_ON(1); return ERR_PTR(-EINVAL); } pll_writel_base(0, pll); _update_pll_mnp(pll, &cfg); pll_writel_misc(PLLCX_MISC_DEFAULT, pll); pll_writel(PLLCX_MISC1_DEFAULT, pll_params->ext_misc_reg[0], pll); pll_writel(PLLCX_MISC2_DEFAULT, pll_params->ext_misc_reg[1], pll); pll_writel(PLLCX_MISC3_DEFAULT, pll_params->ext_misc_reg[2], pll); _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pllc_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk *tegra_clk_register_plle_tegra114(const char *name, const char *parent_name, void __iomem *clk_base, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk; pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); _clk_plle_tegra_init_parent(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_plle_tegra114_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk * tegra_clk_register_pllu_tegra114(const char *name, const char *parent_name, void __iomem *clk_base, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk; pll_params->flags |= TEGRA_PLLU; pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pllu_tegra114_ops); if (IS_ERR(clk)) kfree(pll); return clk; } #endif #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC) || defined(CONFIG_ARCH_TEGRA_210_SOC) static const struct clk_ops tegra_clk_pllss_ops = { .is_enabled = clk_pll_is_enabled, .enable = clk_pll_enable, .disable = clk_pll_disable, .recalc_rate = clk_pll_recalc_rate, .round_rate = clk_pll_ramp_round_rate, .set_rate = clk_pllxc_set_rate, .restore_context = tegra_clk_pll_restore_context, }; struct clk *tegra_clk_register_pllss(const char *name, const char *parent_name, void __iomem *clk_base, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk, *parent; struct tegra_clk_pll_freq_table cfg; unsigned long parent_rate; u32 val, val_iddq; int i; if (!pll_params->div_nmp) return ERR_PTR(-EINVAL); parent = __clk_lookup(parent_name); if (!parent) { WARN(1, "parent clk %s of %s must be registered first\n", parent_name, name); return ERR_PTR(-EINVAL); } pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); val = pll_readl_base(pll); val &= ~PLLSS_REF_SRC_SEL_MASK; pll_writel_base(val, pll); parent_rate = clk_get_rate(parent); pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); /* initialize PLL to minimum rate */ cfg.m = _pll_fixed_mdiv(pll_params, parent_rate); cfg.n = cfg.m * pll_params->vco_min / parent_rate; for (i = 0; pll_params->pdiv_tohw[i].pdiv; i++) ; if (!i) { kfree(pll); return ERR_PTR(-EINVAL); } cfg.p = pll_params->pdiv_tohw[i-1].hw_val; _update_pll_mnp(pll, &cfg); pll_writel_misc(PLLSS_MISC_DEFAULT, pll); pll_writel(PLLSS_CFG_DEFAULT, pll_params->ext_misc_reg[0], pll); pll_writel(PLLSS_CTRL1_DEFAULT, pll_params->ext_misc_reg[1], pll); pll_writel(PLLSS_CTRL1_DEFAULT, pll_params->ext_misc_reg[2], pll); val = pll_readl_base(pll); val_iddq = readl_relaxed(clk_base + pll_params->iddq_reg); if (val & PLL_BASE_ENABLE) { if (val_iddq & BIT(pll_params->iddq_bit_idx)) { WARN(1, "%s is on but IDDQ set\n", name); kfree(pll); return ERR_PTR(-EINVAL); } } else { val_iddq |= BIT(pll_params->iddq_bit_idx); writel_relaxed(val_iddq, clk_base + pll_params->iddq_reg); } val &= ~PLLSS_LOCK_OVERRIDE; pll_writel_base(val, pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pllss_ops); if (IS_ERR(clk)) kfree(pll); return clk; } #endif #if defined(CONFIG_ARCH_TEGRA_210_SOC) struct clk *tegra_clk_register_pllre_tegra210(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock, unsigned long parent_rate) { struct tegra_clk_pll *pll; struct clk *clk; pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); if (pll_params->adjust_vco) pll_params->vco_min = pll_params->adjust_vco(pll_params, parent_rate); pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pll_ops); if (IS_ERR(clk)) kfree(pll); return clk; } static int clk_plle_tegra210_is_enabled(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); u32 val; val = pll_readl_base(pll); return val & PLLE_BASE_ENABLE ? 1 : 0; } static int clk_plle_tegra210_enable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); struct tegra_clk_pll_freq_table sel; u32 val; int ret = 0; unsigned long flags = 0; unsigned long input_rate; if (clk_plle_tegra210_is_enabled(hw)) return 0; input_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate)) return -EINVAL; if (pll->lock) spin_lock_irqsave(pll->lock, flags); val = pll_readl(pll->params->aux_reg, pll); if (val & PLLE_AUX_SEQ_ENABLE) goto out; val = pll_readl_base(pll); val &= ~BIT(30); /* Disable lock override */ pll_writel_base(val, pll); val = pll_readl_misc(pll); val |= PLLE_MISC_LOCK_ENABLE; val |= PLLE_MISC_IDDQ_SW_CTRL; val &= ~PLLE_MISC_IDDQ_SW_VALUE; val |= PLLE_MISC_PLLE_PTS; val &= ~(PLLE_MISC_VREG_BG_CTRL_MASK | PLLE_MISC_VREG_CTRL_MASK); pll_writel_misc(val, pll); udelay(5); val = pll_readl(PLLE_SS_CTRL, pll); val |= PLLE_SS_DISABLE; pll_writel(val, PLLE_SS_CTRL, pll); val = pll_readl_base(pll); val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) | divm_mask_shifted(pll)); val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT); val |= sel.m << divm_shift(pll); val |= sel.n << divn_shift(pll); val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT; pll_writel_base(val, pll); udelay(1); val = pll_readl_base(pll); val |= PLLE_BASE_ENABLE; pll_writel_base(val, pll); ret = clk_pll_wait_for_lock(pll); if (ret < 0) goto out; val = pll_readl(PLLE_SS_CTRL, pll); val &= ~(PLLE_SS_CNTL_CENTER | PLLE_SS_CNTL_INVERT); val &= ~PLLE_SS_COEFFICIENTS_MASK; val |= PLLE_SS_COEFFICIENTS_VAL_TEGRA210; pll_writel(val, PLLE_SS_CTRL, pll); val &= ~(PLLE_SS_CNTL_SSC_BYP | PLLE_SS_CNTL_BYPASS_SS); pll_writel(val, PLLE_SS_CTRL, pll); udelay(1); val &= ~PLLE_SS_CNTL_INTERP_RESET; pll_writel(val, PLLE_SS_CTRL, pll); udelay(1); out: if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static void clk_plle_tegra210_disable(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); unsigned long flags = 0; u32 val; if (pll->lock) spin_lock_irqsave(pll->lock, flags); /* If PLLE HW sequencer is enabled, SW should not disable PLLE */ val = pll_readl(pll->params->aux_reg, pll); if (val & PLLE_AUX_SEQ_ENABLE) goto out; val = pll_readl_base(pll); val &= ~PLLE_BASE_ENABLE; pll_writel_base(val, pll); val = pll_readl(pll->params->aux_reg, pll); val |= PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL; pll_writel(val, pll->params->aux_reg, pll); val = pll_readl_misc(pll); val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE; pll_writel_misc(val, pll); udelay(1); out: if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); } static void tegra_clk_plle_t210_restore_context(struct clk_hw *hw) { struct tegra_clk_pll *pll = to_clk_pll(hw); _clk_plle_tegra_init_parent(pll); } static const struct clk_ops tegra_clk_plle_tegra210_ops = { .is_enabled = clk_plle_tegra210_is_enabled, .enable = clk_plle_tegra210_enable, .disable = clk_plle_tegra210_disable, .recalc_rate = clk_pll_recalc_rate, .restore_context = tegra_clk_plle_t210_restore_context, }; struct clk *tegra_clk_register_plle_tegra210(const char *name, const char *parent_name, void __iomem *clk_base, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk; pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); _clk_plle_tegra_init_parent(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_plle_tegra210_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk *tegra_clk_register_pllc_tegra210(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct clk *parent, *clk; const struct pdiv_map *p_tohw = pll_params->pdiv_tohw; struct tegra_clk_pll *pll; unsigned long parent_rate; if (!p_tohw) return ERR_PTR(-EINVAL); parent = __clk_lookup(parent_name); if (!parent) { WARN(1, "parent clk %s of %s must be registered first\n", name, parent_name); return ERR_PTR(-EINVAL); } parent_rate = clk_get_rate(parent); pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); if (pll_params->adjust_vco) pll_params->vco_min = pll_params->adjust_vco(pll_params, parent_rate); pll_params->flags |= TEGRA_PLL_BYPASS; pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pll_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk *tegra_clk_register_pllss_tegra210(const char *name, const char *parent_name, void __iomem *clk_base, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk, *parent; unsigned long parent_rate; u32 val; if (!pll_params->div_nmp) return ERR_PTR(-EINVAL); parent = __clk_lookup(parent_name); if (!parent) { WARN(1, "parent clk %s of %s must be registered first\n", name, parent_name); return ERR_PTR(-EINVAL); } val = readl_relaxed(clk_base + pll_params->base_reg); if (val & PLLSS_REF_SRC_SEL_MASK) { WARN(1, "not supported reference clock for %s\n", name); return ERR_PTR(-EINVAL); } parent_rate = clk_get_rate(parent); pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); if (pll_params->adjust_vco) pll_params->vco_min = pll_params->adjust_vco(pll_params, parent_rate); pll_params->flags |= TEGRA_PLL_BYPASS; pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pll_ops); if (IS_ERR(clk)) kfree(pll); return clk; } struct clk *tegra_clk_register_pllmb(const char *name, const char *parent_name, void __iomem *clk_base, void __iomem *pmc, unsigned long flags, struct tegra_clk_pll_params *pll_params, spinlock_t *lock) { struct tegra_clk_pll *pll; struct clk *clk, *parent; unsigned long parent_rate; if (!pll_params->pdiv_tohw) return ERR_PTR(-EINVAL); parent = __clk_lookup(parent_name); if (!parent) { WARN(1, "parent clk %s of %s must be registered first\n", parent_name, name); return ERR_PTR(-EINVAL); } parent_rate = clk_get_rate(parent); pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); if (pll_params->adjust_vco) pll_params->vco_min = pll_params->adjust_vco(pll_params, parent_rate); pll_params->flags |= TEGRA_PLL_BYPASS; pll_params->flags |= TEGRA_PLLMB; pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); if (IS_ERR(pll)) return ERR_CAST(pll); clk = _tegra_clk_register_pll(pll, name, parent_name, flags, &tegra_clk_pll_ops); if (IS_ERR(clk)) kfree(pll); return clk; } #endif
linux-master
drivers/clk/tegra/clk-pll.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/clk-provider.h> #include <linux/slab.h> #include <linux/io.h> #include <linux/delay.h> #include <linux/err.h> #include <soc/tegra/fuse.h> #include "clk.h" static DEFINE_SPINLOCK(periph_ref_lock); /* Macros to assist peripheral gate clock */ #define read_enb(gate) \ readl_relaxed(gate->clk_base + (gate->regs->enb_reg)) #define write_enb_set(val, gate) \ writel_relaxed(val, gate->clk_base + (gate->regs->enb_set_reg)) #define write_enb_clr(val, gate) \ writel_relaxed(val, gate->clk_base + (gate->regs->enb_clr_reg)) #define read_rst(gate) \ readl_relaxed(gate->clk_base + (gate->regs->rst_reg)) #define write_rst_clr(val, gate) \ writel_relaxed(val, gate->clk_base + (gate->regs->rst_clr_reg)) #define periph_clk_to_bit(gate) (1 << (gate->clk_num % 32)) #define LVL2_CLK_GATE_OVRE 0x554 /* Peripheral gate clock ops */ static int clk_periph_is_enabled(struct clk_hw *hw) { struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); int state = 1; if (!(read_enb(gate) & periph_clk_to_bit(gate))) state = 0; if (!(gate->flags & TEGRA_PERIPH_NO_RESET)) if (read_rst(gate) & periph_clk_to_bit(gate)) state = 0; return state; } static void clk_periph_enable_locked(struct clk_hw *hw) { struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); write_enb_set(periph_clk_to_bit(gate), gate); udelay(2); if (gate->flags & TEGRA_PERIPH_WAR_1005168) { writel_relaxed(0, gate->clk_base + LVL2_CLK_GATE_OVRE); writel_relaxed(BIT(22), gate->clk_base + LVL2_CLK_GATE_OVRE); udelay(1); writel_relaxed(0, gate->clk_base + LVL2_CLK_GATE_OVRE); } } static void clk_periph_disable_locked(struct clk_hw *hw) { struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); /* * If peripheral is in the APB bus then read the APB bus to * flush the write operation in apb bus. This will avoid the * peripheral access after disabling clock */ if (gate->flags & TEGRA_PERIPH_ON_APB) tegra_read_chipid(); write_enb_clr(periph_clk_to_bit(gate), gate); } static int clk_periph_enable(struct clk_hw *hw) { struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); unsigned long flags = 0; spin_lock_irqsave(&periph_ref_lock, flags); if (!gate->enable_refcnt[gate->clk_num]++) clk_periph_enable_locked(hw); spin_unlock_irqrestore(&periph_ref_lock, flags); return 0; } static void clk_periph_disable(struct clk_hw *hw) { struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); unsigned long flags = 0; spin_lock_irqsave(&periph_ref_lock, flags); WARN_ON(!gate->enable_refcnt[gate->clk_num]); if (--gate->enable_refcnt[gate->clk_num] == 0) clk_periph_disable_locked(hw); spin_unlock_irqrestore(&periph_ref_lock, flags); } static void clk_periph_disable_unused(struct clk_hw *hw) { struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); unsigned long flags = 0; spin_lock_irqsave(&periph_ref_lock, flags); /* * Some clocks are duplicated and some of them are marked as critical, * like fuse and fuse_burn for example, thus the enable_refcnt will * be non-zero here if the "unused" duplicate is disabled by CCF. */ if (!gate->enable_refcnt[gate->clk_num]) clk_periph_disable_locked(hw); spin_unlock_irqrestore(&periph_ref_lock, flags); } const struct clk_ops tegra_clk_periph_gate_ops = { .is_enabled = clk_periph_is_enabled, .enable = clk_periph_enable, .disable = clk_periph_disable, .disable_unused = clk_periph_disable_unused, }; struct clk *tegra_clk_register_periph_gate(const char *name, const char *parent_name, u8 gate_flags, void __iomem *clk_base, unsigned long flags, int clk_num, int *enable_refcnt) { struct tegra_clk_periph_gate *gate; struct clk *clk; struct clk_init_data init; const struct tegra_clk_periph_regs *pregs; pregs = get_reg_bank(clk_num); if (!pregs) return ERR_PTR(-EINVAL); gate = kzalloc(sizeof(*gate), GFP_KERNEL); if (!gate) { pr_err("%s: could not allocate periph gate clk\n", __func__); return ERR_PTR(-ENOMEM); } init.name = name; init.flags = flags; init.parent_names = parent_name ? &parent_name : NULL; init.num_parents = parent_name ? 1 : 0; init.ops = &tegra_clk_periph_gate_ops; gate->magic = TEGRA_CLK_PERIPH_GATE_MAGIC; gate->clk_base = clk_base; gate->clk_num = clk_num; gate->flags = gate_flags; gate->enable_refcnt = enable_refcnt; gate->regs = pregs; /* Data in .init is copied by clk_register(), so stack variable OK */ gate->hw.init = &init; clk = clk_register(NULL, &gate->hw); if (IS_ERR(clk)) kfree(gate); return clk; }
linux-master
drivers/clk/tegra/clk-periph-gate.c
// SPDX-License-Identifier: GPL-2.0-only /* * Based on clk-super.c * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. * * Based on older tegra20-cpufreq driver by Colin Cross <[email protected]> * Copyright (C) 2010 Google, Inc. * * Author: Dmitry Osipenko <[email protected]> * Copyright (C) 2019 GRATE-DRIVER project */ #include <linux/bits.h> #include <linux/clk-provider.h> #include <linux/err.h> #include <linux/io.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/types.h> #include "clk.h" #define PLLP_INDEX 4 #define PLLX_INDEX 8 #define SUPER_CDIV_ENB BIT(31) #define TSENSOR_SLOWDOWN BIT(23) static struct tegra_clk_super_mux *cclk_super; static bool cclk_on_pllx; static u8 cclk_super_get_parent(struct clk_hw *hw) { return tegra_clk_super_ops.get_parent(hw); } static int cclk_super_set_parent(struct clk_hw *hw, u8 index) { return tegra_clk_super_ops.set_parent(hw, index); } static int cclk_super_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { return tegra_clk_super_ops.set_rate(hw, rate, parent_rate); } static unsigned long cclk_super_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_super_mux *super = to_clk_super_mux(hw); u32 val = readl_relaxed(super->reg); unsigned int div2; /* check whether thermal throttling is active */ if (val & TSENSOR_SLOWDOWN) div2 = 1; else div2 = 0; if (cclk_super_get_parent(hw) == PLLX_INDEX) return parent_rate >> div2; return tegra_clk_super_ops.recalc_rate(hw, parent_rate) >> div2; } static int cclk_super_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_hw *pllp_hw = clk_hw_get_parent_by_index(hw, PLLP_INDEX); struct clk_hw *pllx_hw = clk_hw_get_parent_by_index(hw, PLLX_INDEX); struct tegra_clk_super_mux *super = to_clk_super_mux(hw); unsigned long pllp_rate; long rate = req->rate; if (WARN_ON_ONCE(!pllp_hw || !pllx_hw)) return -EINVAL; /* * Switch parent to PLLP for all CCLK rates that are suitable for PLLP. * PLLX will be disabled in this case, saving some power. */ pllp_rate = clk_hw_get_rate(pllp_hw); if (rate <= pllp_rate) { if (super->flags & TEGRA20_SUPER_CLK) rate = pllp_rate; else { struct clk_rate_request parent = { .rate = req->rate, .best_parent_rate = pllp_rate, }; clk_hw_get_rate_range(hw, &parent.min_rate, &parent.max_rate); tegra_clk_super_ops.determine_rate(hw, &parent); pllp_rate = parent.best_parent_rate; rate = parent.rate; } req->best_parent_rate = pllp_rate; req->best_parent_hw = pllp_hw; req->rate = rate; } else { rate = clk_hw_round_rate(pllx_hw, rate); req->best_parent_rate = rate; req->best_parent_hw = pllx_hw; req->rate = rate; } if (WARN_ON_ONCE(rate <= 0)) return -EINVAL; return 0; } static const struct clk_ops tegra_cclk_super_ops = { .get_parent = cclk_super_get_parent, .set_parent = cclk_super_set_parent, .set_rate = cclk_super_set_rate, .recalc_rate = cclk_super_recalc_rate, .determine_rate = cclk_super_determine_rate, }; static const struct clk_ops tegra_cclk_super_mux_ops = { .get_parent = cclk_super_get_parent, .set_parent = cclk_super_set_parent, .determine_rate = cclk_super_determine_rate, }; struct clk *tegra_clk_register_super_cclk(const char *name, const char * const *parent_names, u8 num_parents, unsigned long flags, void __iomem *reg, u8 clk_super_flags, spinlock_t *lock) { struct tegra_clk_super_mux *super; struct clk *clk; struct clk_init_data init; u32 val; if (WARN_ON(cclk_super)) return ERR_PTR(-EBUSY); super = kzalloc(sizeof(*super), GFP_KERNEL); if (!super) return ERR_PTR(-ENOMEM); init.name = name; init.flags = flags; init.parent_names = parent_names; init.num_parents = num_parents; super->reg = reg; super->lock = lock; super->width = 4; super->flags = clk_super_flags; super->hw.init = &init; if (super->flags & TEGRA20_SUPER_CLK) { init.ops = &tegra_cclk_super_mux_ops; } else { init.ops = &tegra_cclk_super_ops; super->frac_div.reg = reg + 4; super->frac_div.shift = 16; super->frac_div.width = 8; super->frac_div.frac_width = 1; super->frac_div.lock = lock; super->div_ops = &tegra_clk_frac_div_ops; } /* * Tegra30+ has the following CPUG clock topology: * * +---+ +-------+ +-+ +-+ +-+ * PLLP+->+ +->+DIVIDER+->+0| +-------->+0| ------------->+0| * | | +-------+ | | | +---+ | | | | | * PLLC+->+MUX| | +->+ | S | | +->+ | +->+CPU * ... | | | | | | K | | | | +-------+ | | * PLLX+->+-->+------------>+1| +->+ I +->+1| +->+ DIV2 +->+1| * +---+ +++ | P | +++ |SKIPPER| +++ * ^ | P | ^ +-------+ ^ * | | E | | | * PLLX_SEL+--+ | R | | OVERHEAT+--+ * +---+ | * | * SUPER_CDIV_ENB+--+ * * Tegra20 is similar, but simpler. It doesn't have the divider and * thermal DIV2 skipper. * * At least for now we're not going to use clock-skipper, hence let's * ensure that it is disabled. */ val = readl_relaxed(reg + 4); val &= ~SUPER_CDIV_ENB; writel_relaxed(val, reg + 4); clk = clk_register(NULL, &super->hw); if (IS_ERR(clk)) kfree(super); else cclk_super = super; return clk; } int tegra_cclk_pre_pllx_rate_change(void) { if (IS_ERR_OR_NULL(cclk_super)) return -EINVAL; if (cclk_super_get_parent(&cclk_super->hw) == PLLX_INDEX) cclk_on_pllx = true; else cclk_on_pllx = false; /* * CPU needs to be temporarily re-parented away from PLLX if PLLX * changes its rate. PLLP is a safe parent for CPU on all Tegra SoCs. */ if (cclk_on_pllx) cclk_super_set_parent(&cclk_super->hw, PLLP_INDEX); return 0; } void tegra_cclk_post_pllx_rate_change(void) { if (cclk_on_pllx) cclk_super_set_parent(&cclk_super->hw, PLLX_INDEX); }
linux-master
drivers/clk/tegra/clk-tegra-super-cclk.c
// SPDX-License-Identifier: GPL-2.0+ /* * Based on drivers/clk/tegra/clk-emc.c * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. * * Author: Dmitry Osipenko <[email protected]> * Copyright (C) 2019 GRATE-DRIVER project */ #define pr_fmt(fmt) "tegra-emc-clk: " fmt #include <linux/bits.h> #include <linux/clk-provider.h> #include <linux/clk/tegra.h> #include <linux/err.h> #include <linux/export.h> #include <linux/io.h> #include <linux/kernel.h> #include <linux/slab.h> #include "clk.h" #define CLK_SOURCE_EMC_2X_CLK_DIVISOR_MASK GENMASK(7, 0) #define CLK_SOURCE_EMC_2X_CLK_SRC_MASK GENMASK(31, 30) #define CLK_SOURCE_EMC_2X_CLK_SRC_SHIFT 30 #define MC_EMC_SAME_FREQ BIT(16) #define USE_PLLM_UD BIT(29) #define EMC_SRC_PLL_M 0 #define EMC_SRC_PLL_C 1 #define EMC_SRC_PLL_P 2 #define EMC_SRC_CLK_M 3 static const char * const emc_parent_clk_names[] = { "pll_m", "pll_c", "pll_p", "clk_m", }; struct tegra_clk_emc { struct clk_hw hw; void __iomem *reg; bool mc_same_freq; bool want_low_jitter; tegra20_clk_emc_round_cb *round_cb; void *cb_arg; }; static inline struct tegra_clk_emc *to_tegra_clk_emc(struct clk_hw *hw) { return container_of(hw, struct tegra_clk_emc, hw); } static unsigned long emc_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_emc *emc = to_tegra_clk_emc(hw); u32 val, div; val = readl_relaxed(emc->reg); div = val & CLK_SOURCE_EMC_2X_CLK_DIVISOR_MASK; return DIV_ROUND_UP(parent_rate * 2, div + 2); } static u8 emc_get_parent(struct clk_hw *hw) { struct tegra_clk_emc *emc = to_tegra_clk_emc(hw); return readl_relaxed(emc->reg) >> CLK_SOURCE_EMC_2X_CLK_SRC_SHIFT; } static int emc_set_parent(struct clk_hw *hw, u8 index) { struct tegra_clk_emc *emc = to_tegra_clk_emc(hw); u32 val, div; val = readl_relaxed(emc->reg); val &= ~CLK_SOURCE_EMC_2X_CLK_SRC_MASK; val |= index << CLK_SOURCE_EMC_2X_CLK_SRC_SHIFT; div = val & CLK_SOURCE_EMC_2X_CLK_DIVISOR_MASK; if (index == EMC_SRC_PLL_M && div == 0 && emc->want_low_jitter) val |= USE_PLLM_UD; else val &= ~USE_PLLM_UD; if (emc->mc_same_freq) val |= MC_EMC_SAME_FREQ; else val &= ~MC_EMC_SAME_FREQ; writel_relaxed(val, emc->reg); fence_udelay(1, emc->reg); return 0; } static int emc_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_emc *emc = to_tegra_clk_emc(hw); unsigned int index; u32 val, div; div = div_frac_get(rate, parent_rate, 8, 1, 0); val = readl_relaxed(emc->reg); val &= ~CLK_SOURCE_EMC_2X_CLK_DIVISOR_MASK; val |= div; index = val >> CLK_SOURCE_EMC_2X_CLK_SRC_SHIFT; if (index == EMC_SRC_PLL_M && div == 0 && emc->want_low_jitter) val |= USE_PLLM_UD; else val &= ~USE_PLLM_UD; if (emc->mc_same_freq) val |= MC_EMC_SAME_FREQ; else val &= ~MC_EMC_SAME_FREQ; writel_relaxed(val, emc->reg); fence_udelay(1, emc->reg); return 0; } static int emc_set_rate_and_parent(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate, u8 index) { struct tegra_clk_emc *emc = to_tegra_clk_emc(hw); u32 val, div; div = div_frac_get(rate, parent_rate, 8, 1, 0); val = readl_relaxed(emc->reg); val &= ~CLK_SOURCE_EMC_2X_CLK_SRC_MASK; val |= index << CLK_SOURCE_EMC_2X_CLK_SRC_SHIFT; val &= ~CLK_SOURCE_EMC_2X_CLK_DIVISOR_MASK; val |= div; if (index == EMC_SRC_PLL_M && div == 0 && emc->want_low_jitter) val |= USE_PLLM_UD; else val &= ~USE_PLLM_UD; if (emc->mc_same_freq) val |= MC_EMC_SAME_FREQ; else val &= ~MC_EMC_SAME_FREQ; writel_relaxed(val, emc->reg); fence_udelay(1, emc->reg); return 0; } static int emc_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct tegra_clk_emc *emc = to_tegra_clk_emc(hw); struct clk_hw *parent_hw; unsigned long divided_rate; unsigned long parent_rate; unsigned int i; long emc_rate; int div; emc_rate = emc->round_cb(req->rate, req->min_rate, req->max_rate, emc->cb_arg); if (emc_rate < 0) return emc_rate; for (i = 0; i < ARRAY_SIZE(emc_parent_clk_names); i++) { parent_hw = clk_hw_get_parent_by_index(hw, i); if (req->best_parent_hw == parent_hw) parent_rate = req->best_parent_rate; else parent_rate = clk_hw_get_rate(parent_hw); if (emc_rate > parent_rate) continue; div = div_frac_get(emc_rate, parent_rate, 8, 1, 0); divided_rate = DIV_ROUND_UP(parent_rate * 2, div + 2); if (divided_rate != emc_rate) continue; req->best_parent_rate = parent_rate; req->best_parent_hw = parent_hw; req->rate = emc_rate; break; } if (i == ARRAY_SIZE(emc_parent_clk_names)) { pr_err_once("can't find parent for rate %lu emc_rate %lu\n", req->rate, emc_rate); return -EINVAL; } return 0; } static const struct clk_ops tegra_clk_emc_ops = { .recalc_rate = emc_recalc_rate, .get_parent = emc_get_parent, .set_parent = emc_set_parent, .set_rate = emc_set_rate, .set_rate_and_parent = emc_set_rate_and_parent, .determine_rate = emc_determine_rate, }; void tegra20_clk_set_emc_round_callback(tegra20_clk_emc_round_cb *round_cb, void *cb_arg) { struct clk *clk = __clk_lookup("emc"); struct tegra_clk_emc *emc; struct clk_hw *hw; if (clk) { hw = __clk_get_hw(clk); emc = to_tegra_clk_emc(hw); emc->round_cb = round_cb; emc->cb_arg = cb_arg; } } EXPORT_SYMBOL_GPL(tegra20_clk_set_emc_round_callback); bool tegra20_clk_emc_driver_available(struct clk_hw *emc_hw) { return to_tegra_clk_emc(emc_hw)->round_cb != NULL; } struct clk *tegra20_clk_register_emc(void __iomem *ioaddr, bool low_jitter) { struct tegra_clk_emc *emc; struct clk_init_data init; struct clk *clk; emc = kzalloc(sizeof(*emc), GFP_KERNEL); if (!emc) return NULL; /* * EMC stands for External Memory Controller. * * We don't want EMC clock to be disabled ever by gating its * parent and whatnot because system is busted immediately in that * case, hence the clock is marked as critical. */ init.name = "emc"; init.ops = &tegra_clk_emc_ops; init.flags = CLK_IS_CRITICAL; init.parent_names = emc_parent_clk_names; init.num_parents = ARRAY_SIZE(emc_parent_clk_names); emc->reg = ioaddr; emc->hw.init = &init; emc->want_low_jitter = low_jitter; clk = clk_register(NULL, &emc->hw); if (IS_ERR(clk)) { kfree(emc); return NULL; } return clk; } int tegra20_clk_prepare_emc_mc_same_freq(struct clk *emc_clk, bool same) { struct tegra_clk_emc *emc; struct clk_hw *hw; if (!emc_clk) return -EINVAL; hw = __clk_get_hw(emc_clk); emc = to_tegra_clk_emc(hw); emc->mc_same_freq = same; return 0; } EXPORT_SYMBOL_GPL(tegra20_clk_prepare_emc_mc_same_freq);
linux-master
drivers/clk/tegra/clk-tegra20-emc.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/clk/tegra.h> #include "clk.h" #include "clk-id.h" #define OSC_CTRL 0x50 #define OSC_CTRL_OSC_FREQ_SHIFT 28 #define OSC_CTRL_PLL_REF_DIV_SHIFT 26 #define OSC_CTRL_MASK (0x3f2 | \ (0xf << OSC_CTRL_OSC_FREQ_SHIFT)) static u32 osc_ctrl_ctx; int __init tegra_osc_clk_init(void __iomem *clk_base, struct tegra_clk *clks, unsigned long *input_freqs, unsigned int num, unsigned int clk_m_div, unsigned long *osc_freq, unsigned long *pll_ref_freq) { struct clk *clk, *osc; struct clk **dt_clk; u32 val, pll_ref_div; unsigned osc_idx; val = readl_relaxed(clk_base + OSC_CTRL); osc_ctrl_ctx = val & OSC_CTRL_MASK; osc_idx = val >> OSC_CTRL_OSC_FREQ_SHIFT; if (osc_idx < num) *osc_freq = input_freqs[osc_idx]; else *osc_freq = 0; if (!*osc_freq) { WARN_ON(1); return -EINVAL; } dt_clk = tegra_lookup_dt_id(tegra_clk_osc, clks); if (!dt_clk) return 0; osc = clk_register_fixed_rate(NULL, "osc", NULL, 0, *osc_freq); *dt_clk = osc; /* osc_div2 */ dt_clk = tegra_lookup_dt_id(tegra_clk_osc_div2, clks); if (dt_clk) { clk = clk_register_fixed_factor(NULL, "osc_div2", "osc", 0, 1, 2); *dt_clk = clk; } /* osc_div4 */ dt_clk = tegra_lookup_dt_id(tegra_clk_osc_div4, clks); if (dt_clk) { clk = clk_register_fixed_factor(NULL, "osc_div4", "osc", 0, 1, 4); *dt_clk = clk; } dt_clk = tegra_lookup_dt_id(tegra_clk_clk_m, clks); if (!dt_clk) return 0; clk = clk_register_fixed_factor(NULL, "clk_m", "osc", 0, 1, clk_m_div); *dt_clk = clk; /* pll_ref */ val = (val >> OSC_CTRL_PLL_REF_DIV_SHIFT) & 3; pll_ref_div = 1 << val; dt_clk = tegra_lookup_dt_id(tegra_clk_pll_ref, clks); if (!dt_clk) return 0; clk = clk_register_fixed_factor(NULL, "pll_ref", "osc", 0, 1, pll_ref_div); *dt_clk = clk; if (pll_ref_freq) *pll_ref_freq = *osc_freq / pll_ref_div; return 0; } void __init tegra_fixed_clk_init(struct tegra_clk *tegra_clks) { struct clk *clk; struct clk **dt_clk; /* clk_32k */ dt_clk = tegra_lookup_dt_id(tegra_clk_clk_32k, tegra_clks); if (dt_clk) { clk = clk_register_fixed_rate(NULL, "clk_32k", NULL, 0, 32768); *dt_clk = clk; } } void tegra_clk_osc_resume(void __iomem *clk_base) { u32 val; val = readl_relaxed(clk_base + OSC_CTRL) & ~OSC_CTRL_MASK; val |= osc_ctrl_ctx; writel_relaxed(val, clk_base + OSC_CTRL); fence_udelay(2, clk_base); }
linux-master
drivers/clk/tegra/clk-tegra-fixed.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/clkdev.h> #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/delay.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_platform.h> #include <linux/clk/tegra.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/reset-controller.h> #include <linux/string_helpers.h> #include <soc/tegra/fuse.h> #include "clk.h" /* Global data of Tegra CPU CAR ops */ static struct device_node *tegra_car_np; static struct tegra_cpu_car_ops dummy_car_ops; struct tegra_cpu_car_ops *tegra_cpu_car_ops = &dummy_car_ops; int *periph_clk_enb_refcnt; static int periph_banks; static u32 *periph_state_ctx; static struct clk **clks; static int clk_num; static struct clk_onecell_data clk_data; /* Handlers for SoC-specific reset lines */ static int (*special_reset_assert)(unsigned long); static int (*special_reset_deassert)(unsigned long); static unsigned int num_special_reset; static const struct tegra_clk_periph_regs periph_regs[] = { [0] = { .enb_reg = CLK_OUT_ENB_L, .enb_set_reg = CLK_OUT_ENB_SET_L, .enb_clr_reg = CLK_OUT_ENB_CLR_L, .rst_reg = RST_DEVICES_L, .rst_set_reg = RST_DEVICES_SET_L, .rst_clr_reg = RST_DEVICES_CLR_L, }, [1] = { .enb_reg = CLK_OUT_ENB_H, .enb_set_reg = CLK_OUT_ENB_SET_H, .enb_clr_reg = CLK_OUT_ENB_CLR_H, .rst_reg = RST_DEVICES_H, .rst_set_reg = RST_DEVICES_SET_H, .rst_clr_reg = RST_DEVICES_CLR_H, }, [2] = { .enb_reg = CLK_OUT_ENB_U, .enb_set_reg = CLK_OUT_ENB_SET_U, .enb_clr_reg = CLK_OUT_ENB_CLR_U, .rst_reg = RST_DEVICES_U, .rst_set_reg = RST_DEVICES_SET_U, .rst_clr_reg = RST_DEVICES_CLR_U, }, [3] = { .enb_reg = CLK_OUT_ENB_V, .enb_set_reg = CLK_OUT_ENB_SET_V, .enb_clr_reg = CLK_OUT_ENB_CLR_V, .rst_reg = RST_DEVICES_V, .rst_set_reg = RST_DEVICES_SET_V, .rst_clr_reg = RST_DEVICES_CLR_V, }, [4] = { .enb_reg = CLK_OUT_ENB_W, .enb_set_reg = CLK_OUT_ENB_SET_W, .enb_clr_reg = CLK_OUT_ENB_CLR_W, .rst_reg = RST_DEVICES_W, .rst_set_reg = RST_DEVICES_SET_W, .rst_clr_reg = RST_DEVICES_CLR_W, }, [5] = { .enb_reg = CLK_OUT_ENB_X, .enb_set_reg = CLK_OUT_ENB_SET_X, .enb_clr_reg = CLK_OUT_ENB_CLR_X, .rst_reg = RST_DEVICES_X, .rst_set_reg = RST_DEVICES_SET_X, .rst_clr_reg = RST_DEVICES_CLR_X, }, [6] = { .enb_reg = CLK_OUT_ENB_Y, .enb_set_reg = CLK_OUT_ENB_SET_Y, .enb_clr_reg = CLK_OUT_ENB_CLR_Y, .rst_reg = RST_DEVICES_Y, .rst_set_reg = RST_DEVICES_SET_Y, .rst_clr_reg = RST_DEVICES_CLR_Y, }, }; static void __iomem *clk_base; static int tegra_clk_rst_assert(struct reset_controller_dev *rcdev, unsigned long id) { /* * If peripheral is on the APB bus then we must read the APB bus to * flush the write operation in apb bus. This will avoid peripheral * access after disabling clock. Since the reset driver has no * knowledge of which reset IDs represent which devices, simply do * this all the time. */ tegra_read_chipid(); if (id < periph_banks * 32) { writel_relaxed(BIT(id % 32), clk_base + periph_regs[id / 32].rst_set_reg); return 0; } else if (id < periph_banks * 32 + num_special_reset) { return special_reset_assert(id); } return -EINVAL; } static int tegra_clk_rst_deassert(struct reset_controller_dev *rcdev, unsigned long id) { if (id < periph_banks * 32) { writel_relaxed(BIT(id % 32), clk_base + periph_regs[id / 32].rst_clr_reg); return 0; } else if (id < periph_banks * 32 + num_special_reset) { return special_reset_deassert(id); } return -EINVAL; } static int tegra_clk_rst_reset(struct reset_controller_dev *rcdev, unsigned long id) { int err; err = tegra_clk_rst_assert(rcdev, id); if (err) return err; udelay(1); return tegra_clk_rst_deassert(rcdev, id); } const struct tegra_clk_periph_regs *get_reg_bank(int clkid) { int reg_bank = clkid / 32; if (reg_bank < periph_banks) return &periph_regs[reg_bank]; else { WARN_ON(1); return NULL; } } void tegra_clk_set_pllp_out_cpu(bool enable) { u32 val; val = readl_relaxed(clk_base + CLK_OUT_ENB_Y); if (enable) val |= CLK_ENB_PLLP_OUT_CPU; else val &= ~CLK_ENB_PLLP_OUT_CPU; writel_relaxed(val, clk_base + CLK_OUT_ENB_Y); } void tegra_clk_periph_suspend(void) { unsigned int i, idx; idx = 0; for (i = 0; i < periph_banks; i++, idx++) periph_state_ctx[idx] = readl_relaxed(clk_base + periph_regs[i].enb_reg); for (i = 0; i < periph_banks; i++, idx++) periph_state_ctx[idx] = readl_relaxed(clk_base + periph_regs[i].rst_reg); } void tegra_clk_periph_resume(void) { unsigned int i, idx; idx = 0; for (i = 0; i < periph_banks; i++, idx++) writel_relaxed(periph_state_ctx[idx], clk_base + periph_regs[i].enb_reg); /* * All non-boot peripherals will be in reset state on resume. * Wait for 5us of reset propagation delay before de-asserting * the peripherals based on the saved context. */ fence_udelay(5, clk_base); for (i = 0; i < periph_banks; i++, idx++) writel_relaxed(periph_state_ctx[idx], clk_base + periph_regs[i].rst_reg); fence_udelay(2, clk_base); } static int tegra_clk_periph_ctx_init(int banks) { periph_state_ctx = kcalloc(2 * banks, sizeof(*periph_state_ctx), GFP_KERNEL); if (!periph_state_ctx) return -ENOMEM; return 0; } struct clk ** __init tegra_clk_init(void __iomem *regs, int num, int banks) { clk_base = regs; if (WARN_ON(banks > ARRAY_SIZE(periph_regs))) return NULL; periph_clk_enb_refcnt = kcalloc(32 * banks, sizeof(*periph_clk_enb_refcnt), GFP_KERNEL); if (!periph_clk_enb_refcnt) return NULL; periph_banks = banks; clks = kcalloc(num, sizeof(struct clk *), GFP_KERNEL); if (!clks) { kfree(periph_clk_enb_refcnt); return NULL; } clk_num = num; if (IS_ENABLED(CONFIG_PM_SLEEP)) { if (tegra_clk_periph_ctx_init(banks)) { kfree(periph_clk_enb_refcnt); kfree(clks); return NULL; } } return clks; } void __init tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list, struct clk *clks[], int clk_max) { struct clk *clk; for (; dup_list->clk_id < clk_max; dup_list++) { clk = clks[dup_list->clk_id]; dup_list->lookup.clk = clk; clkdev_add(&dup_list->lookup); } } void tegra_init_from_table(struct tegra_clk_init_table *tbl, struct clk *clks[], int clk_max) { struct clk *clk; for (; tbl->clk_id < clk_max; tbl++) { clk = clks[tbl->clk_id]; if (IS_ERR_OR_NULL(clk)) { pr_err("%s: invalid entry %ld in clks array for id %d\n", __func__, PTR_ERR(clk), tbl->clk_id); WARN_ON(1); continue; } if (tbl->parent_id < clk_max) { struct clk *parent = clks[tbl->parent_id]; if (clk_set_parent(clk, parent)) { pr_err("%s: Failed to set parent %s of %s\n", __func__, __clk_get_name(parent), __clk_get_name(clk)); WARN_ON(1); } } if (tbl->rate) if (clk_set_rate(clk, tbl->rate)) { pr_err("%s: Failed to set rate %lu of %s\n", __func__, tbl->rate, __clk_get_name(clk)); WARN_ON(1); } if (tbl->state) if (clk_prepare_enable(clk)) { pr_err("%s: Failed to enable %s\n", __func__, __clk_get_name(clk)); WARN_ON(1); } } } static const struct reset_control_ops rst_ops = { .assert = tegra_clk_rst_assert, .deassert = tegra_clk_rst_deassert, .reset = tegra_clk_rst_reset, }; static struct reset_controller_dev rst_ctlr = { .ops = &rst_ops, .owner = THIS_MODULE, .of_reset_n_cells = 1, }; void __init tegra_add_of_provider(struct device_node *np, void *clk_src_onecell_get) { int i; tegra_car_np = np; for (i = 0; i < clk_num; i++) { if (IS_ERR(clks[i])) { pr_err ("Tegra clk %d: register failed with %ld\n", i, PTR_ERR(clks[i])); } if (!clks[i]) clks[i] = ERR_PTR(-EINVAL); } clk_data.clks = clks; clk_data.clk_num = clk_num; of_clk_add_provider(np, clk_src_onecell_get, &clk_data); rst_ctlr.of_node = np; rst_ctlr.nr_resets = periph_banks * 32 + num_special_reset; reset_controller_register(&rst_ctlr); } void __init tegra_init_special_resets(unsigned int num, int (*assert)(unsigned long), int (*deassert)(unsigned long)) { num_special_reset = num; special_reset_assert = assert; special_reset_deassert = deassert; } void tegra_register_devclks(struct tegra_devclk *dev_clks, int num) { int i; for (i = 0; i < num; i++, dev_clks++) clk_register_clkdev(clks[dev_clks->dt_id], dev_clks->con_id, dev_clks->dev_id); for (i = 0; i < clk_num; i++) { if (!IS_ERR_OR_NULL(clks[i])) clk_register_clkdev(clks[i], __clk_get_name(clks[i]), "tegra-clk-debug"); } } struct clk ** __init tegra_lookup_dt_id(int clk_id, struct tegra_clk *tegra_clk) { if (tegra_clk[clk_id].present) return &clks[tegra_clk[clk_id].dt_id]; else return NULL; } static struct device_node *tegra_clk_get_of_node(struct clk_hw *hw) { struct device_node *np; char *node_name; node_name = kstrdup_and_replace(hw->init->name, '_', '-', GFP_KERNEL); if (!node_name) return NULL; for_each_child_of_node(tegra_car_np, np) { if (!strcmp(np->name, node_name)) break; } kfree(node_name); return np; } struct clk *tegra_clk_dev_register(struct clk_hw *hw) { struct platform_device *pdev, *parent; const char *dev_name = NULL; struct device *dev = NULL; struct device_node *np; np = tegra_clk_get_of_node(hw); if (!of_device_is_available(np)) goto put_node; dev_name = kasprintf(GFP_KERNEL, "tegra_clk_%s", hw->init->name); if (!dev_name) goto put_node; parent = of_find_device_by_node(tegra_car_np); if (parent) { pdev = of_platform_device_create(np, dev_name, &parent->dev); put_device(&parent->dev); if (!pdev) { pr_err("%s: failed to create device for %pOF\n", __func__, np); goto free_name; } dev = &pdev->dev; pm_runtime_enable(dev); } else { WARN(1, "failed to find device for %pOF\n", tegra_car_np); } free_name: kfree(dev_name); put_node: of_node_put(np); return clk_register(dev, hw); } tegra_clk_apply_init_table_func tegra_clk_apply_init_table; static int __init tegra_clocks_apply_init_table(void) { if (!tegra_clk_apply_init_table) return 0; tegra_clk_apply_init_table(); return 0; } arch_initcall(tegra_clocks_apply_init_table);
linux-master
drivers/clk/tegra/clk.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012-2014 NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/clk-provider.h> #include <linux/clkdev.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/clk/tegra.h> #include <dt-bindings/clock/tegra124-car.h> #include <dt-bindings/reset/tegra124-car.h> #include "clk.h" #include "clk-id.h" /* * TEGRA124_CAR_BANK_COUNT: the number of peripheral clock register * banks present in the Tegra124/132 CAR IP block. The banks are * identified by single letters, e.g.: L, H, U, V, W, X. See * periph_regs[] in drivers/clk/tegra/clk.c */ #define TEGRA124_CAR_BANK_COUNT 6 #define CLK_SOURCE_CSITE 0x1d4 #define CLK_SOURCE_EMC 0x19c #define CLK_SOURCE_SOR0 0x414 #define RST_DFLL_DVCO 0x2f4 #define DVFS_DFLL_RESET_SHIFT 0 #define PLLC_BASE 0x80 #define PLLC_OUT 0x84 #define PLLC_MISC2 0x88 #define PLLC_MISC 0x8c #define PLLC2_BASE 0x4e8 #define PLLC2_MISC 0x4ec #define PLLC3_BASE 0x4fc #define PLLC3_MISC 0x500 #define PLLM_BASE 0x90 #define PLLM_OUT 0x94 #define PLLM_MISC 0x9c #define PLLP_BASE 0xa0 #define PLLP_MISC 0xac #define PLLA_BASE 0xb0 #define PLLA_MISC 0xbc #define PLLD_BASE 0xd0 #define PLLD_MISC 0xdc #define PLLU_BASE 0xc0 #define PLLU_MISC 0xcc #define PLLX_BASE 0xe0 #define PLLX_MISC 0xe4 #define PLLX_MISC2 0x514 #define PLLX_MISC3 0x518 #define PLLE_BASE 0xe8 #define PLLE_MISC 0xec #define PLLD2_BASE 0x4b8 #define PLLD2_MISC 0x4bc #define PLLE_AUX 0x48c #define PLLRE_BASE 0x4c4 #define PLLRE_MISC 0x4c8 #define PLLDP_BASE 0x590 #define PLLDP_MISC 0x594 #define PLLC4_BASE 0x5a4 #define PLLC4_MISC 0x5a8 #define PLLC_IDDQ_BIT 26 #define PLLRE_IDDQ_BIT 16 #define PLLSS_IDDQ_BIT 19 #define PLL_BASE_LOCK BIT(27) #define PLLE_MISC_LOCK BIT(11) #define PLLRE_MISC_LOCK BIT(24) #define PLL_MISC_LOCK_ENABLE 18 #define PLLC_MISC_LOCK_ENABLE 24 #define PLLDU_MISC_LOCK_ENABLE 22 #define PLLE_MISC_LOCK_ENABLE 9 #define PLLRE_MISC_LOCK_ENABLE 30 #define PLLSS_MISC_LOCK_ENABLE 30 #define PLLXC_SW_MAX_P 6 #define PMC_PLLM_WB0_OVERRIDE 0x1dc #define PMC_PLLM_WB0_OVERRIDE_2 0x2b0 #define CCLKG_BURST_POLICY 0x368 /* Tegra CPU clock and reset control regs */ #define CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470 #define MASK(x) (BIT(x) - 1) #define MUX8_NOGATE_LOCK(_name, _parents, _offset, _clk_id, _lock) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset, \ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP,\ 0, TEGRA_PERIPH_NO_GATE, _clk_id,\ _parents##_idx, 0, _lock) #define NODIV(_name, _parents, _offset, \ _mux_shift, _mux_mask, _clk_num, \ _gate_flags, _clk_id, _lock) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ _mux_shift, _mux_mask, 0, 0, 0, 0, 0,\ _clk_num, (_gate_flags) | TEGRA_PERIPH_NO_DIV,\ _clk_id, _parents##_idx, 0, _lock) #ifdef CONFIG_PM_SLEEP static struct cpu_clk_suspend_context { u32 clk_csite_src; u32 cclkg_burst; u32 cclkg_divider; } tegra124_cpu_clk_sctx; #endif static void __iomem *clk_base; static void __iomem *pmc_base; static unsigned long osc_freq; static unsigned long pll_ref_freq; static DEFINE_SPINLOCK(pll_d_lock); static DEFINE_SPINLOCK(pll_e_lock); static DEFINE_SPINLOCK(pll_re_lock); static DEFINE_SPINLOCK(pll_u_lock); static DEFINE_SPINLOCK(emc_lock); static DEFINE_SPINLOCK(sor0_lock); /* possible OSC frequencies in Hz */ static unsigned long tegra124_input_freq[] = { [ 0] = 13000000, [ 1] = 16800000, [ 4] = 19200000, [ 5] = 38400000, [ 8] = 12000000, [ 9] = 48000000, [12] = 26000000, }; static struct div_nmp pllxc_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 20, .divp_width = 4, }; static const struct pdiv_map pllxc_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 3, .hw_val = 2 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 5, .hw_val = 4 }, { .pdiv = 6, .hw_val = 5 }, { .pdiv = 8, .hw_val = 6 }, { .pdiv = 10, .hw_val = 7 }, { .pdiv = 12, .hw_val = 8 }, { .pdiv = 16, .hw_val = 9 }, { .pdiv = 12, .hw_val = 10 }, { .pdiv = 16, .hw_val = 11 }, { .pdiv = 20, .hw_val = 12 }, { .pdiv = 24, .hw_val = 13 }, { .pdiv = 32, .hw_val = 14 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_x_freq_table[] = { /* 1 GHz */ { 12000000, 1000000000, 83, 1, 1, 0 }, /* actual: 996.0 MHz */ { 13000000, 1000000000, 76, 1, 1, 0 }, /* actual: 988.0 MHz */ { 16800000, 1000000000, 59, 1, 1, 0 }, /* actual: 991.2 MHz */ { 19200000, 1000000000, 52, 1, 1, 0 }, /* actual: 998.4 MHz */ { 26000000, 1000000000, 76, 2, 1, 0 }, /* actual: 988.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_x_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */ .vco_min = 700000000, .vco_max = 3000000000UL, .base_reg = PLLX_BASE, .misc_reg = PLLX_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLX_MISC3, .iddq_bit_idx = 3, .max_p = 6, .dyn_ramp_reg = PLLX_MISC2, .stepa_shift = 16, .stepb_shift = 24, .pdiv_tohw = pllxc_p, .div_nmp = &pllxc_nmp, .freq_table = pll_x_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_freq_table pll_c_freq_table[] = { { 12000000, 624000000, 104, 1, 2, 0 }, { 12000000, 600000000, 100, 1, 2, 0 }, { 13000000, 600000000, 92, 1, 2, 0 }, /* actual: 598.0 MHz */ { 16800000, 600000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */ { 19200000, 600000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */ { 26000000, 600000000, 92, 2, 2, 0 }, /* actual: 598.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_c_params = { .input_min = 12000000, .input_max = 800000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */ .vco_min = 600000000, .vco_max = 1400000000, .base_reg = PLLC_BASE, .misc_reg = PLLC_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLC_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLC_MISC, .iddq_bit_idx = PLLC_IDDQ_BIT, .max_p = PLLXC_SW_MAX_P, .dyn_ramp_reg = PLLC_MISC2, .stepa_shift = 17, .stepb_shift = 9, .pdiv_tohw = pllxc_p, .div_nmp = &pllxc_nmp, .freq_table = pll_c_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct div_nmp pllcx_nmp = { .divm_shift = 0, .divm_width = 2, .divn_shift = 8, .divn_width = 8, .divp_shift = 20, .divp_width = 3, }; static const struct pdiv_map pllc_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 3, .hw_val = 2 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 6, .hw_val = 4 }, { .pdiv = 8, .hw_val = 5 }, { .pdiv = 12, .hw_val = 6 }, { .pdiv = 16, .hw_val = 7 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_cx_freq_table[] = { { 12000000, 600000000, 100, 1, 2, 0 }, { 13000000, 600000000, 92, 1, 2, 0 }, /* actual: 598.0 MHz */ { 16800000, 600000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */ { 19200000, 600000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */ { 26000000, 600000000, 92, 2, 2, 0 }, /* actual: 598.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_c2_params = { .input_min = 12000000, .input_max = 48000000, .cf_min = 12000000, .cf_max = 19200000, .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLC2_BASE, .misc_reg = PLLC2_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .pdiv_tohw = pllc_p, .div_nmp = &pllcx_nmp, .max_p = 7, .ext_misc_reg[0] = 0x4f0, .ext_misc_reg[1] = 0x4f4, .ext_misc_reg[2] = 0x4f8, .freq_table = pll_cx_freq_table, .flags = TEGRA_PLL_USE_LOCK, }; static struct tegra_clk_pll_params pll_c3_params = { .input_min = 12000000, .input_max = 48000000, .cf_min = 12000000, .cf_max = 19200000, .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLC3_BASE, .misc_reg = PLLC3_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .pdiv_tohw = pllc_p, .div_nmp = &pllcx_nmp, .max_p = 7, .ext_misc_reg[0] = 0x504, .ext_misc_reg[1] = 0x508, .ext_misc_reg[2] = 0x50c, .freq_table = pll_cx_freq_table, .flags = TEGRA_PLL_USE_LOCK, }; static struct div_nmp pllss_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 20, .divp_width = 4, }; static const struct pdiv_map pll12g_ssd_esd_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 3, .hw_val = 2 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 5, .hw_val = 4 }, { .pdiv = 6, .hw_val = 5 }, { .pdiv = 8, .hw_val = 6 }, { .pdiv = 10, .hw_val = 7 }, { .pdiv = 12, .hw_val = 8 }, { .pdiv = 16, .hw_val = 9 }, { .pdiv = 12, .hw_val = 10 }, { .pdiv = 16, .hw_val = 11 }, { .pdiv = 20, .hw_val = 12 }, { .pdiv = 24, .hw_val = 13 }, { .pdiv = 32, .hw_val = 14 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_c4_freq_table[] = { { 12000000, 600000000, 100, 1, 2, 0 }, { 13000000, 600000000, 92, 1, 2, 0 }, /* actual: 598.0 MHz */ { 16800000, 600000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */ { 19200000, 600000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */ { 26000000, 600000000, 92, 2, 2, 0 }, /* actual: 598.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_c4_params = { .input_min = 12000000, .input_max = 1000000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 38 MHz */ .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLC4_BASE, .misc_reg = PLLC4_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLSS_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLC4_BASE, .iddq_bit_idx = PLLSS_IDDQ_BIT, .pdiv_tohw = pll12g_ssd_esd_p, .div_nmp = &pllss_nmp, .ext_misc_reg[0] = 0x5ac, .ext_misc_reg[1] = 0x5b0, .ext_misc_reg[2] = 0x5b4, .freq_table = pll_c4_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static const struct pdiv_map pllm_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 3, .hw_val = 2 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 5, .hw_val = 4 }, { .pdiv = 6, .hw_val = 5 }, { .pdiv = 8, .hw_val = 6 }, { .pdiv = 10, .hw_val = 7 }, { .pdiv = 12, .hw_val = 8 }, { .pdiv = 16, .hw_val = 9 }, { .pdiv = 12, .hw_val = 10 }, { .pdiv = 16, .hw_val = 11 }, { .pdiv = 20, .hw_val = 12 }, { .pdiv = 24, .hw_val = 13 }, { .pdiv = 32, .hw_val = 14 }, { .pdiv = 0, .hw_val = 0 }, }; static struct tegra_clk_pll_freq_table pll_m_freq_table[] = { { 12000000, 800000000, 66, 1, 1, 0 }, /* actual: 792.0 MHz */ { 13000000, 800000000, 61, 1, 1, 0 }, /* actual: 793.0 MHz */ { 16800000, 800000000, 47, 1, 1, 0 }, /* actual: 789.6 MHz */ { 19200000, 800000000, 41, 1, 1, 0 }, /* actual: 787.2 MHz */ { 26000000, 800000000, 61, 2, 1, 0 }, /* actual: 793.0 MHz */ { 0, 0, 0, 0, 0, 0}, }; static struct div_nmp pllm_nmp = { .divm_shift = 0, .divm_width = 8, .override_divm_shift = 0, .divn_shift = 8, .divn_width = 8, .override_divn_shift = 8, .divp_shift = 20, .divp_width = 1, .override_divp_shift = 27, }; static struct tegra_clk_pll_params pll_m_params = { .input_min = 12000000, .input_max = 500000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */ .vco_min = 400000000, .vco_max = 1066000000, .base_reg = PLLM_BASE, .misc_reg = PLLM_MISC, .lock_mask = PLL_BASE_LOCK, .lock_delay = 300, .max_p = 5, .pdiv_tohw = pllm_p, .div_nmp = &pllm_nmp, .pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE, .pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE_2, .freq_table = pll_m_freq_table, .flags = TEGRA_PLL_USE_LOCK, }; static struct tegra_clk_pll_freq_table pll_e_freq_table[] = { /* PLLE special case: use cpcon field to store cml divider value */ { 336000000, 100000000, 100, 21, 16, 11 }, { 312000000, 100000000, 200, 26, 24, 13 }, { 13000000, 100000000, 200, 1, 26, 13 }, { 12000000, 100000000, 200, 1, 24, 13 }, { 0, 0, 0, 0, 0, 0 }, }; static const struct pdiv_map plle_p[] = { { .pdiv = 1, .hw_val = 0 }, { .pdiv = 2, .hw_val = 1 }, { .pdiv = 3, .hw_val = 2 }, { .pdiv = 4, .hw_val = 3 }, { .pdiv = 5, .hw_val = 4 }, { .pdiv = 6, .hw_val = 5 }, { .pdiv = 8, .hw_val = 6 }, { .pdiv = 10, .hw_val = 7 }, { .pdiv = 12, .hw_val = 8 }, { .pdiv = 16, .hw_val = 9 }, { .pdiv = 12, .hw_val = 10 }, { .pdiv = 16, .hw_val = 11 }, { .pdiv = 20, .hw_val = 12 }, { .pdiv = 24, .hw_val = 13 }, { .pdiv = 32, .hw_val = 14 }, { .pdiv = 1, .hw_val = 0 }, }; static struct div_nmp plle_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 24, .divp_width = 4, }; static struct tegra_clk_pll_params pll_e_params = { .input_min = 12000000, .input_max = 1000000000, .cf_min = 12000000, .cf_max = 75000000, .vco_min = 1600000000, .vco_max = 2400000000U, .base_reg = PLLE_BASE, .misc_reg = PLLE_MISC, .aux_reg = PLLE_AUX, .lock_mask = PLLE_MISC_LOCK, .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE, .lock_delay = 300, .pdiv_tohw = plle_p, .div_nmp = &plle_nmp, .freq_table = pll_e_freq_table, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_HAS_LOCK_ENABLE, .fixed_rate = 100000000, }; static const struct clk_div_table pll_re_div_table[] = { { .val = 0, .div = 1 }, { .val = 1, .div = 2 }, { .val = 2, .div = 3 }, { .val = 3, .div = 4 }, { .val = 4, .div = 5 }, { .val = 5, .div = 6 }, { .val = 0, .div = 0 }, }; static struct div_nmp pllre_nmp = { .divm_shift = 0, .divm_width = 8, .divn_shift = 8, .divn_width = 8, .divp_shift = 16, .divp_width = 4, }; static struct tegra_clk_pll_params pll_re_vco_params = { .input_min = 12000000, .input_max = 1000000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 38 MHz */ .vco_min = 300000000, .vco_max = 600000000, .base_reg = PLLRE_BASE, .misc_reg = PLLRE_MISC, .lock_mask = PLLRE_MISC_LOCK, .lock_enable_bit_idx = PLLRE_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLRE_MISC, .iddq_bit_idx = PLLRE_IDDQ_BIT, .div_nmp = &pllre_nmp, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE | TEGRA_PLL_LOCK_MISC, }; static struct div_nmp pllp_nmp = { .divm_shift = 0, .divm_width = 5, .divn_shift = 8, .divn_width = 10, .divp_shift = 20, .divp_width = 3, }; static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { { 12000000, 408000000, 408, 12, 1, 8 }, { 13000000, 408000000, 408, 13, 1, 8 }, { 16800000, 408000000, 340, 14, 1, 8 }, { 19200000, 408000000, 340, 16, 1, 8 }, { 26000000, 408000000, 408, 26, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_p_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 200000000, .vco_max = 700000000, .base_reg = PLLP_BASE, .misc_reg = PLLP_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .div_nmp = &pllp_nmp, .freq_table = pll_p_freq_table, .fixed_rate = 408000000, .flags = TEGRA_PLL_FIXED | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_freq_table pll_a_freq_table[] = { { 9600000, 282240000, 147, 5, 1, 4 }, { 9600000, 368640000, 192, 5, 1, 4 }, { 9600000, 240000000, 200, 8, 1, 8 }, { 28800000, 282240000, 245, 25, 1, 8 }, { 28800000, 368640000, 320, 25, 1, 8 }, { 28800000, 240000000, 200, 24, 1, 8 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_a_params = { .input_min = 2000000, .input_max = 31000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 200000000, .vco_max = 700000000, .base_reg = PLLA_BASE, .misc_reg = PLLA_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, .lock_delay = 300, .div_nmp = &pllp_nmp, .freq_table = pll_a_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct div_nmp plld_nmp = { .divm_shift = 0, .divm_width = 5, .divn_shift = 8, .divn_width = 11, .divp_shift = 20, .divp_width = 3, }; static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { { 12000000, 216000000, 864, 12, 4, 12 }, { 13000000, 216000000, 864, 13, 4, 12 }, { 16800000, 216000000, 720, 14, 4, 12 }, { 19200000, 216000000, 720, 16, 4, 12 }, { 26000000, 216000000, 864, 26, 4, 12 }, { 12000000, 594000000, 594, 12, 1, 12 }, { 13000000, 594000000, 594, 13, 1, 12 }, { 16800000, 594000000, 495, 14, 1, 12 }, { 19200000, 594000000, 495, 16, 1, 12 }, { 26000000, 594000000, 594, 26, 1, 12 }, { 12000000, 1000000000, 1000, 12, 1, 12 }, { 13000000, 1000000000, 1000, 13, 1, 12 }, { 19200000, 1000000000, 625, 12, 1, 12 }, { 26000000, 1000000000, 1000, 26, 1, 12 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_d_params = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 500000000, .vco_max = 1000000000, .base_reg = PLLD_BASE, .misc_reg = PLLD_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .div_nmp = &plld_nmp, .freq_table = pll_d_freq_table, .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_freq_table tegra124_pll_d2_freq_table[] = { { 12000000, 594000000, 99, 1, 2, 0 }, { 13000000, 594000000, 91, 1, 2, 0 }, /* actual: 591.5 MHz */ { 16800000, 594000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */ { 19200000, 594000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */ { 26000000, 594000000, 91, 2, 2, 0 }, /* actual: 591.5 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params tegra124_pll_d2_params = { .input_min = 12000000, .input_max = 1000000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 38 MHz */ .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLD2_BASE, .misc_reg = PLLD2_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLSS_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLD2_BASE, .iddq_bit_idx = PLLSS_IDDQ_BIT, .pdiv_tohw = pll12g_ssd_esd_p, .div_nmp = &pllss_nmp, .ext_misc_reg[0] = 0x570, .ext_misc_reg[1] = 0x574, .ext_misc_reg[2] = 0x578, .max_p = 15, .freq_table = tegra124_pll_d2_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk_pll_freq_table pll_dp_freq_table[] = { { 12000000, 600000000, 100, 1, 2, 0 }, { 13000000, 600000000, 92, 1, 2, 0 }, /* actual: 598.0 MHz */ { 16800000, 600000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */ { 19200000, 600000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */ { 26000000, 600000000, 92, 2, 2, 0 }, /* actual: 598.0 MHz */ { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_dp_params = { .input_min = 12000000, .input_max = 1000000000, .cf_min = 12000000, .cf_max = 19200000, /* s/w policy, h/w capability 38 MHz */ .vco_min = 600000000, .vco_max = 1200000000, .base_reg = PLLDP_BASE, .misc_reg = PLLDP_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLSS_MISC_LOCK_ENABLE, .lock_delay = 300, .iddq_reg = PLLDP_BASE, .iddq_bit_idx = PLLSS_IDDQ_BIT, .pdiv_tohw = pll12g_ssd_esd_p, .div_nmp = &pllss_nmp, .ext_misc_reg[0] = 0x598, .ext_misc_reg[1] = 0x59c, .ext_misc_reg[2] = 0x5a0, .max_p = 5, .freq_table = pll_dp_freq_table, .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static const struct pdiv_map pllu_p[] = { { .pdiv = 1, .hw_val = 1 }, { .pdiv = 2, .hw_val = 0 }, { .pdiv = 0, .hw_val = 0 }, }; static struct div_nmp pllu_nmp = { .divm_shift = 0, .divm_width = 5, .divn_shift = 8, .divn_width = 10, .divp_shift = 20, .divp_width = 1, }; static struct tegra_clk_pll_freq_table pll_u_freq_table[] = { { 12000000, 480000000, 960, 12, 2, 12 }, { 13000000, 480000000, 960, 13, 2, 12 }, { 16800000, 480000000, 400, 7, 2, 5 }, { 19200000, 480000000, 200, 4, 2, 3 }, { 26000000, 480000000, 960, 26, 2, 12 }, { 0, 0, 0, 0, 0, 0 }, }; static struct tegra_clk_pll_params pll_u_params = { .input_min = 2000000, .input_max = 40000000, .cf_min = 1000000, .cf_max = 6000000, .vco_min = 480000000, .vco_max = 960000000, .base_reg = PLLU_BASE, .misc_reg = PLLU_MISC, .lock_mask = PLL_BASE_LOCK, .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, .lock_delay = 1000, .pdiv_tohw = pllu_p, .div_nmp = &pllu_nmp, .freq_table = pll_u_freq_table, .flags = TEGRA_PLLU | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, }; static struct tegra_clk tegra124_clks[tegra_clk_max] __initdata = { [tegra_clk_ispb] = { .dt_id = TEGRA124_CLK_ISPB, .present = true }, [tegra_clk_rtc] = { .dt_id = TEGRA124_CLK_RTC, .present = true }, [tegra_clk_timer] = { .dt_id = TEGRA124_CLK_TIMER, .present = true }, [tegra_clk_uarta] = { .dt_id = TEGRA124_CLK_UARTA, .present = true }, [tegra_clk_sdmmc2_8] = { .dt_id = TEGRA124_CLK_SDMMC2, .present = true }, [tegra_clk_i2s1] = { .dt_id = TEGRA124_CLK_I2S1, .present = true }, [tegra_clk_i2c1] = { .dt_id = TEGRA124_CLK_I2C1, .present = true }, [tegra_clk_sdmmc1_8] = { .dt_id = TEGRA124_CLK_SDMMC1, .present = true }, [tegra_clk_sdmmc4_8] = { .dt_id = TEGRA124_CLK_SDMMC4, .present = true }, [tegra_clk_pwm] = { .dt_id = TEGRA124_CLK_PWM, .present = true }, [tegra_clk_i2s2] = { .dt_id = TEGRA124_CLK_I2S2, .present = true }, [tegra_clk_usbd] = { .dt_id = TEGRA124_CLK_USBD, .present = true }, [tegra_clk_isp_8] = { .dt_id = TEGRA124_CLK_ISP, .present = true }, [tegra_clk_disp2] = { .dt_id = TEGRA124_CLK_DISP2, .present = true }, [tegra_clk_disp1] = { .dt_id = TEGRA124_CLK_DISP1, .present = true }, [tegra_clk_host1x_8] = { .dt_id = TEGRA124_CLK_HOST1X, .present = true }, [tegra_clk_vcp] = { .dt_id = TEGRA124_CLK_VCP, .present = true }, [tegra_clk_i2s0] = { .dt_id = TEGRA124_CLK_I2S0, .present = true }, [tegra_clk_apbdma] = { .dt_id = TEGRA124_CLK_APBDMA, .present = true }, [tegra_clk_kbc] = { .dt_id = TEGRA124_CLK_KBC, .present = true }, [tegra_clk_kfuse] = { .dt_id = TEGRA124_CLK_KFUSE, .present = true }, [tegra_clk_sbc1] = { .dt_id = TEGRA124_CLK_SBC1, .present = true }, [tegra_clk_nor] = { .dt_id = TEGRA124_CLK_NOR, .present = true }, [tegra_clk_sbc2] = { .dt_id = TEGRA124_CLK_SBC2, .present = true }, [tegra_clk_sbc3] = { .dt_id = TEGRA124_CLK_SBC3, .present = true }, [tegra_clk_i2c5] = { .dt_id = TEGRA124_CLK_I2C5, .present = true }, [tegra_clk_mipi] = { .dt_id = TEGRA124_CLK_MIPI, .present = true }, [tegra_clk_hdmi] = { .dt_id = TEGRA124_CLK_HDMI, .present = true }, [tegra_clk_csi] = { .dt_id = TEGRA124_CLK_CSI, .present = true }, [tegra_clk_i2c2] = { .dt_id = TEGRA124_CLK_I2C2, .present = true }, [tegra_clk_uartc] = { .dt_id = TEGRA124_CLK_UARTC, .present = true }, [tegra_clk_mipi_cal] = { .dt_id = TEGRA124_CLK_MIPI_CAL, .present = true }, [tegra_clk_usb2] = { .dt_id = TEGRA124_CLK_USB2, .present = true }, [tegra_clk_usb3] = { .dt_id = TEGRA124_CLK_USB3, .present = true }, [tegra_clk_vde_8] = { .dt_id = TEGRA124_CLK_VDE, .present = true }, [tegra_clk_bsea] = { .dt_id = TEGRA124_CLK_BSEA, .present = true }, [tegra_clk_bsev] = { .dt_id = TEGRA124_CLK_BSEV, .present = true }, [tegra_clk_uartd] = { .dt_id = TEGRA124_CLK_UARTD, .present = true }, [tegra_clk_i2c3] = { .dt_id = TEGRA124_CLK_I2C3, .present = true }, [tegra_clk_sbc4] = { .dt_id = TEGRA124_CLK_SBC4, .present = true }, [tegra_clk_sdmmc3_8] = { .dt_id = TEGRA124_CLK_SDMMC3, .present = true }, [tegra_clk_pcie] = { .dt_id = TEGRA124_CLK_PCIE, .present = true }, [tegra_clk_owr] = { .dt_id = TEGRA124_CLK_OWR, .present = true }, [tegra_clk_afi] = { .dt_id = TEGRA124_CLK_AFI, .present = true }, [tegra_clk_csite] = { .dt_id = TEGRA124_CLK_CSITE, .present = true }, [tegra_clk_la] = { .dt_id = TEGRA124_CLK_LA, .present = true }, [tegra_clk_trace] = { .dt_id = TEGRA124_CLK_TRACE, .present = true }, [tegra_clk_soc_therm] = { .dt_id = TEGRA124_CLK_SOC_THERM, .present = true }, [tegra_clk_dtv] = { .dt_id = TEGRA124_CLK_DTV, .present = true }, [tegra_clk_i2cslow] = { .dt_id = TEGRA124_CLK_I2CSLOW, .present = true }, [tegra_clk_tsec] = { .dt_id = TEGRA124_CLK_TSEC, .present = true }, [tegra_clk_xusb_host] = { .dt_id = TEGRA124_CLK_XUSB_HOST, .present = true }, [tegra_clk_msenc] = { .dt_id = TEGRA124_CLK_MSENC, .present = true }, [tegra_clk_csus] = { .dt_id = TEGRA124_CLK_CSUS, .present = true }, [tegra_clk_mselect] = { .dt_id = TEGRA124_CLK_MSELECT, .present = true }, [tegra_clk_tsensor] = { .dt_id = TEGRA124_CLK_TSENSOR, .present = true }, [tegra_clk_i2s3] = { .dt_id = TEGRA124_CLK_I2S3, .present = true }, [tegra_clk_i2s4] = { .dt_id = TEGRA124_CLK_I2S4, .present = true }, [tegra_clk_i2c4] = { .dt_id = TEGRA124_CLK_I2C4, .present = true }, [tegra_clk_sbc5] = { .dt_id = TEGRA124_CLK_SBC5, .present = true }, [tegra_clk_sbc6] = { .dt_id = TEGRA124_CLK_SBC6, .present = true }, [tegra_clk_d_audio] = { .dt_id = TEGRA124_CLK_D_AUDIO, .present = true }, [tegra_clk_apbif] = { .dt_id = TEGRA124_CLK_APBIF, .present = true }, [tegra_clk_dam0] = { .dt_id = TEGRA124_CLK_DAM0, .present = true }, [tegra_clk_dam1] = { .dt_id = TEGRA124_CLK_DAM1, .present = true }, [tegra_clk_dam2] = { .dt_id = TEGRA124_CLK_DAM2, .present = true }, [tegra_clk_hda2codec_2x] = { .dt_id = TEGRA124_CLK_HDA2CODEC_2X, .present = true }, [tegra_clk_audio0_2x] = { .dt_id = TEGRA124_CLK_AUDIO0_2X, .present = true }, [tegra_clk_audio1_2x] = { .dt_id = TEGRA124_CLK_AUDIO1_2X, .present = true }, [tegra_clk_audio2_2x] = { .dt_id = TEGRA124_CLK_AUDIO2_2X, .present = true }, [tegra_clk_audio3_2x] = { .dt_id = TEGRA124_CLK_AUDIO3_2X, .present = true }, [tegra_clk_audio4_2x] = { .dt_id = TEGRA124_CLK_AUDIO4_2X, .present = true }, [tegra_clk_spdif_2x] = { .dt_id = TEGRA124_CLK_SPDIF_2X, .present = true }, [tegra_clk_actmon] = { .dt_id = TEGRA124_CLK_ACTMON, .present = true }, [tegra_clk_extern1] = { .dt_id = TEGRA124_CLK_EXTERN1, .present = true }, [tegra_clk_extern2] = { .dt_id = TEGRA124_CLK_EXTERN2, .present = true }, [tegra_clk_extern3] = { .dt_id = TEGRA124_CLK_EXTERN3, .present = true }, [tegra_clk_sata_oob] = { .dt_id = TEGRA124_CLK_SATA_OOB, .present = true }, [tegra_clk_sata] = { .dt_id = TEGRA124_CLK_SATA, .present = true }, [tegra_clk_hda] = { .dt_id = TEGRA124_CLK_HDA, .present = true }, [tegra_clk_se] = { .dt_id = TEGRA124_CLK_SE, .present = true }, [tegra_clk_hda2hdmi] = { .dt_id = TEGRA124_CLK_HDA2HDMI, .present = true }, [tegra_clk_sata_cold] = { .dt_id = TEGRA124_CLK_SATA_COLD, .present = true }, [tegra_clk_cilab] = { .dt_id = TEGRA124_CLK_CILAB, .present = true }, [tegra_clk_cilcd] = { .dt_id = TEGRA124_CLK_CILCD, .present = true }, [tegra_clk_cile] = { .dt_id = TEGRA124_CLK_CILE, .present = true }, [tegra_clk_dsialp] = { .dt_id = TEGRA124_CLK_DSIALP, .present = true }, [tegra_clk_dsiblp] = { .dt_id = TEGRA124_CLK_DSIBLP, .present = true }, [tegra_clk_entropy] = { .dt_id = TEGRA124_CLK_ENTROPY, .present = true }, [tegra_clk_dds] = { .dt_id = TEGRA124_CLK_DDS, .present = true }, [tegra_clk_dp2] = { .dt_id = TEGRA124_CLK_DP2, .present = true }, [tegra_clk_amx] = { .dt_id = TEGRA124_CLK_AMX, .present = true }, [tegra_clk_adx] = { .dt_id = TEGRA124_CLK_ADX, .present = true }, [tegra_clk_xusb_ss] = { .dt_id = TEGRA124_CLK_XUSB_SS, .present = true }, [tegra_clk_i2c6] = { .dt_id = TEGRA124_CLK_I2C6, .present = true }, [tegra_clk_vim2_clk] = { .dt_id = TEGRA124_CLK_VIM2_CLK, .present = true }, [tegra_clk_hdmi_audio] = { .dt_id = TEGRA124_CLK_HDMI_AUDIO, .present = true }, [tegra_clk_clk72Mhz] = { .dt_id = TEGRA124_CLK_CLK72MHZ, .present = true }, [tegra_clk_vic03] = { .dt_id = TEGRA124_CLK_VIC03, .present = true }, [tegra_clk_adx1] = { .dt_id = TEGRA124_CLK_ADX1, .present = true }, [tegra_clk_dpaux] = { .dt_id = TEGRA124_CLK_DPAUX, .present = true }, [tegra_clk_sor0] = { .dt_id = TEGRA124_CLK_SOR0, .present = true }, [tegra_clk_sor0_out] = { .dt_id = TEGRA124_CLK_SOR0_OUT, .present = true }, [tegra_clk_gpu] = { .dt_id = TEGRA124_CLK_GPU, .present = true }, [tegra_clk_amx1] = { .dt_id = TEGRA124_CLK_AMX1, .present = true }, [tegra_clk_uartb] = { .dt_id = TEGRA124_CLK_UARTB, .present = true }, [tegra_clk_vfir] = { .dt_id = TEGRA124_CLK_VFIR, .present = true }, [tegra_clk_spdif_in] = { .dt_id = TEGRA124_CLK_SPDIF_IN, .present = true }, [tegra_clk_spdif_out] = { .dt_id = TEGRA124_CLK_SPDIF_OUT, .present = true }, [tegra_clk_vi_9] = { .dt_id = TEGRA124_CLK_VI, .present = true }, [tegra_clk_vi_sensor_8] = { .dt_id = TEGRA124_CLK_VI_SENSOR, .present = true }, [tegra_clk_fuse] = { .dt_id = TEGRA124_CLK_FUSE, .present = true }, [tegra_clk_fuse_burn] = { .dt_id = TEGRA124_CLK_FUSE_BURN, .present = true }, [tegra_clk_clk_32k] = { .dt_id = TEGRA124_CLK_CLK_32K, .present = true }, [tegra_clk_clk_m] = { .dt_id = TEGRA124_CLK_CLK_M, .present = true }, [tegra_clk_osc] = { .dt_id = TEGRA124_CLK_OSC, .present = true }, [tegra_clk_osc_div2] = { .dt_id = TEGRA124_CLK_OSC_DIV2, .present = true }, [tegra_clk_osc_div4] = { .dt_id = TEGRA124_CLK_OSC_DIV4, .present = true }, [tegra_clk_pll_ref] = { .dt_id = TEGRA124_CLK_PLL_REF, .present = true }, [tegra_clk_pll_c] = { .dt_id = TEGRA124_CLK_PLL_C, .present = true }, [tegra_clk_pll_c_out1] = { .dt_id = TEGRA124_CLK_PLL_C_OUT1, .present = true }, [tegra_clk_pll_c2] = { .dt_id = TEGRA124_CLK_PLL_C2, .present = true }, [tegra_clk_pll_c3] = { .dt_id = TEGRA124_CLK_PLL_C3, .present = true }, [tegra_clk_pll_m] = { .dt_id = TEGRA124_CLK_PLL_M, .present = true }, [tegra_clk_pll_m_out1] = { .dt_id = TEGRA124_CLK_PLL_M_OUT1, .present = true }, [tegra_clk_pll_p] = { .dt_id = TEGRA124_CLK_PLL_P, .present = true }, [tegra_clk_pll_p_out1] = { .dt_id = TEGRA124_CLK_PLL_P_OUT1, .present = true }, [tegra_clk_pll_p_out2] = { .dt_id = TEGRA124_CLK_PLL_P_OUT2, .present = true }, [tegra_clk_pll_p_out3] = { .dt_id = TEGRA124_CLK_PLL_P_OUT3, .present = true }, [tegra_clk_pll_p_out4] = { .dt_id = TEGRA124_CLK_PLL_P_OUT4, .present = true }, [tegra_clk_pll_a] = { .dt_id = TEGRA124_CLK_PLL_A, .present = true }, [tegra_clk_pll_a_out0] = { .dt_id = TEGRA124_CLK_PLL_A_OUT0, .present = true }, [tegra_clk_pll_d] = { .dt_id = TEGRA124_CLK_PLL_D, .present = true }, [tegra_clk_pll_d_out0] = { .dt_id = TEGRA124_CLK_PLL_D_OUT0, .present = true }, [tegra_clk_pll_d2] = { .dt_id = TEGRA124_CLK_PLL_D2, .present = true }, [tegra_clk_pll_d2_out0] = { .dt_id = TEGRA124_CLK_PLL_D2_OUT0, .present = true }, [tegra_clk_pll_u] = { .dt_id = TEGRA124_CLK_PLL_U, .present = true }, [tegra_clk_pll_u_480m] = { .dt_id = TEGRA124_CLK_PLL_U_480M, .present = true }, [tegra_clk_pll_u_60m] = { .dt_id = TEGRA124_CLK_PLL_U_60M, .present = true }, [tegra_clk_pll_u_48m] = { .dt_id = TEGRA124_CLK_PLL_U_48M, .present = true }, [tegra_clk_pll_u_12m] = { .dt_id = TEGRA124_CLK_PLL_U_12M, .present = true }, [tegra_clk_pll_x] = { .dt_id = TEGRA124_CLK_PLL_X, .present = true }, [tegra_clk_pll_x_out0] = { .dt_id = TEGRA124_CLK_PLL_X_OUT0, .present = true }, [tegra_clk_pll_re_vco] = { .dt_id = TEGRA124_CLK_PLL_RE_VCO, .present = true }, [tegra_clk_pll_re_out] = { .dt_id = TEGRA124_CLK_PLL_RE_OUT, .present = true }, [tegra_clk_spdif_in_sync] = { .dt_id = TEGRA124_CLK_SPDIF_IN_SYNC, .present = true }, [tegra_clk_i2s0_sync] = { .dt_id = TEGRA124_CLK_I2S0_SYNC, .present = true }, [tegra_clk_i2s1_sync] = { .dt_id = TEGRA124_CLK_I2S1_SYNC, .present = true }, [tegra_clk_i2s2_sync] = { .dt_id = TEGRA124_CLK_I2S2_SYNC, .present = true }, [tegra_clk_i2s3_sync] = { .dt_id = TEGRA124_CLK_I2S3_SYNC, .present = true }, [tegra_clk_i2s4_sync] = { .dt_id = TEGRA124_CLK_I2S4_SYNC, .present = true }, [tegra_clk_vimclk_sync] = { .dt_id = TEGRA124_CLK_VIMCLK_SYNC, .present = true }, [tegra_clk_audio0] = { .dt_id = TEGRA124_CLK_AUDIO0, .present = true }, [tegra_clk_audio1] = { .dt_id = TEGRA124_CLK_AUDIO1, .present = true }, [tegra_clk_audio2] = { .dt_id = TEGRA124_CLK_AUDIO2, .present = true }, [tegra_clk_audio3] = { .dt_id = TEGRA124_CLK_AUDIO3, .present = true }, [tegra_clk_audio4] = { .dt_id = TEGRA124_CLK_AUDIO4, .present = true }, [tegra_clk_spdif] = { .dt_id = TEGRA124_CLK_SPDIF, .present = true }, [tegra_clk_xusb_host_src] = { .dt_id = TEGRA124_CLK_XUSB_HOST_SRC, .present = true }, [tegra_clk_xusb_falcon_src] = { .dt_id = TEGRA124_CLK_XUSB_FALCON_SRC, .present = true }, [tegra_clk_xusb_fs_src] = { .dt_id = TEGRA124_CLK_XUSB_FS_SRC, .present = true }, [tegra_clk_xusb_ss_src] = { .dt_id = TEGRA124_CLK_XUSB_SS_SRC, .present = true }, [tegra_clk_xusb_ss_div2] = { .dt_id = TEGRA124_CLK_XUSB_SS_DIV2, .present = true }, [tegra_clk_xusb_dev_src] = { .dt_id = TEGRA124_CLK_XUSB_DEV_SRC, .present = true }, [tegra_clk_xusb_dev] = { .dt_id = TEGRA124_CLK_XUSB_DEV, .present = true }, [tegra_clk_xusb_hs_src] = { .dt_id = TEGRA124_CLK_XUSB_HS_SRC, .present = true }, [tegra_clk_sclk] = { .dt_id = TEGRA124_CLK_SCLK, .present = true }, [tegra_clk_hclk] = { .dt_id = TEGRA124_CLK_HCLK, .present = true }, [tegra_clk_pclk] = { .dt_id = TEGRA124_CLK_PCLK, .present = true }, [tegra_clk_cclk_g] = { .dt_id = TEGRA124_CLK_CCLK_G, .present = true }, [tegra_clk_cclk_lp] = { .dt_id = TEGRA124_CLK_CCLK_LP, .present = true }, [tegra_clk_dfll_ref] = { .dt_id = TEGRA124_CLK_DFLL_REF, .present = true }, [tegra_clk_dfll_soc] = { .dt_id = TEGRA124_CLK_DFLL_SOC, .present = true }, [tegra_clk_vi_sensor2] = { .dt_id = TEGRA124_CLK_VI_SENSOR2, .present = true }, [tegra_clk_pll_p_out5] = { .dt_id = TEGRA124_CLK_PLL_P_OUT5, .present = true }, [tegra_clk_pll_c4] = { .dt_id = TEGRA124_CLK_PLL_C4, .present = true }, [tegra_clk_pll_dp] = { .dt_id = TEGRA124_CLK_PLL_DP, .present = true }, [tegra_clk_audio0_mux] = { .dt_id = TEGRA124_CLK_AUDIO0_MUX, .present = true }, [tegra_clk_audio1_mux] = { .dt_id = TEGRA124_CLK_AUDIO1_MUX, .present = true }, [tegra_clk_audio2_mux] = { .dt_id = TEGRA124_CLK_AUDIO2_MUX, .present = true }, [tegra_clk_audio3_mux] = { .dt_id = TEGRA124_CLK_AUDIO3_MUX, .present = true }, [tegra_clk_audio4_mux] = { .dt_id = TEGRA124_CLK_AUDIO4_MUX, .present = true }, [tegra_clk_spdif_mux] = { .dt_id = TEGRA124_CLK_SPDIF_MUX, .present = true }, [tegra_clk_cec] = { .dt_id = TEGRA124_CLK_CEC, .present = true }, }; static struct tegra_devclk devclks[] __initdata = { { .con_id = "clk_m", .dt_id = TEGRA124_CLK_CLK_M }, { .con_id = "pll_ref", .dt_id = TEGRA124_CLK_PLL_REF }, { .con_id = "clk_32k", .dt_id = TEGRA124_CLK_CLK_32K }, { .con_id = "osc", .dt_id = TEGRA124_CLK_OSC }, { .con_id = "osc_div2", .dt_id = TEGRA124_CLK_OSC_DIV2 }, { .con_id = "osc_div4", .dt_id = TEGRA124_CLK_OSC_DIV4 }, { .con_id = "pll_c", .dt_id = TEGRA124_CLK_PLL_C }, { .con_id = "pll_c_out1", .dt_id = TEGRA124_CLK_PLL_C_OUT1 }, { .con_id = "pll_c2", .dt_id = TEGRA124_CLK_PLL_C2 }, { .con_id = "pll_c3", .dt_id = TEGRA124_CLK_PLL_C3 }, { .con_id = "pll_p", .dt_id = TEGRA124_CLK_PLL_P }, { .con_id = "pll_p_out1", .dt_id = TEGRA124_CLK_PLL_P_OUT1 }, { .con_id = "pll_p_out2", .dt_id = TEGRA124_CLK_PLL_P_OUT2 }, { .con_id = "pll_p_out3", .dt_id = TEGRA124_CLK_PLL_P_OUT3 }, { .con_id = "pll_p_out4", .dt_id = TEGRA124_CLK_PLL_P_OUT4 }, { .con_id = "pll_m", .dt_id = TEGRA124_CLK_PLL_M }, { .con_id = "pll_m_out1", .dt_id = TEGRA124_CLK_PLL_M_OUT1 }, { .con_id = "pll_x", .dt_id = TEGRA124_CLK_PLL_X }, { .con_id = "pll_x_out0", .dt_id = TEGRA124_CLK_PLL_X_OUT0 }, { .con_id = "pll_u", .dt_id = TEGRA124_CLK_PLL_U }, { .con_id = "pll_u_480M", .dt_id = TEGRA124_CLK_PLL_U_480M }, { .con_id = "pll_u_60M", .dt_id = TEGRA124_CLK_PLL_U_60M }, { .con_id = "pll_u_48M", .dt_id = TEGRA124_CLK_PLL_U_48M }, { .con_id = "pll_u_12M", .dt_id = TEGRA124_CLK_PLL_U_12M }, { .con_id = "pll_d", .dt_id = TEGRA124_CLK_PLL_D }, { .con_id = "pll_d_out0", .dt_id = TEGRA124_CLK_PLL_D_OUT0 }, { .con_id = "pll_d2", .dt_id = TEGRA124_CLK_PLL_D2 }, { .con_id = "pll_d2_out0", .dt_id = TEGRA124_CLK_PLL_D2_OUT0 }, { .con_id = "pll_a", .dt_id = TEGRA124_CLK_PLL_A }, { .con_id = "pll_a_out0", .dt_id = TEGRA124_CLK_PLL_A_OUT0 }, { .con_id = "pll_re_vco", .dt_id = TEGRA124_CLK_PLL_RE_VCO }, { .con_id = "pll_re_out", .dt_id = TEGRA124_CLK_PLL_RE_OUT }, { .con_id = "spdif_in_sync", .dt_id = TEGRA124_CLK_SPDIF_IN_SYNC }, { .con_id = "i2s0_sync", .dt_id = TEGRA124_CLK_I2S0_SYNC }, { .con_id = "i2s1_sync", .dt_id = TEGRA124_CLK_I2S1_SYNC }, { .con_id = "i2s2_sync", .dt_id = TEGRA124_CLK_I2S2_SYNC }, { .con_id = "i2s3_sync", .dt_id = TEGRA124_CLK_I2S3_SYNC }, { .con_id = "i2s4_sync", .dt_id = TEGRA124_CLK_I2S4_SYNC }, { .con_id = "vimclk_sync", .dt_id = TEGRA124_CLK_VIMCLK_SYNC }, { .con_id = "audio0", .dt_id = TEGRA124_CLK_AUDIO0 }, { .con_id = "audio1", .dt_id = TEGRA124_CLK_AUDIO1 }, { .con_id = "audio2", .dt_id = TEGRA124_CLK_AUDIO2 }, { .con_id = "audio3", .dt_id = TEGRA124_CLK_AUDIO3 }, { .con_id = "audio4", .dt_id = TEGRA124_CLK_AUDIO4 }, { .con_id = "spdif", .dt_id = TEGRA124_CLK_SPDIF }, { .con_id = "audio0_2x", .dt_id = TEGRA124_CLK_AUDIO0_2X }, { .con_id = "audio1_2x", .dt_id = TEGRA124_CLK_AUDIO1_2X }, { .con_id = "audio2_2x", .dt_id = TEGRA124_CLK_AUDIO2_2X }, { .con_id = "audio3_2x", .dt_id = TEGRA124_CLK_AUDIO3_2X }, { .con_id = "audio4_2x", .dt_id = TEGRA124_CLK_AUDIO4_2X }, { .con_id = "spdif_2x", .dt_id = TEGRA124_CLK_SPDIF_2X }, { .con_id = "extern1", .dt_id = TEGRA124_CLK_EXTERN1 }, { .con_id = "extern2", .dt_id = TEGRA124_CLK_EXTERN2 }, { .con_id = "extern3", .dt_id = TEGRA124_CLK_EXTERN3 }, { .con_id = "cclk_g", .dt_id = TEGRA124_CLK_CCLK_G }, { .con_id = "cclk_lp", .dt_id = TEGRA124_CLK_CCLK_LP }, { .con_id = "sclk", .dt_id = TEGRA124_CLK_SCLK }, { .con_id = "hclk", .dt_id = TEGRA124_CLK_HCLK }, { .con_id = "pclk", .dt_id = TEGRA124_CLK_PCLK }, { .con_id = "fuse", .dt_id = TEGRA124_CLK_FUSE }, { .dev_id = "rtc-tegra", .dt_id = TEGRA124_CLK_RTC }, { .dev_id = "timer", .dt_id = TEGRA124_CLK_TIMER }, { .con_id = "hda", .dt_id = TEGRA124_CLK_HDA }, { .con_id = "hda2codec_2x", .dt_id = TEGRA124_CLK_HDA2CODEC_2X }, { .con_id = "hda2hdmi", .dt_id = TEGRA124_CLK_HDA2HDMI }, }; static const char * const sor0_parents[] = { "pll_p_out0", "pll_m_out0", "pll_d_out0", "pll_a_out0", "pll_c_out0", "pll_d2_out0", "clk_m", }; static const char * const sor0_out_parents[] = { "clk_m", "sor0_pad_clkout", }; static struct tegra_periph_init_data tegra124_periph[] = { TEGRA_INIT_DATA_TABLE("sor0", NULL, NULL, sor0_parents, CLK_SOURCE_SOR0, 29, 0x7, 0, 0, 0, 0, 0, 182, 0, tegra_clk_sor0, NULL, 0, &sor0_lock), TEGRA_INIT_DATA_TABLE("sor0_out", NULL, NULL, sor0_out_parents, CLK_SOURCE_SOR0, 14, 0x1, 0, 0, 0, 0, 0, 0, TEGRA_PERIPH_NO_GATE, tegra_clk_sor0_out, NULL, 0, &sor0_lock), }; static struct clk **clks; static __init void tegra124_periph_clk_init(void __iomem *clk_base, void __iomem *pmc_base) { struct clk *clk; unsigned int i; /* xusb_ss_div2 */ clk = clk_register_fixed_factor(NULL, "xusb_ss_div2", "xusb_ss_src", 0, 1, 2); clks[TEGRA124_CLK_XUSB_SS_DIV2] = clk; clk = tegra_clk_register_periph_fixed("dpaux", "pll_p", 0, clk_base, 1, 17, 181); clks[TEGRA124_CLK_DPAUX] = clk; clk = clk_register_gate(NULL, "pll_d_dsi_out", "pll_d_out0", 0, clk_base + PLLD_MISC, 30, 0, &pll_d_lock); clks[TEGRA124_CLK_PLL_D_DSI_OUT] = clk; clk = tegra_clk_register_periph_gate("dsia", "pll_d_dsi_out", 0, clk_base, 0, 48, periph_clk_enb_refcnt); clks[TEGRA124_CLK_DSIA] = clk; clk = tegra_clk_register_periph_gate("dsib", "pll_d_dsi_out", 0, clk_base, 0, 82, periph_clk_enb_refcnt); clks[TEGRA124_CLK_DSIB] = clk; clk = tegra_clk_register_mc("mc", "emc", clk_base + CLK_SOURCE_EMC, &emc_lock); clks[TEGRA124_CLK_MC] = clk; /* cml0 */ clk = clk_register_gate(NULL, "cml0", "pll_e", 0, clk_base + PLLE_AUX, 0, 0, &pll_e_lock); clk_register_clkdev(clk, "cml0", NULL); clks[TEGRA124_CLK_CML0] = clk; /* cml1 */ clk = clk_register_gate(NULL, "cml1", "pll_e", 0, clk_base + PLLE_AUX, 1, 0, &pll_e_lock); clk_register_clkdev(clk, "cml1", NULL); clks[TEGRA124_CLK_CML1] = clk; for (i = 0; i < ARRAY_SIZE(tegra124_periph); i++) { struct tegra_periph_init_data *init = &tegra124_periph[i]; struct clk **clkp; clkp = tegra_lookup_dt_id(init->clk_id, tegra124_clks); if (!clkp) { pr_warn("clock %u not found\n", init->clk_id); continue; } clk = tegra_clk_register_periph_data(clk_base, init); *clkp = clk; } tegra_periph_clk_init(clk_base, pmc_base, tegra124_clks, &pll_p_params); } static void __init tegra124_pll_init(void __iomem *clk_base, void __iomem *pmc) { struct clk *clk; /* PLLC */ clk = tegra_clk_register_pllxc("pll_c", "pll_ref", clk_base, pmc, 0, &pll_c_params, NULL); clk_register_clkdev(clk, "pll_c", NULL); clks[TEGRA124_CLK_PLL_C] = clk; /* PLLC_OUT1 */ clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c", clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div", clk_base + PLLC_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clk_register_clkdev(clk, "pll_c_out1", NULL); clks[TEGRA124_CLK_PLL_C_OUT1] = clk; /* PLLC_UD */ clk = clk_register_fixed_factor(NULL, "pll_c_ud", "pll_c", CLK_SET_RATE_PARENT, 1, 1); clk_register_clkdev(clk, "pll_c_ud", NULL); clks[TEGRA124_CLK_PLL_C_UD] = clk; /* PLLC2 */ clk = tegra_clk_register_pllc("pll_c2", "pll_ref", clk_base, pmc, 0, &pll_c2_params, NULL); clk_register_clkdev(clk, "pll_c2", NULL); clks[TEGRA124_CLK_PLL_C2] = clk; /* PLLC3 */ clk = tegra_clk_register_pllc("pll_c3", "pll_ref", clk_base, pmc, 0, &pll_c3_params, NULL); clk_register_clkdev(clk, "pll_c3", NULL); clks[TEGRA124_CLK_PLL_C3] = clk; /* PLLM */ clk = tegra_clk_register_pllm("pll_m", "pll_ref", clk_base, pmc, CLK_SET_RATE_GATE, &pll_m_params, NULL); clk_register_clkdev(clk, "pll_m", NULL); clks[TEGRA124_CLK_PLL_M] = clk; /* PLLM_OUT1 */ clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m", clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div", clk_base + PLLM_OUT, 1, 0, CLK_SET_RATE_PARENT, 0, NULL); clk_register_clkdev(clk, "pll_m_out1", NULL); clks[TEGRA124_CLK_PLL_M_OUT1] = clk; /* PLLM_UD */ clk = clk_register_fixed_factor(NULL, "pll_m_ud", "pll_m", CLK_SET_RATE_PARENT, 1, 1); clk_register_clkdev(clk, "pll_m_ud", NULL); clks[TEGRA124_CLK_PLL_M_UD] = clk; /* PLLU */ clk = tegra_clk_register_pllu_tegra114("pll_u", "pll_ref", clk_base, 0, &pll_u_params, &pll_u_lock); clk_register_clkdev(clk, "pll_u", NULL); clks[TEGRA124_CLK_PLL_U] = clk; /* PLLU_480M */ clk = clk_register_gate(NULL, "pll_u_480M", "pll_u", CLK_SET_RATE_PARENT, clk_base + PLLU_BASE, 22, 0, &pll_u_lock); clk_register_clkdev(clk, "pll_u_480M", NULL); clks[TEGRA124_CLK_PLL_U_480M] = clk; /* PLLU_60M */ clk = clk_register_fixed_factor(NULL, "pll_u_60M", "pll_u", CLK_SET_RATE_PARENT, 1, 8); clk_register_clkdev(clk, "pll_u_60M", NULL); clks[TEGRA124_CLK_PLL_U_60M] = clk; /* PLLU_48M */ clk = clk_register_fixed_factor(NULL, "pll_u_48M", "pll_u", CLK_SET_RATE_PARENT, 1, 10); clk_register_clkdev(clk, "pll_u_48M", NULL); clks[TEGRA124_CLK_PLL_U_48M] = clk; /* PLLU_12M */ clk = clk_register_fixed_factor(NULL, "pll_u_12M", "pll_u", CLK_SET_RATE_PARENT, 1, 40); clk_register_clkdev(clk, "pll_u_12M", NULL); clks[TEGRA124_CLK_PLL_U_12M] = clk; /* PLLD */ clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc, 0, &pll_d_params, &pll_d_lock); clk_register_clkdev(clk, "pll_d", NULL); clks[TEGRA124_CLK_PLL_D] = clk; /* PLLD_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d", CLK_SET_RATE_PARENT, 1, 2); clk_register_clkdev(clk, "pll_d_out0", NULL); clks[TEGRA124_CLK_PLL_D_OUT0] = clk; /* PLLRE */ clk = tegra_clk_register_pllre("pll_re_vco", "pll_ref", clk_base, pmc, 0, &pll_re_vco_params, &pll_re_lock, pll_ref_freq); clk_register_clkdev(clk, "pll_re_vco", NULL); clks[TEGRA124_CLK_PLL_RE_VCO] = clk; clk = clk_register_divider_table(NULL, "pll_re_out", "pll_re_vco", 0, clk_base + PLLRE_BASE, 16, 4, 0, pll_re_div_table, &pll_re_lock); clk_register_clkdev(clk, "pll_re_out", NULL); clks[TEGRA124_CLK_PLL_RE_OUT] = clk; /* PLLE */ clk = tegra_clk_register_plle_tegra114("pll_e", "pll_ref", clk_base, 0, &pll_e_params, NULL); clk_register_clkdev(clk, "pll_e", NULL); clks[TEGRA124_CLK_PLL_E] = clk; /* PLLC4 */ clk = tegra_clk_register_pllss("pll_c4", "pll_ref", clk_base, 0, &pll_c4_params, NULL); clk_register_clkdev(clk, "pll_c4", NULL); clks[TEGRA124_CLK_PLL_C4] = clk; /* PLLDP */ clk = tegra_clk_register_pllss("pll_dp", "pll_ref", clk_base, 0, &pll_dp_params, NULL); clk_register_clkdev(clk, "pll_dp", NULL); clks[TEGRA124_CLK_PLL_DP] = clk; /* PLLD2 */ clk = tegra_clk_register_pllss("pll_d2", "pll_ref", clk_base, 0, &tegra124_pll_d2_params, NULL); clk_register_clkdev(clk, "pll_d2", NULL); clks[TEGRA124_CLK_PLL_D2] = clk; /* PLLD2_OUT0 */ clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2", CLK_SET_RATE_PARENT, 1, 1); clk_register_clkdev(clk, "pll_d2_out0", NULL); clks[TEGRA124_CLK_PLL_D2_OUT0] = clk; } /* Tegra124 CPU clock and reset control functions */ static void tegra124_wait_cpu_in_reset(u32 cpu) { unsigned int reg; do { reg = readl(clk_base + CLK_RST_CONTROLLER_CPU_CMPLX_STATUS); cpu_relax(); } while (!(reg & (1 << cpu))); /* check CPU been reset or not */ } static void tegra124_disable_cpu_clock(u32 cpu) { /* flow controller would take care in the power sequence. */ } #ifdef CONFIG_PM_SLEEP static void tegra124_cpu_clock_suspend(void) { /* switch coresite to clk_m, save off original source */ tegra124_cpu_clk_sctx.clk_csite_src = readl(clk_base + CLK_SOURCE_CSITE); writel(3 << 30, clk_base + CLK_SOURCE_CSITE); tegra124_cpu_clk_sctx.cclkg_burst = readl(clk_base + CCLKG_BURST_POLICY); tegra124_cpu_clk_sctx.cclkg_divider = readl(clk_base + CCLKG_BURST_POLICY + 4); } static void tegra124_cpu_clock_resume(void) { writel(tegra124_cpu_clk_sctx.clk_csite_src, clk_base + CLK_SOURCE_CSITE); writel(tegra124_cpu_clk_sctx.cclkg_burst, clk_base + CCLKG_BURST_POLICY); writel(tegra124_cpu_clk_sctx.cclkg_divider, clk_base + CCLKG_BURST_POLICY + 4); } #endif static struct tegra_cpu_car_ops tegra124_cpu_car_ops = { .wait_for_reset = tegra124_wait_cpu_in_reset, .disable_clock = tegra124_disable_cpu_clock, #ifdef CONFIG_PM_SLEEP .suspend = tegra124_cpu_clock_suspend, .resume = tegra124_cpu_clock_resume, #endif }; static const struct of_device_id pmc_match[] __initconst = { { .compatible = "nvidia,tegra124-pmc" }, { }, }; static struct tegra_clk_init_table common_init_table[] __initdata = { { TEGRA124_CLK_UARTA, TEGRA124_CLK_PLL_P, 408000000, 0 }, { TEGRA124_CLK_UARTB, TEGRA124_CLK_PLL_P, 408000000, 0 }, { TEGRA124_CLK_UARTC, TEGRA124_CLK_PLL_P, 408000000, 0 }, { TEGRA124_CLK_UARTD, TEGRA124_CLK_PLL_P, 408000000, 0 }, { TEGRA124_CLK_PLL_A, TEGRA124_CLK_CLK_MAX, 282240000, 0 }, { TEGRA124_CLK_PLL_A_OUT0, TEGRA124_CLK_CLK_MAX, 11289600, 0 }, { TEGRA124_CLK_I2S0, TEGRA124_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA124_CLK_I2S1, TEGRA124_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA124_CLK_I2S2, TEGRA124_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA124_CLK_I2S3, TEGRA124_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA124_CLK_I2S4, TEGRA124_CLK_PLL_A_OUT0, 11289600, 0 }, { TEGRA124_CLK_VDE, TEGRA124_CLK_PLL_C3, 600000000, 0 }, { TEGRA124_CLK_HOST1X, TEGRA124_CLK_PLL_P, 136000000, 1 }, { TEGRA124_CLK_DSIALP, TEGRA124_CLK_PLL_P, 68000000, 0 }, { TEGRA124_CLK_DSIBLP, TEGRA124_CLK_PLL_P, 68000000, 0 }, { TEGRA124_CLK_SCLK, TEGRA124_CLK_PLL_P_OUT2, 102000000, 0 }, { TEGRA124_CLK_DFLL_SOC, TEGRA124_CLK_PLL_P, 51000000, 1 }, { TEGRA124_CLK_DFLL_REF, TEGRA124_CLK_PLL_P, 51000000, 1 }, { TEGRA124_CLK_PLL_C, TEGRA124_CLK_CLK_MAX, 768000000, 0 }, { TEGRA124_CLK_PLL_C_OUT1, TEGRA124_CLK_CLK_MAX, 100000000, 0 }, { TEGRA124_CLK_SBC4, TEGRA124_CLK_PLL_P, 12000000, 1 }, { TEGRA124_CLK_TSEC, TEGRA124_CLK_PLL_C3, 0, 0 }, { TEGRA124_CLK_MSENC, TEGRA124_CLK_PLL_C3, 0, 0 }, { TEGRA124_CLK_PLL_RE_VCO, TEGRA124_CLK_CLK_MAX, 672000000, 0 }, { TEGRA124_CLK_XUSB_SS_SRC, TEGRA124_CLK_PLL_U_480M, 120000000, 0 }, { TEGRA124_CLK_XUSB_FS_SRC, TEGRA124_CLK_PLL_U_48M, 48000000, 0 }, { TEGRA124_CLK_XUSB_HS_SRC, TEGRA124_CLK_PLL_U_60M, 60000000, 0 }, { TEGRA124_CLK_XUSB_FALCON_SRC, TEGRA124_CLK_PLL_RE_OUT, 224000000, 0 }, { TEGRA124_CLK_XUSB_HOST_SRC, TEGRA124_CLK_PLL_RE_OUT, 112000000, 0 }, { TEGRA124_CLK_SATA, TEGRA124_CLK_PLL_P, 104000000, 0 }, { TEGRA124_CLK_SATA_OOB, TEGRA124_CLK_PLL_P, 204000000, 0 }, { TEGRA124_CLK_MSELECT, TEGRA124_CLK_CLK_MAX, 0, 1 }, { TEGRA124_CLK_CSITE, TEGRA124_CLK_CLK_MAX, 0, 1 }, { TEGRA124_CLK_TSENSOR, TEGRA124_CLK_CLK_M, 400000, 0 }, { TEGRA124_CLK_VIC03, TEGRA124_CLK_PLL_C3, 0, 0 }, { TEGRA124_CLK_SPDIF_IN_SYNC, TEGRA124_CLK_CLK_MAX, 24576000, 0 }, { TEGRA124_CLK_I2S0_SYNC, TEGRA124_CLK_CLK_MAX, 24576000, 0 }, { TEGRA124_CLK_I2S1_SYNC, TEGRA124_CLK_CLK_MAX, 24576000, 0 }, { TEGRA124_CLK_I2S2_SYNC, TEGRA124_CLK_CLK_MAX, 24576000, 0 }, { TEGRA124_CLK_I2S3_SYNC, TEGRA124_CLK_CLK_MAX, 24576000, 0 }, { TEGRA124_CLK_I2S4_SYNC, TEGRA124_CLK_CLK_MAX, 24576000, 0 }, { TEGRA124_CLK_VIMCLK_SYNC, TEGRA124_CLK_CLK_MAX, 24576000, 0 }, { TEGRA124_CLK_PWM, TEGRA124_CLK_PLL_P, 408000000, 0 }, /* must be the last entry */ { TEGRA124_CLK_CLK_MAX, TEGRA124_CLK_CLK_MAX, 0, 0 }, }; static struct tegra_clk_init_table tegra124_init_table[] __initdata = { { TEGRA124_CLK_SOC_THERM, TEGRA124_CLK_PLL_P, 51000000, 0 }, { TEGRA124_CLK_CCLK_G, TEGRA124_CLK_CLK_MAX, 0, 1 }, { TEGRA124_CLK_HDA, TEGRA124_CLK_PLL_P, 102000000, 0 }, { TEGRA124_CLK_HDA2CODEC_2X, TEGRA124_CLK_PLL_P, 48000000, 0 }, /* must be the last entry */ { TEGRA124_CLK_CLK_MAX, TEGRA124_CLK_CLK_MAX, 0, 0 }, }; /* Tegra132 requires the SOC_THERM clock to remain active */ static struct tegra_clk_init_table tegra132_init_table[] __initdata = { { TEGRA124_CLK_SOC_THERM, TEGRA124_CLK_PLL_P, 51000000, 1 }, /* must be the last entry */ { TEGRA124_CLK_CLK_MAX, TEGRA124_CLK_CLK_MAX, 0, 0 }, }; static struct tegra_audio_clk_info tegra124_audio_plls[] = { { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_p_out1" }, }; /** * tegra124_clock_apply_init_table - initialize clocks on Tegra124 SoCs * * Program an initial clock rate and enable or disable clocks needed * by the rest of the kernel, for Tegra124 SoCs. It is intended to be * called by assigning a pointer to it to tegra_clk_apply_init_table - * this will be called as an arch_initcall. No return value. */ static void __init tegra124_clock_apply_init_table(void) { tegra_init_from_table(common_init_table, clks, TEGRA124_CLK_CLK_MAX); tegra_init_from_table(tegra124_init_table, clks, TEGRA124_CLK_CLK_MAX); } /** * tegra124_car_barrier - wait for pending writes to the CAR to complete * * Wait for any outstanding writes to the CAR MMIO space from this CPU * to complete before continuing execution. No return value. */ static void tegra124_car_barrier(void) { readl_relaxed(clk_base + RST_DFLL_DVCO); } /** * tegra124_clock_assert_dfll_dvco_reset - assert the DFLL's DVCO reset * * Assert the reset line of the DFLL's DVCO. No return value. */ static void tegra124_clock_assert_dfll_dvco_reset(void) { u32 v; v = readl_relaxed(clk_base + RST_DFLL_DVCO); v |= (1 << DVFS_DFLL_RESET_SHIFT); writel_relaxed(v, clk_base + RST_DFLL_DVCO); tegra124_car_barrier(); } /** * tegra124_clock_deassert_dfll_dvco_reset - deassert the DFLL's DVCO reset * * Deassert the reset line of the DFLL's DVCO, allowing the DVCO to * operate. No return value. */ static void tegra124_clock_deassert_dfll_dvco_reset(void) { u32 v; v = readl_relaxed(clk_base + RST_DFLL_DVCO); v &= ~(1 << DVFS_DFLL_RESET_SHIFT); writel_relaxed(v, clk_base + RST_DFLL_DVCO); tegra124_car_barrier(); } static int tegra124_reset_assert(unsigned long id) { if (id == TEGRA124_RST_DFLL_DVCO) tegra124_clock_assert_dfll_dvco_reset(); else return -EINVAL; return 0; } static int tegra124_reset_deassert(unsigned long id) { if (id == TEGRA124_RST_DFLL_DVCO) tegra124_clock_deassert_dfll_dvco_reset(); else return -EINVAL; return 0; } /** * tegra132_clock_apply_init_table - initialize clocks on Tegra132 SoCs * * Program an initial clock rate and enable or disable clocks needed * by the rest of the kernel, for Tegra132 SoCs. It is intended to be * called by assigning a pointer to it to tegra_clk_apply_init_table - * this will be called as an arch_initcall. No return value. */ static void __init tegra132_clock_apply_init_table(void) { tegra_init_from_table(common_init_table, clks, TEGRA124_CLK_CLK_MAX); tegra_init_from_table(tegra132_init_table, clks, TEGRA124_CLK_CLK_MAX); } /** * tegra124_132_clock_init_pre - clock initialization preamble for T124/T132 * @np: struct device_node * of the DT node for the SoC CAR IP block * * Register most of the clocks controlled by the CAR IP block. * Everything in this function should be common to Tegra124 and Tegra132. * No return value. */ static void __init tegra124_132_clock_init_pre(struct device_node *np) { struct device_node *node; u32 plld_base; clk_base = of_iomap(np, 0); if (!clk_base) { pr_err("ioremap tegra124/tegra132 CAR failed\n"); return; } node = of_find_matching_node(NULL, pmc_match); if (!node) { pr_err("Failed to find pmc node\n"); WARN_ON(1); return; } pmc_base = of_iomap(node, 0); of_node_put(node); if (!pmc_base) { pr_err("Can't map pmc registers\n"); WARN_ON(1); return; } clks = tegra_clk_init(clk_base, TEGRA124_CLK_CLK_MAX, TEGRA124_CAR_BANK_COUNT); if (!clks) return; if (tegra_osc_clk_init(clk_base, tegra124_clks, tegra124_input_freq, ARRAY_SIZE(tegra124_input_freq), 1, &osc_freq, &pll_ref_freq) < 0) return; tegra_fixed_clk_init(tegra124_clks); tegra124_pll_init(clk_base, pmc_base); tegra124_periph_clk_init(clk_base, pmc_base); tegra_audio_clk_init(clk_base, pmc_base, tegra124_clks, tegra124_audio_plls, ARRAY_SIZE(tegra124_audio_plls), 24576000); /* For Tegra124 & Tegra132, PLLD is the only source for DSIA & DSIB */ plld_base = readl(clk_base + PLLD_BASE); plld_base &= ~BIT(25); writel(plld_base, clk_base + PLLD_BASE); } static struct clk *tegra124_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data) { struct clk_hw *hw; struct clk *clk; clk = of_clk_src_onecell_get(clkspec, data); if (IS_ERR(clk)) return clk; hw = __clk_get_hw(clk); if (clkspec->args[0] == TEGRA124_CLK_EMC) { if (!tegra124_clk_emc_driver_available(hw)) return ERR_PTR(-EPROBE_DEFER); } return clk; } /** * tegra124_132_clock_init_post - clock initialization postamble for T124/T132 * @np: struct device_node * of the DT node for the SoC CAR IP block * * Register most of the clocks controlled by the CAR IP block. * Everything in this function should be common to Tegra124 * and Tegra132. This function must be called after * tegra124_132_clock_init_pre(), otherwise clk_base will not be set. * No return value. */ static void __init tegra124_132_clock_init_post(struct device_node *np) { tegra_super_clk_gen4_init(clk_base, pmc_base, tegra124_clks, &pll_x_params); tegra_init_special_resets(1, tegra124_reset_assert, tegra124_reset_deassert); tegra_add_of_provider(np, tegra124_clk_src_onecell_get); clks[TEGRA124_CLK_EMC] = tegra124_clk_register_emc(clk_base, np, &emc_lock); tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); tegra_cpu_car_ops = &tegra124_cpu_car_ops; } /** * tegra124_clock_init - Tegra124-specific clock initialization * @np: struct device_node * of the DT node for the SoC CAR IP block * * Register most SoC clocks for the Tegra124 system-on-chip. Most of * this code is shared between the Tegra124 and Tegra132 SoCs, * although some of the initial clock settings and CPU clocks differ. * Intended to be called by the OF init code when a DT node with the * "nvidia,tegra124-car" string is encountered, and declared with * CLK_OF_DECLARE. No return value. */ static void __init tegra124_clock_init(struct device_node *np) { tegra124_132_clock_init_pre(np); tegra_clk_apply_init_table = tegra124_clock_apply_init_table; tegra124_132_clock_init_post(np); } /** * tegra132_clock_init - Tegra132-specific clock initialization * @np: struct device_node * of the DT node for the SoC CAR IP block * * Register most SoC clocks for the Tegra132 system-on-chip. Most of * this code is shared between the Tegra124 and Tegra132 SoCs, * although some of the initial clock settings and CPU clocks differ. * Intended to be called by the OF init code when a DT node with the * "nvidia,tegra132-car" string is encountered, and declared with * CLK_OF_DECLARE. No return value. */ static void __init tegra132_clock_init(struct device_node *np) { tegra124_132_clock_init_pre(np); /* * On Tegra132, these clocks are controlled by the * CLUSTER_clocks IP block, located in the CPU complex */ tegra124_clks[tegra_clk_cclk_g].present = false; tegra124_clks[tegra_clk_cclk_lp].present = false; tegra124_clks[tegra_clk_pll_x].present = false; tegra124_clks[tegra_clk_pll_x_out0].present = false; tegra_clk_apply_init_table = tegra132_clock_apply_init_table; tegra124_132_clock_init_post(np); } CLK_OF_DECLARE(tegra124, "nvidia,tegra124-car", tegra124_clock_init); CLK_OF_DECLARE(tegra132, "nvidia,tegra132-car", tegra132_clock_init);
linux-master
drivers/clk/tegra/clk-tegra124.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/kernel.h> #include <linux/io.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/slab.h> #include <linux/clk-provider.h> #include "clk.h" #define SUPER_STATE_IDLE 0 #define SUPER_STATE_RUN 1 #define SUPER_STATE_IRQ 2 #define SUPER_STATE_FIQ 3 #define SUPER_STATE_SHIFT 28 #define SUPER_STATE_MASK ((BIT(SUPER_STATE_IDLE) | BIT(SUPER_STATE_RUN) | \ BIT(SUPER_STATE_IRQ) | BIT(SUPER_STATE_FIQ)) \ << SUPER_STATE_SHIFT) #define SUPER_LP_DIV2_BYPASS (1 << 16) #define super_state(s) (BIT(s) << SUPER_STATE_SHIFT) #define super_state_to_src_shift(m, s) ((m->width * s)) #define super_state_to_src_mask(m) (((1 << m->width) - 1)) #define CCLK_SRC_PLLP_OUT0 4 #define CCLK_SRC_PLLP_OUT4 5 static u8 clk_super_get_parent(struct clk_hw *hw) { struct tegra_clk_super_mux *mux = to_clk_super_mux(hw); u32 val, state; u8 source, shift; val = readl_relaxed(mux->reg); state = val & SUPER_STATE_MASK; BUG_ON((state != super_state(SUPER_STATE_RUN)) && (state != super_state(SUPER_STATE_IDLE))); shift = (state == super_state(SUPER_STATE_IDLE)) ? super_state_to_src_shift(mux, SUPER_STATE_IDLE) : super_state_to_src_shift(mux, SUPER_STATE_RUN); source = (val >> shift) & super_state_to_src_mask(mux); /* * If LP_DIV2_BYPASS is not set and PLLX is current parent then * PLLX/2 is the input source to CCLKLP. */ if ((mux->flags & TEGRA_DIVIDER_2) && !(val & SUPER_LP_DIV2_BYPASS) && (source == mux->pllx_index)) source = mux->div2_index; return source; } static int clk_super_set_parent(struct clk_hw *hw, u8 index) { struct tegra_clk_super_mux *mux = to_clk_super_mux(hw); u32 val, state; int err = 0; u8 parent_index, shift; unsigned long flags = 0; if (mux->lock) spin_lock_irqsave(mux->lock, flags); val = readl_relaxed(mux->reg); state = val & SUPER_STATE_MASK; BUG_ON((state != super_state(SUPER_STATE_RUN)) && (state != super_state(SUPER_STATE_IDLE))); shift = (state == super_state(SUPER_STATE_IDLE)) ? super_state_to_src_shift(mux, SUPER_STATE_IDLE) : super_state_to_src_shift(mux, SUPER_STATE_RUN); /* * For LP mode super-clock switch between PLLX direct * and divided-by-2 outputs is allowed only when other * than PLLX clock source is current parent. */ if ((mux->flags & TEGRA_DIVIDER_2) && ((index == mux->div2_index) || (index == mux->pllx_index))) { parent_index = clk_super_get_parent(hw); if ((parent_index == mux->div2_index) || (parent_index == mux->pllx_index)) { err = -EINVAL; goto out; } val ^= SUPER_LP_DIV2_BYPASS; writel_relaxed(val, mux->reg); udelay(2); if (index == mux->div2_index) index = mux->pllx_index; } /* enable PLLP branches to CPU before selecting PLLP source */ if ((mux->flags & TEGRA210_CPU_CLK) && (index == CCLK_SRC_PLLP_OUT0 || index == CCLK_SRC_PLLP_OUT4)) tegra_clk_set_pllp_out_cpu(true); val &= ~((super_state_to_src_mask(mux)) << shift); val |= (index & (super_state_to_src_mask(mux))) << shift; writel_relaxed(val, mux->reg); udelay(2); /* disable PLLP branches to CPU if not used */ if ((mux->flags & TEGRA210_CPU_CLK) && index != CCLK_SRC_PLLP_OUT0 && index != CCLK_SRC_PLLP_OUT4) tegra_clk_set_pllp_out_cpu(false); out: if (mux->lock) spin_unlock_irqrestore(mux->lock, flags); return err; } static void clk_super_mux_restore_context(struct clk_hw *hw) { int parent_id; parent_id = clk_hw_get_parent_index(hw); if (WARN_ON(parent_id < 0)) return; clk_super_set_parent(hw, parent_id); } static const struct clk_ops tegra_clk_super_mux_ops = { .determine_rate = clk_hw_determine_rate_no_reparent, .get_parent = clk_super_get_parent, .set_parent = clk_super_set_parent, .restore_context = clk_super_mux_restore_context, }; static int clk_super_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct tegra_clk_super_mux *super = to_clk_super_mux(hw); struct clk_hw *div_hw = &super->frac_div.hw; unsigned long rate; __clk_hw_set_clk(div_hw, hw); rate = super->div_ops->round_rate(div_hw, req->rate, &req->best_parent_rate); if (rate < 0) return rate; req->rate = rate; return 0; } static unsigned long clk_super_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_super_mux *super = to_clk_super_mux(hw); struct clk_hw *div_hw = &super->frac_div.hw; __clk_hw_set_clk(div_hw, hw); return super->div_ops->recalc_rate(div_hw, parent_rate); } static int clk_super_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_super_mux *super = to_clk_super_mux(hw); struct clk_hw *div_hw = &super->frac_div.hw; __clk_hw_set_clk(div_hw, hw); return super->div_ops->set_rate(div_hw, rate, parent_rate); } static void clk_super_restore_context(struct clk_hw *hw) { struct tegra_clk_super_mux *super = to_clk_super_mux(hw); struct clk_hw *div_hw = &super->frac_div.hw; int parent_id; parent_id = clk_hw_get_parent_index(hw); if (WARN_ON(parent_id < 0)) return; super->div_ops->restore_context(div_hw); clk_super_set_parent(hw, parent_id); } const struct clk_ops tegra_clk_super_ops = { .get_parent = clk_super_get_parent, .set_parent = clk_super_set_parent, .set_rate = clk_super_set_rate, .determine_rate = clk_super_determine_rate, .recalc_rate = clk_super_recalc_rate, .restore_context = clk_super_restore_context, }; struct clk *tegra_clk_register_super_mux(const char *name, const char **parent_names, u8 num_parents, unsigned long flags, void __iomem *reg, u8 clk_super_flags, u8 width, u8 pllx_index, u8 div2_index, spinlock_t *lock) { struct tegra_clk_super_mux *super; struct clk *clk; struct clk_init_data init; super = kzalloc(sizeof(*super), GFP_KERNEL); if (!super) return ERR_PTR(-ENOMEM); init.name = name; init.ops = &tegra_clk_super_mux_ops; init.flags = flags; init.parent_names = parent_names; init.num_parents = num_parents; super->reg = reg; super->pllx_index = pllx_index; super->div2_index = div2_index; super->lock = lock; super->width = width; super->flags = clk_super_flags; /* Data in .init is copied by clk_register(), so stack variable OK */ super->hw.init = &init; clk = tegra_clk_dev_register(&super->hw); if (IS_ERR(clk)) kfree(super); return clk; } struct clk *tegra_clk_register_super_clk(const char *name, const char * const *parent_names, u8 num_parents, unsigned long flags, void __iomem *reg, u8 clk_super_flags, spinlock_t *lock) { struct tegra_clk_super_mux *super; struct clk *clk; struct clk_init_data init; super = kzalloc(sizeof(*super), GFP_KERNEL); if (!super) return ERR_PTR(-ENOMEM); init.name = name; init.ops = &tegra_clk_super_ops; init.flags = flags; init.parent_names = parent_names; init.num_parents = num_parents; super->reg = reg; super->lock = lock; super->width = 4; super->flags = clk_super_flags; super->frac_div.reg = reg + 4; super->frac_div.shift = 16; super->frac_div.width = 8; super->frac_div.frac_width = 1; super->frac_div.lock = lock; super->div_ops = &tegra_clk_frac_div_ops; /* Data in .init is copied by clk_register(), so stack variable OK */ super->hw.init = &init; clk = clk_register(NULL, &super->hw); if (IS_ERR(clk)) kfree(super); return clk; }
linux-master
drivers/clk/tegra/clk-super.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/export.h> #include <linux/slab.h> #include <linux/err.h> #include "clk.h" static u8 clk_periph_get_parent(struct clk_hw *hw) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *mux_ops = periph->mux_ops; struct clk_hw *mux_hw = &periph->mux.hw; __clk_hw_set_clk(mux_hw, hw); return mux_ops->get_parent(mux_hw); } static int clk_periph_set_parent(struct clk_hw *hw, u8 index) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *mux_ops = periph->mux_ops; struct clk_hw *mux_hw = &periph->mux.hw; __clk_hw_set_clk(mux_hw, hw); return mux_ops->set_parent(mux_hw, index); } static unsigned long clk_periph_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *div_ops = periph->div_ops; struct clk_hw *div_hw = &periph->divider.hw; __clk_hw_set_clk(div_hw, hw); return div_ops->recalc_rate(div_hw, parent_rate); } static int clk_periph_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *div_ops = periph->div_ops; struct clk_hw *div_hw = &periph->divider.hw; unsigned long rate; __clk_hw_set_clk(div_hw, hw); rate = div_ops->round_rate(div_hw, req->rate, &req->best_parent_rate); if (rate < 0) return rate; req->rate = rate; return 0; } static int clk_periph_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *div_ops = periph->div_ops; struct clk_hw *div_hw = &periph->divider.hw; __clk_hw_set_clk(div_hw, hw); return div_ops->set_rate(div_hw, rate, parent_rate); } static int clk_periph_is_enabled(struct clk_hw *hw) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *gate_ops = periph->gate_ops; struct clk_hw *gate_hw = &periph->gate.hw; __clk_hw_set_clk(gate_hw, hw); return gate_ops->is_enabled(gate_hw); } static int clk_periph_enable(struct clk_hw *hw) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *gate_ops = periph->gate_ops; struct clk_hw *gate_hw = &periph->gate.hw; __clk_hw_set_clk(gate_hw, hw); return gate_ops->enable(gate_hw); } static void clk_periph_disable(struct clk_hw *hw) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *gate_ops = periph->gate_ops; struct clk_hw *gate_hw = &periph->gate.hw; gate_ops->disable(gate_hw); } static void clk_periph_disable_unused(struct clk_hw *hw) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *gate_ops = periph->gate_ops; struct clk_hw *gate_hw = &periph->gate.hw; gate_ops->disable_unused(gate_hw); } static void clk_periph_restore_context(struct clk_hw *hw) { struct tegra_clk_periph *periph = to_clk_periph(hw); const struct clk_ops *div_ops = periph->div_ops; struct clk_hw *div_hw = &periph->divider.hw; int parent_id; parent_id = clk_hw_get_parent_index(hw); if (WARN_ON(parent_id < 0)) return; if (!(periph->gate.flags & TEGRA_PERIPH_NO_DIV)) div_ops->restore_context(div_hw); clk_periph_set_parent(hw, parent_id); } const struct clk_ops tegra_clk_periph_ops = { .get_parent = clk_periph_get_parent, .set_parent = clk_periph_set_parent, .recalc_rate = clk_periph_recalc_rate, .determine_rate = clk_periph_determine_rate, .set_rate = clk_periph_set_rate, .is_enabled = clk_periph_is_enabled, .enable = clk_periph_enable, .disable = clk_periph_disable, .disable_unused = clk_periph_disable_unused, .restore_context = clk_periph_restore_context, }; static const struct clk_ops tegra_clk_periph_nodiv_ops = { .determine_rate = clk_hw_determine_rate_no_reparent, .get_parent = clk_periph_get_parent, .set_parent = clk_periph_set_parent, .is_enabled = clk_periph_is_enabled, .enable = clk_periph_enable, .disable = clk_periph_disable, .disable_unused = clk_periph_disable_unused, .restore_context = clk_periph_restore_context, }; static const struct clk_ops tegra_clk_periph_no_gate_ops = { .get_parent = clk_periph_get_parent, .set_parent = clk_periph_set_parent, .recalc_rate = clk_periph_recalc_rate, .determine_rate = clk_periph_determine_rate, .set_rate = clk_periph_set_rate, .restore_context = clk_periph_restore_context, }; static struct clk *_tegra_clk_register_periph(const char *name, const char * const *parent_names, int num_parents, struct tegra_clk_periph *periph, void __iomem *clk_base, u32 offset, unsigned long flags) { struct clk *clk; struct clk_init_data init; const struct tegra_clk_periph_regs *bank; bool div = !(periph->gate.flags & TEGRA_PERIPH_NO_DIV); if (periph->gate.flags & TEGRA_PERIPH_NO_DIV) { flags |= CLK_SET_RATE_PARENT; init.ops = &tegra_clk_periph_nodiv_ops; } else if (periph->gate.flags & TEGRA_PERIPH_NO_GATE) init.ops = &tegra_clk_periph_no_gate_ops; else init.ops = &tegra_clk_periph_ops; init.name = name; init.flags = flags; init.parent_names = parent_names; init.num_parents = num_parents; bank = get_reg_bank(periph->gate.clk_num); if (!bank) return ERR_PTR(-EINVAL); /* Data in .init is copied by clk_register(), so stack variable OK */ periph->hw.init = &init; periph->magic = TEGRA_CLK_PERIPH_MAGIC; periph->mux.reg = clk_base + offset; periph->divider.reg = div ? (clk_base + offset) : NULL; periph->gate.clk_base = clk_base; periph->gate.regs = bank; periph->gate.enable_refcnt = periph_clk_enb_refcnt; clk = clk_register(NULL, &periph->hw); if (IS_ERR(clk)) return clk; periph->mux.hw.clk = clk; periph->divider.hw.clk = div ? clk : NULL; periph->gate.hw.clk = clk; return clk; } struct clk *tegra_clk_register_periph(const char *name, const char * const *parent_names, int num_parents, struct tegra_clk_periph *periph, void __iomem *clk_base, u32 offset, unsigned long flags) { return _tegra_clk_register_periph(name, parent_names, num_parents, periph, clk_base, offset, flags); } struct clk *tegra_clk_register_periph_nodiv(const char *name, const char * const *parent_names, int num_parents, struct tegra_clk_periph *periph, void __iomem *clk_base, u32 offset) { periph->gate.flags |= TEGRA_PERIPH_NO_DIV; return _tegra_clk_register_periph(name, parent_names, num_parents, periph, clk_base, offset, CLK_SET_RATE_PARENT); } struct clk *tegra_clk_register_periph_data(void __iomem *clk_base, struct tegra_periph_init_data *init) { return _tegra_clk_register_periph(init->name, init->p.parent_names, init->num_parents, &init->periph, clk_base, init->offset, init->flags); }
linux-master
drivers/clk/tegra/clk-periph.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/kernel.h> #include <linux/io.h> #include <linux/err.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/clk-provider.h> #include "clk.h" #define pll_out_enb(p) (BIT(p->enb_bit_idx)) #define pll_out_rst(p) (BIT(p->rst_bit_idx)) static int clk_pll_out_is_enabled(struct clk_hw *hw) { struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw); u32 val = readl_relaxed(pll_out->reg); int state; state = (val & pll_out_enb(pll_out)) ? 1 : 0; if (!(val & (pll_out_rst(pll_out)))) state = 0; return state; } static int clk_pll_out_enable(struct clk_hw *hw) { struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw); unsigned long flags = 0; u32 val; if (pll_out->lock) spin_lock_irqsave(pll_out->lock, flags); val = readl_relaxed(pll_out->reg); val |= (pll_out_enb(pll_out) | pll_out_rst(pll_out)); writel_relaxed(val, pll_out->reg); udelay(2); if (pll_out->lock) spin_unlock_irqrestore(pll_out->lock, flags); return 0; } static void clk_pll_out_disable(struct clk_hw *hw) { struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw); unsigned long flags = 0; u32 val; if (pll_out->lock) spin_lock_irqsave(pll_out->lock, flags); val = readl_relaxed(pll_out->reg); val &= ~(pll_out_enb(pll_out) | pll_out_rst(pll_out)); writel_relaxed(val, pll_out->reg); udelay(2); if (pll_out->lock) spin_unlock_irqrestore(pll_out->lock, flags); } static void tegra_clk_pll_out_restore_context(struct clk_hw *hw) { if (!__clk_get_enable_count(hw->clk)) clk_pll_out_disable(hw); else clk_pll_out_enable(hw); } const struct clk_ops tegra_clk_pll_out_ops = { .is_enabled = clk_pll_out_is_enabled, .enable = clk_pll_out_enable, .disable = clk_pll_out_disable, .restore_context = tegra_clk_pll_out_restore_context, }; struct clk *tegra_clk_register_pll_out(const char *name, const char *parent_name, void __iomem *reg, u8 enb_bit_idx, u8 rst_bit_idx, unsigned long flags, u8 pll_out_flags, spinlock_t *lock) { struct tegra_clk_pll_out *pll_out; struct clk *clk; struct clk_init_data init; pll_out = kzalloc(sizeof(*pll_out), GFP_KERNEL); if (!pll_out) return ERR_PTR(-ENOMEM); init.name = name; init.ops = &tegra_clk_pll_out_ops; init.parent_names = (parent_name ? &parent_name : NULL); init.num_parents = (parent_name ? 1 : 0); init.flags = flags; pll_out->reg = reg; pll_out->enb_bit_idx = enb_bit_idx; pll_out->rst_bit_idx = rst_bit_idx; pll_out->flags = pll_out_flags; pll_out->lock = lock; /* Data in .init is copied by clk_register(), so stack variable OK */ pll_out->hw.init = &init; clk = clk_register(NULL, &pll_out->hw); if (IS_ERR(clk)) kfree(pll_out); return clk; }
linux-master
drivers/clk/tegra/clk-pll-out.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved. */ #include <linux/io.h> #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/clk/tegra.h> #include "clk.h" #include "clk-id.h" #define AUDIO_SYNC_CLK_I2S0 0x4a0 #define AUDIO_SYNC_CLK_I2S1 0x4a4 #define AUDIO_SYNC_CLK_I2S2 0x4a8 #define AUDIO_SYNC_CLK_I2S3 0x4ac #define AUDIO_SYNC_CLK_I2S4 0x4b0 #define AUDIO_SYNC_CLK_SPDIF 0x4b4 #define AUDIO_SYNC_CLK_DMIC1 0x560 #define AUDIO_SYNC_CLK_DMIC2 0x564 #define AUDIO_SYNC_CLK_DMIC3 0x6b8 #define AUDIO_SYNC_DOUBLER 0x49c #define PLLA_OUT 0xb4 struct tegra_sync_source_initdata { char *name; unsigned long rate; unsigned long max_rate; int clk_id; }; #define SYNC(_name) \ {\ .name = #_name,\ .clk_id = tegra_clk_ ## _name,\ } struct tegra_audio_clk_initdata { char *gate_name; char *mux_name; u32 offset; int gate_clk_id; int mux_clk_id; }; #define AUDIO(_name, _offset) \ {\ .gate_name = #_name,\ .mux_name = #_name"_mux",\ .offset = _offset,\ .gate_clk_id = tegra_clk_ ## _name,\ .mux_clk_id = tegra_clk_ ## _name ## _mux,\ } struct tegra_audio2x_clk_initdata { char *parent; char *gate_name; char *name_2x; char *div_name; int clk_id; int clk_num; u8 div_offset; }; #define AUDIO2X(_name, _num, _offset) \ {\ .parent = #_name,\ .gate_name = #_name"_2x",\ .name_2x = #_name"_doubler",\ .div_name = #_name"_div",\ .clk_id = tegra_clk_ ## _name ## _2x,\ .clk_num = _num,\ .div_offset = _offset,\ } static DEFINE_SPINLOCK(clk_doubler_lock); static const char * const mux_audio_sync_clk[] = { "spdif_in_sync", "i2s0_sync", "i2s1_sync", "i2s2_sync", "i2s3_sync", "i2s4_sync", "pll_a_out0", "vimclk_sync", }; static const char * const mux_dmic_sync_clk[] = { "unused", "i2s0_sync", "i2s1_sync", "i2s2_sync", "i2s3_sync", "i2s4_sync", "pll_a_out0", "vimclk_sync", }; static struct tegra_sync_source_initdata sync_source_clks[] __initdata = { SYNC(spdif_in_sync), SYNC(i2s0_sync), SYNC(i2s1_sync), SYNC(i2s2_sync), SYNC(i2s3_sync), SYNC(i2s4_sync), SYNC(vimclk_sync), }; static struct tegra_audio_clk_initdata audio_clks[] = { AUDIO(audio0, AUDIO_SYNC_CLK_I2S0), AUDIO(audio1, AUDIO_SYNC_CLK_I2S1), AUDIO(audio2, AUDIO_SYNC_CLK_I2S2), AUDIO(audio3, AUDIO_SYNC_CLK_I2S3), AUDIO(audio4, AUDIO_SYNC_CLK_I2S4), AUDIO(spdif, AUDIO_SYNC_CLK_SPDIF), }; static struct tegra_audio_clk_initdata dmic_clks[] = { AUDIO(dmic1_sync_clk, AUDIO_SYNC_CLK_DMIC1), AUDIO(dmic2_sync_clk, AUDIO_SYNC_CLK_DMIC2), AUDIO(dmic3_sync_clk, AUDIO_SYNC_CLK_DMIC3), }; static struct tegra_audio2x_clk_initdata audio2x_clks[] = { AUDIO2X(audio0, 113, 24), AUDIO2X(audio1, 114, 25), AUDIO2X(audio2, 115, 26), AUDIO2X(audio3, 116, 27), AUDIO2X(audio4, 117, 28), AUDIO2X(spdif, 118, 29), }; static void __init tegra_audio_sync_clk_init(void __iomem *clk_base, struct tegra_clk *tegra_clks, struct tegra_audio_clk_initdata *sync, int num_sync_clks, const char * const *mux_names, int num_mux_inputs) { struct clk *clk; struct clk **dt_clk; struct tegra_audio_clk_initdata *data; int i; for (i = 0, data = sync; i < num_sync_clks; i++, data++) { dt_clk = tegra_lookup_dt_id(data->mux_clk_id, tegra_clks); if (!dt_clk) continue; clk = clk_register_mux(NULL, data->mux_name, mux_names, num_mux_inputs, CLK_SET_RATE_NO_REPARENT, clk_base + data->offset, 0, 3, 0, NULL); *dt_clk = clk; dt_clk = tegra_lookup_dt_id(data->gate_clk_id, tegra_clks); if (!dt_clk) continue; clk = clk_register_gate(NULL, data->gate_name, data->mux_name, 0, clk_base + data->offset, 4, CLK_GATE_SET_TO_DISABLE, NULL); *dt_clk = clk; } } void __init tegra_audio_clk_init(void __iomem *clk_base, void __iomem *pmc_base, struct tegra_clk *tegra_clks, struct tegra_audio_clk_info *audio_info, unsigned int num_plls, unsigned long sync_max_rate) { struct clk *clk; struct clk **dt_clk; int i; if (!audio_info || num_plls < 1) { pr_err("No audio data passed to tegra_audio_clk_init\n"); WARN_ON(1); return; } for (i = 0; i < num_plls; i++) { struct tegra_audio_clk_info *info = &audio_info[i]; dt_clk = tegra_lookup_dt_id(info->clk_id, tegra_clks); if (dt_clk) { clk = tegra_clk_register_pll(info->name, info->parent, clk_base, pmc_base, 0, info->pll_params, NULL); *dt_clk = clk; } } /* PLLA_OUT0 */ dt_clk = tegra_lookup_dt_id(tegra_clk_pll_a_out0, tegra_clks); if (dt_clk) { clk = tegra_clk_register_divider("pll_a_out0_div", "pll_a", clk_base + PLLA_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 8, 8, 1, NULL); clk = tegra_clk_register_pll_out("pll_a_out0", "pll_a_out0_div", clk_base + PLLA_OUT, 1, 0, CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0, NULL); *dt_clk = clk; } for (i = 0; i < ARRAY_SIZE(sync_source_clks); i++) { struct tegra_sync_source_initdata *data; data = &sync_source_clks[i]; dt_clk = tegra_lookup_dt_id(data->clk_id, tegra_clks); if (!dt_clk) continue; clk = tegra_clk_register_sync_source(data->name, sync_max_rate); *dt_clk = clk; } tegra_audio_sync_clk_init(clk_base, tegra_clks, audio_clks, ARRAY_SIZE(audio_clks), mux_audio_sync_clk, ARRAY_SIZE(mux_audio_sync_clk)); /* make sure the DMIC sync clocks have a valid parent */ for (i = 0; i < ARRAY_SIZE(dmic_clks); i++) writel_relaxed(1, clk_base + dmic_clks[i].offset); tegra_audio_sync_clk_init(clk_base, tegra_clks, dmic_clks, ARRAY_SIZE(dmic_clks), mux_dmic_sync_clk, ARRAY_SIZE(mux_dmic_sync_clk)); for (i = 0; i < ARRAY_SIZE(audio2x_clks); i++) { struct tegra_audio2x_clk_initdata *data; data = &audio2x_clks[i]; dt_clk = tegra_lookup_dt_id(data->clk_id, tegra_clks); if (!dt_clk) continue; clk = clk_register_fixed_factor(NULL, data->name_2x, data->parent, CLK_SET_RATE_PARENT, 2, 1); clk = tegra_clk_register_divider(data->div_name, data->name_2x, clk_base + AUDIO_SYNC_DOUBLER, 0, 0, data->div_offset, 1, 0, &clk_doubler_lock); clk = tegra_clk_register_periph_gate(data->gate_name, data->div_name, TEGRA_PERIPH_NO_RESET, clk_base, CLK_SET_RATE_PARENT, data->clk_num, periph_clk_enb_refcnt); *dt_clk = clk; } }
linux-master
drivers/clk/tegra/clk-tegra-audio.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ #include <linux/kernel.h> #include <linux/io.h> #include <linux/err.h> #include <linux/slab.h> #include <linux/clk-provider.h> #include "clk.h" #define pll_out_override(p) (BIT((p->shift - 6))) #define div_mask(d) ((1 << (d->width)) - 1) #define get_mul(d) (1 << d->frac_width) #define get_max_div(d) div_mask(d) #define PERIPH_CLK_UART_DIV_ENB BIT(24) static int get_div(struct tegra_clk_frac_div *divider, unsigned long rate, unsigned long parent_rate) { int div; div = div_frac_get(rate, parent_rate, divider->width, divider->frac_width, divider->flags); if (div < 0) return 0; return div; } static unsigned long clk_frac_div_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_clk_frac_div *divider = to_clk_frac_div(hw); u32 reg; int div, mul; u64 rate = parent_rate; reg = readl_relaxed(divider->reg); if ((divider->flags & TEGRA_DIVIDER_UART) && !(reg & PERIPH_CLK_UART_DIV_ENB)) return rate; div = (reg >> divider->shift) & div_mask(divider); mul = get_mul(divider); div += mul; rate *= mul; rate += div - 1; do_div(rate, div); return rate; } static long clk_frac_div_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct tegra_clk_frac_div *divider = to_clk_frac_div(hw); int div, mul; unsigned long output_rate = *prate; if (!rate) return output_rate; div = get_div(divider, rate, output_rate); if (div < 0) return *prate; mul = get_mul(divider); return DIV_ROUND_UP(output_rate * mul, div + mul); } static int clk_frac_div_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_clk_frac_div *divider = to_clk_frac_div(hw); int div; unsigned long flags = 0; u32 val; div = get_div(divider, rate, parent_rate); if (div < 0) return div; if (divider->lock) spin_lock_irqsave(divider->lock, flags); val = readl_relaxed(divider->reg); val &= ~(div_mask(divider) << divider->shift); val |= div << divider->shift; if (divider->flags & TEGRA_DIVIDER_UART) { if (div) val |= PERIPH_CLK_UART_DIV_ENB; else val &= ~PERIPH_CLK_UART_DIV_ENB; } if (divider->flags & TEGRA_DIVIDER_FIXED) val |= pll_out_override(divider); writel_relaxed(val, divider->reg); if (divider->lock) spin_unlock_irqrestore(divider->lock, flags); return 0; } static void clk_divider_restore_context(struct clk_hw *hw) { struct clk_hw *parent = clk_hw_get_parent(hw); unsigned long parent_rate = clk_hw_get_rate(parent); unsigned long rate = clk_hw_get_rate(hw); if (clk_frac_div_set_rate(hw, rate, parent_rate) < 0) WARN_ON(1); } const struct clk_ops tegra_clk_frac_div_ops = { .recalc_rate = clk_frac_div_recalc_rate, .set_rate = clk_frac_div_set_rate, .round_rate = clk_frac_div_round_rate, .restore_context = clk_divider_restore_context, }; struct clk *tegra_clk_register_divider(const char *name, const char *parent_name, void __iomem *reg, unsigned long flags, u8 clk_divider_flags, u8 shift, u8 width, u8 frac_width, spinlock_t *lock) { struct tegra_clk_frac_div *divider; struct clk *clk; struct clk_init_data init; divider = kzalloc(sizeof(*divider), GFP_KERNEL); if (!divider) { pr_err("%s: could not allocate fractional divider clk\n", __func__); return ERR_PTR(-ENOMEM); } init.name = name; init.ops = &tegra_clk_frac_div_ops; init.flags = flags; init.parent_names = parent_name ? &parent_name : NULL; init.num_parents = parent_name ? 1 : 0; divider->reg = reg; divider->shift = shift; divider->width = width; divider->frac_width = frac_width; divider->lock = lock; divider->flags = clk_divider_flags; /* Data in .init is copied by clk_register(), so stack variable OK */ divider->hw.init = &init; clk = clk_register(NULL, &divider->hw); if (IS_ERR(clk)) kfree(divider); return clk; } static const struct clk_div_table mc_div_table[] = { { .val = 0, .div = 2 }, { .val = 1, .div = 1 }, { .val = 0, .div = 0 }, }; struct clk *tegra_clk_register_mc(const char *name, const char *parent_name, void __iomem *reg, spinlock_t *lock) { return clk_register_divider_table(NULL, name, parent_name, CLK_IS_CRITICAL, reg, 16, 1, CLK_DIVIDER_READ_ONLY, mc_div_table, lock); }
linux-master
drivers/clk/tegra/clk-divider.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. * * based on clk-mux.c * * Copyright (C) 2011 Sascha Hauer, Pengutronix <[email protected]> * Copyright (C) 2011 Richard Zhao, Linaro <[email protected]> * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <[email protected]> * */ #include <linux/clk-provider.h> #include <linux/err.h> #include <linux/io.h> #include <linux/types.h> #include "clk.h" #define DIV_MASK GENMASK(7, 0) #define MUX_SHIFT 29 #define MUX_MASK GENMASK(MUX_SHIFT + 2, MUX_SHIFT) #define SDMMC_MUL 2 #define get_max_div(d) DIV_MASK #define get_div_field(val) ((val) & DIV_MASK) #define get_mux_field(val) (((val) & MUX_MASK) >> MUX_SHIFT) static const char * const mux_sdmmc_parents[] = { "pll_p", "pll_c4_out2", "pll_c4_out0", "pll_c4_out1", "clk_m" }; static const u8 mux_lj_idx[] = { [0] = 0, [1] = 1, [2] = 2, [3] = 5, [4] = 6 }; static const u8 mux_non_lj_idx[] = { [0] = 0, [1] = 3, [2] = 7, [3] = 4, [4] = 6 }; static u8 clk_sdmmc_mux_get_parent(struct clk_hw *hw) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); int num_parents, i; u32 src, val; const u8 *mux_idx; num_parents = clk_hw_get_num_parents(hw); val = readl_relaxed(sdmmc_mux->reg); src = get_mux_field(val); if (get_div_field(val)) mux_idx = mux_non_lj_idx; else mux_idx = mux_lj_idx; for (i = 0; i < num_parents; i++) { if (mux_idx[i] == src) return i; } WARN(1, "Unknown parent selector %d\n", src); return 0; } static int clk_sdmmc_mux_set_parent(struct clk_hw *hw, u8 index) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); u32 val; val = readl_relaxed(sdmmc_mux->reg); if (get_div_field(val)) index = mux_non_lj_idx[index]; else index = mux_lj_idx[index]; val &= ~MUX_MASK; val |= index << MUX_SHIFT; writel(val, sdmmc_mux->reg); return 0; } static unsigned long clk_sdmmc_mux_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); u32 val; int div; u64 rate = parent_rate; val = readl_relaxed(sdmmc_mux->reg); div = get_div_field(val); div += SDMMC_MUL; rate *= SDMMC_MUL; rate += div - 1; do_div(rate, div); return rate; } static int clk_sdmmc_mux_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); int div; unsigned long output_rate = req->best_parent_rate; req->rate = max(req->rate, req->min_rate); req->rate = min(req->rate, req->max_rate); if (!req->rate) return output_rate; div = div_frac_get(req->rate, output_rate, 8, 1, sdmmc_mux->div_flags); if (div < 0) div = 0; if (sdmmc_mux->div_flags & TEGRA_DIVIDER_ROUND_UP) req->rate = DIV_ROUND_UP(output_rate * SDMMC_MUL, div + SDMMC_MUL); else req->rate = output_rate * SDMMC_MUL / (div + SDMMC_MUL); return 0; } static int clk_sdmmc_mux_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); int div; unsigned long flags = 0; u32 val; u8 src; div = div_frac_get(rate, parent_rate, 8, 1, sdmmc_mux->div_flags); if (div < 0) return div; if (sdmmc_mux->lock) spin_lock_irqsave(sdmmc_mux->lock, flags); src = clk_sdmmc_mux_get_parent(hw); if (div) src = mux_non_lj_idx[src]; else src = mux_lj_idx[src]; val = src << MUX_SHIFT; val |= div; writel(val, sdmmc_mux->reg); fence_udelay(2, sdmmc_mux->reg); if (sdmmc_mux->lock) spin_unlock_irqrestore(sdmmc_mux->lock, flags); return 0; } static int clk_sdmmc_mux_is_enabled(struct clk_hw *hw) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); const struct clk_ops *gate_ops = sdmmc_mux->gate_ops; struct clk_hw *gate_hw = &sdmmc_mux->gate.hw; __clk_hw_set_clk(gate_hw, hw); return gate_ops->is_enabled(gate_hw); } static int clk_sdmmc_mux_enable(struct clk_hw *hw) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); const struct clk_ops *gate_ops = sdmmc_mux->gate_ops; struct clk_hw *gate_hw = &sdmmc_mux->gate.hw; __clk_hw_set_clk(gate_hw, hw); return gate_ops->enable(gate_hw); } static void clk_sdmmc_mux_disable(struct clk_hw *hw) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); const struct clk_ops *gate_ops = sdmmc_mux->gate_ops; struct clk_hw *gate_hw = &sdmmc_mux->gate.hw; gate_ops->disable(gate_hw); } static void clk_sdmmc_mux_disable_unused(struct clk_hw *hw) { struct tegra_sdmmc_mux *sdmmc_mux = to_clk_sdmmc_mux(hw); const struct clk_ops *gate_ops = sdmmc_mux->gate_ops; struct clk_hw *gate_hw = &sdmmc_mux->gate.hw; gate_ops->disable_unused(gate_hw); } static void clk_sdmmc_mux_restore_context(struct clk_hw *hw) { struct clk_hw *parent = clk_hw_get_parent(hw); unsigned long parent_rate = clk_hw_get_rate(parent); unsigned long rate = clk_hw_get_rate(hw); int parent_id; parent_id = clk_hw_get_parent_index(hw); if (WARN_ON(parent_id < 0)) return; clk_sdmmc_mux_set_parent(hw, parent_id); clk_sdmmc_mux_set_rate(hw, rate, parent_rate); } static const struct clk_ops tegra_clk_sdmmc_mux_ops = { .get_parent = clk_sdmmc_mux_get_parent, .set_parent = clk_sdmmc_mux_set_parent, .determine_rate = clk_sdmmc_mux_determine_rate, .recalc_rate = clk_sdmmc_mux_recalc_rate, .set_rate = clk_sdmmc_mux_set_rate, .is_enabled = clk_sdmmc_mux_is_enabled, .enable = clk_sdmmc_mux_enable, .disable = clk_sdmmc_mux_disable, .disable_unused = clk_sdmmc_mux_disable_unused, .restore_context = clk_sdmmc_mux_restore_context, }; struct clk *tegra_clk_register_sdmmc_mux_div(const char *name, void __iomem *clk_base, u32 offset, u32 clk_num, u8 div_flags, unsigned long flags, void *lock) { struct clk *clk; struct clk_init_data init; const struct tegra_clk_periph_regs *bank; struct tegra_sdmmc_mux *sdmmc_mux; init.ops = &tegra_clk_sdmmc_mux_ops; init.name = name; init.flags = flags; init.parent_names = mux_sdmmc_parents; init.num_parents = ARRAY_SIZE(mux_sdmmc_parents); bank = get_reg_bank(clk_num); if (!bank) return ERR_PTR(-EINVAL); sdmmc_mux = kzalloc(sizeof(*sdmmc_mux), GFP_KERNEL); if (!sdmmc_mux) return ERR_PTR(-ENOMEM); /* Data in .init is copied by clk_register(), so stack variable OK */ sdmmc_mux->hw.init = &init; sdmmc_mux->reg = clk_base + offset; sdmmc_mux->lock = lock; sdmmc_mux->gate.clk_base = clk_base; sdmmc_mux->gate.regs = bank; sdmmc_mux->gate.enable_refcnt = periph_clk_enb_refcnt; sdmmc_mux->gate.clk_num = clk_num; sdmmc_mux->gate.flags = TEGRA_PERIPH_ON_APB; sdmmc_mux->div_flags = div_flags; sdmmc_mux->gate_ops = &tegra_clk_periph_gate_ops; clk = clk_register(NULL, &sdmmc_mux->hw); if (IS_ERR(clk)) { kfree(sdmmc_mux); return clk; } sdmmc_mux->gate.hw.clk = clk; return clk; }
linux-master
drivers/clk/tegra/clk-sdmmc-mux.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2015-2020, NVIDIA CORPORATION. All rights reserved. */ #include <linux/bitfield.h> #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/clk/tegra.h> #include <linux/device.h> #include <linux/module.h> #include <linux/io.h> #include <linux/slab.h> #include "clk.h" #define CLK_SOURCE_EMC 0x19c #define CLK_SOURCE_EMC_2X_CLK_SRC GENMASK(31, 29) #define CLK_SOURCE_EMC_MC_EMC_SAME_FREQ BIT(16) #define CLK_SOURCE_EMC_2X_CLK_DIVISOR GENMASK(7, 0) #define CLK_SRC_PLLM 0 #define CLK_SRC_PLLC 1 #define CLK_SRC_PLLP 2 #define CLK_SRC_CLK_M 3 #define CLK_SRC_PLLM_UD 4 #define CLK_SRC_PLLMB_UD 5 #define CLK_SRC_PLLMB 6 #define CLK_SRC_PLLP_UD 7 struct tegra210_clk_emc { struct clk_hw hw; void __iomem *regs; struct tegra210_clk_emc_provider *provider; struct clk *parents[8]; }; static inline struct tegra210_clk_emc * to_tegra210_clk_emc(struct clk_hw *hw) { return container_of(hw, struct tegra210_clk_emc, hw); } static const char *tegra210_clk_emc_parents[] = { "pll_m", "pll_c", "pll_p", "clk_m", "pll_m_ud", "pll_mb_ud", "pll_mb", "pll_p_ud", }; static u8 tegra210_clk_emc_get_parent(struct clk_hw *hw) { struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw); u32 value; u8 src; value = readl_relaxed(emc->regs + CLK_SOURCE_EMC); src = FIELD_GET(CLK_SOURCE_EMC_2X_CLK_SRC, value); return src; } static unsigned long tegra210_clk_emc_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw); u32 value, div; /* * CCF assumes that neither the parent nor its rate will change during * ->set_rate(), so the parent rate passed in here was cached from the * parent before the ->set_rate() call. * * This can lead to wrong results being reported for the EMC clock if * the parent and/or parent rate have changed as part of the EMC rate * change sequence. Fix this by overriding the parent clock with what * we know to be the correct value after the rate change. */ parent_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); value = readl_relaxed(emc->regs + CLK_SOURCE_EMC); div = FIELD_GET(CLK_SOURCE_EMC_2X_CLK_DIVISOR, value); div += 2; return DIV_ROUND_UP(parent_rate * 2, div); } static long tegra210_clk_emc_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw); struct tegra210_clk_emc_provider *provider = emc->provider; unsigned int i; if (!provider || !provider->configs || provider->num_configs == 0) return clk_hw_get_rate(hw); for (i = 0; i < provider->num_configs; i++) { if (provider->configs[i].rate >= rate) return provider->configs[i].rate; } return provider->configs[i - 1].rate; } static struct clk *tegra210_clk_emc_find_parent(struct tegra210_clk_emc *emc, u8 index) { struct clk_hw *parent = clk_hw_get_parent_by_index(&emc->hw, index); const char *name = clk_hw_get_name(parent); /* XXX implement cache? */ return __clk_lookup(name); } static int tegra210_clk_emc_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw); struct tegra210_clk_emc_provider *provider = emc->provider; struct tegra210_clk_emc_config *config; struct device *dev = provider->dev; struct clk_hw *old, *new, *parent; u8 old_idx, new_idx, index; struct clk *clk; unsigned int i; int err; if (!provider->configs || provider->num_configs == 0) return -EINVAL; for (i = 0; i < provider->num_configs; i++) { if (provider->configs[i].rate >= rate) { config = &provider->configs[i]; break; } } if (i == provider->num_configs) config = &provider->configs[i - 1]; old_idx = tegra210_clk_emc_get_parent(hw); new_idx = FIELD_GET(CLK_SOURCE_EMC_2X_CLK_SRC, config->value); old = clk_hw_get_parent_by_index(hw, old_idx); new = clk_hw_get_parent_by_index(hw, new_idx); /* if the rate has changed... */ if (config->parent_rate != clk_hw_get_rate(old)) { /* ... but the clock source remains the same ... */ if (new_idx == old_idx) { /* ... switch to the alternative clock source. */ switch (new_idx) { case CLK_SRC_PLLM: new_idx = CLK_SRC_PLLMB; break; case CLK_SRC_PLLM_UD: new_idx = CLK_SRC_PLLMB_UD; break; case CLK_SRC_PLLMB_UD: new_idx = CLK_SRC_PLLM_UD; break; case CLK_SRC_PLLMB: new_idx = CLK_SRC_PLLM; break; } /* * This should never happen because we can't deal with * it. */ if (WARN_ON(new_idx == old_idx)) return -EINVAL; new = clk_hw_get_parent_by_index(hw, new_idx); } index = new_idx; parent = new; } else { index = old_idx; parent = old; } clk = tegra210_clk_emc_find_parent(emc, index); if (IS_ERR(clk)) { err = PTR_ERR(clk); dev_err(dev, "failed to get parent clock for index %u: %d\n", index, err); return err; } /* set the new parent clock to the required rate */ if (clk_get_rate(clk) != config->parent_rate) { err = clk_set_rate(clk, config->parent_rate); if (err < 0) { dev_err(dev, "failed to set rate %lu Hz for %pC: %d\n", config->parent_rate, clk, err); return err; } } /* enable the new parent clock */ if (parent != old) { err = clk_prepare_enable(clk); if (err < 0) { dev_err(dev, "failed to enable parent clock %pC: %d\n", clk, err); return err; } } /* update the EMC source configuration to reflect the new parent */ config->value &= ~CLK_SOURCE_EMC_2X_CLK_SRC; config->value |= FIELD_PREP(CLK_SOURCE_EMC_2X_CLK_SRC, index); /* * Finally, switch the EMC programming with both old and new parent * clocks enabled. */ err = provider->set_rate(dev, config); if (err < 0) { dev_err(dev, "failed to set EMC rate to %lu Hz: %d\n", rate, err); /* * If we're unable to switch to the new EMC frequency, we no * longer need the new parent to be enabled. */ if (parent != old) clk_disable_unprepare(clk); return err; } /* reparent to new parent clock and disable the old parent clock */ if (parent != old) { clk = tegra210_clk_emc_find_parent(emc, old_idx); if (IS_ERR(clk)) { err = PTR_ERR(clk); dev_err(dev, "failed to get parent clock for index %u: %d\n", old_idx, err); return err; } clk_hw_reparent(hw, parent); clk_disable_unprepare(clk); } return err; } static const struct clk_ops tegra210_clk_emc_ops = { .get_parent = tegra210_clk_emc_get_parent, .recalc_rate = tegra210_clk_emc_recalc_rate, .round_rate = tegra210_clk_emc_round_rate, .set_rate = tegra210_clk_emc_set_rate, }; struct clk *tegra210_clk_register_emc(struct device_node *np, void __iomem *regs) { struct tegra210_clk_emc *emc; struct clk_init_data init; struct clk *clk; emc = kzalloc(sizeof(*emc), GFP_KERNEL); if (!emc) return ERR_PTR(-ENOMEM); emc->regs = regs; init.name = "emc"; init.ops = &tegra210_clk_emc_ops; init.flags = CLK_IS_CRITICAL | CLK_GET_RATE_NOCACHE; init.parent_names = tegra210_clk_emc_parents; init.num_parents = ARRAY_SIZE(tegra210_clk_emc_parents); emc->hw.init = &init; clk = clk_register(NULL, &emc->hw); if (IS_ERR(clk)) { kfree(emc); return clk; } return clk; } int tegra210_clk_emc_attach(struct clk *clk, struct tegra210_clk_emc_provider *provider) { struct clk_hw *hw = __clk_get_hw(clk); struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw); struct device *dev = provider->dev; unsigned int i; int err; if (!try_module_get(provider->owner)) return -ENODEV; for (i = 0; i < provider->num_configs; i++) { struct tegra210_clk_emc_config *config = &provider->configs[i]; struct clk_hw *parent; bool same_freq; u8 div, src; div = FIELD_GET(CLK_SOURCE_EMC_2X_CLK_DIVISOR, config->value); src = FIELD_GET(CLK_SOURCE_EMC_2X_CLK_SRC, config->value); /* do basic sanity checking on the EMC timings */ if (div & 0x1) { dev_err(dev, "invalid odd divider %u for rate %lu Hz\n", div, config->rate); err = -EINVAL; goto put; } same_freq = config->value & CLK_SOURCE_EMC_MC_EMC_SAME_FREQ; if (same_freq != config->same_freq) { dev_err(dev, "ambiguous EMC to MC ratio for rate %lu Hz\n", config->rate); err = -EINVAL; goto put; } parent = clk_hw_get_parent_by_index(hw, src); config->parent = src; if (src == CLK_SRC_PLLM || src == CLK_SRC_PLLM_UD) { config->parent_rate = config->rate * (1 + div / 2); } else { unsigned long rate = config->rate * (1 + div / 2); config->parent_rate = clk_hw_get_rate(parent); if (config->parent_rate != rate) { dev_err(dev, "rate %lu Hz does not match input\n", config->rate); err = -EINVAL; goto put; } } } emc->provider = provider; return 0; put: module_put(provider->owner); return err; } EXPORT_SYMBOL_GPL(tegra210_clk_emc_attach); void tegra210_clk_emc_detach(struct clk *clk) { struct tegra210_clk_emc *emc = to_tegra210_clk_emc(__clk_get_hw(clk)); module_put(emc->provider->owner); emc->provider = NULL; } EXPORT_SYMBOL_GPL(tegra210_clk_emc_detach);
linux-master
drivers/clk/tegra/clk-tegra210-emc.c
// SPDX-License-Identifier: GPL-2.0-only /* * Toshiba Visconti clock controller * * Copyright (c) 2021 TOSHIBA CORPORATION * Copyright (c) 2021 Toshiba Electronic Devices & Storage Corporation * * Nobuhiro Iwamatsu <[email protected]> */ #include <linux/clk-provider.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/string.h> #include "clkc.h" static inline struct visconti_clk_gate *to_visconti_clk_gate(struct clk_hw *hw) { return container_of(hw, struct visconti_clk_gate, hw); } static int visconti_gate_clk_is_enabled(struct clk_hw *hw) { struct visconti_clk_gate *gate = to_visconti_clk_gate(hw); u32 clk = BIT(gate->ck_idx); u32 val; regmap_read(gate->regmap, gate->ckon_offset, &val); return (val & clk) ? 1 : 0; } static void visconti_gate_clk_disable(struct clk_hw *hw) { struct visconti_clk_gate *gate = to_visconti_clk_gate(hw); u32 clk = BIT(gate->ck_idx); unsigned long flags; spin_lock_irqsave(gate->lock, flags); if (!visconti_gate_clk_is_enabled(hw)) { spin_unlock_irqrestore(gate->lock, flags); return; } regmap_update_bits(gate->regmap, gate->ckoff_offset, clk, clk); spin_unlock_irqrestore(gate->lock, flags); } static int visconti_gate_clk_enable(struct clk_hw *hw) { struct visconti_clk_gate *gate = to_visconti_clk_gate(hw); u32 clk = BIT(gate->ck_idx); unsigned long flags; spin_lock_irqsave(gate->lock, flags); regmap_update_bits(gate->regmap, gate->ckon_offset, clk, clk); spin_unlock_irqrestore(gate->lock, flags); return 0; } static const struct clk_ops visconti_clk_gate_ops = { .enable = visconti_gate_clk_enable, .disable = visconti_gate_clk_disable, .is_enabled = visconti_gate_clk_is_enabled, }; static struct clk_hw *visconti_clk_register_gate(struct device *dev, const char *name, const char *parent_name, struct regmap *regmap, const struct visconti_clk_gate_table *clks, u32 rson_offset, u32 rsoff_offset, u8 rs_idx, spinlock_t *lock) { struct visconti_clk_gate *gate; struct clk_parent_data *pdata; struct clk_init_data init; struct clk_hw *hw; int ret; pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return ERR_PTR(-ENOMEM); pdata->name = pdata->fw_name = parent_name; gate = devm_kzalloc(dev, sizeof(*gate), GFP_KERNEL); if (!gate) return ERR_PTR(-ENOMEM); init.name = name; init.ops = &visconti_clk_gate_ops; init.flags = clks->flags; init.parent_data = pdata; init.num_parents = 1; gate->regmap = regmap; gate->ckon_offset = clks->ckon_offset; gate->ckoff_offset = clks->ckoff_offset; gate->ck_idx = clks->ck_idx; gate->rson_offset = rson_offset; gate->rsoff_offset = rsoff_offset; gate->rs_idx = rs_idx; gate->lock = lock; gate->hw.init = &init; hw = &gate->hw; ret = devm_clk_hw_register(dev, hw); if (ret) hw = ERR_PTR(ret); return hw; } int visconti_clk_register_gates(struct visconti_clk_provider *ctx, const struct visconti_clk_gate_table *clks, int num_gate, const struct visconti_reset_data *reset, spinlock_t *lock) { struct device *dev = ctx->dev; int i; for (i = 0; i < num_gate; i++) { const char *parent_div_name = clks[i].parent_data[0].name; struct clk_parent_data *pdata; u32 rson_offset, rsoff_offset; struct clk_hw *gate_clk; struct clk_hw *div_clk; char *dev_name; u8 rs_idx; pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return -ENOMEM; dev_name = devm_kasprintf(dev, GFP_KERNEL, "%s_div", clks[i].name); if (!dev_name) return -ENOMEM; if (clks[i].rs_id != NO_RESET) { rson_offset = reset[clks[i].rs_id].rson_offset; rsoff_offset = reset[clks[i].rs_id].rsoff_offset; rs_idx = reset[clks[i].rs_id].rs_idx; } else { rson_offset = rsoff_offset = rs_idx = -1; } div_clk = devm_clk_hw_register_fixed_factor(dev, dev_name, parent_div_name, 0, 1, clks[i].div); if (IS_ERR(div_clk)) return PTR_ERR(div_clk); gate_clk = visconti_clk_register_gate(dev, clks[i].name, dev_name, ctx->regmap, &clks[i], rson_offset, rsoff_offset, rs_idx, lock); if (IS_ERR(gate_clk)) { dev_err(dev, "%s: failed to register clock %s\n", __func__, clks[i].name); return PTR_ERR(gate_clk); } ctx->clk_data.hws[clks[i].id] = gate_clk; } return 0; } struct visconti_clk_provider *visconti_init_clk(struct device *dev, struct regmap *regmap, unsigned long nr_clks) { struct visconti_clk_provider *ctx; int i; ctx = devm_kzalloc(dev, struct_size(ctx, clk_data.hws, nr_clks), GFP_KERNEL); if (!ctx) return ERR_PTR(-ENOMEM); for (i = 0; i < nr_clks; ++i) ctx->clk_data.hws[i] = ERR_PTR(-ENOENT); ctx->clk_data.num = nr_clks; ctx->dev = dev; ctx->regmap = regmap; return ctx; }
linux-master
drivers/clk/visconti/clkc.c
// SPDX-License-Identifier: GPL-2.0-only /* * Toshiba Visconti clock controller * * Copyright (c) 2021 TOSHIBA CORPORATION * Copyright (c) 2021 Toshiba Electronic Devices & Storage Corporation * * Nobuhiro Iwamatsu <[email protected]> */ #include <linux/clk-provider.h> #include <linux/platform_device.h> #include <dt-bindings/clock/toshiba,tmpv770x.h> #include <dt-bindings/reset/toshiba,tmpv770x.h> #include "clkc.h" #include "reset.h" static DEFINE_SPINLOCK(tmpv770x_clk_lock); static DEFINE_SPINLOCK(tmpv770x_rst_lock); static const struct clk_parent_data clks_parent_data[] = { { .fw_name = "pipll1", .name = "pipll1", }, }; static const struct clk_parent_data pietherplls_parent_data[] = { { .fw_name = "pietherpll", .name = "pietherpll", }, }; static const struct visconti_fixed_clk fixed_clk_tables[] = { /* PLL1 */ /* PICMPT0/1, PITSC, PIUWDT, PISWDT, PISBUS, PIPMU, PIGPMU, PITMU */ /* PIEMM, PIMISC, PIGCOMM, PIDCOMM, PIMBUS, PIGPIO, PIPGM */ { TMPV770X_CLK_PIPLL1_DIV4, "pipll1_div4", "pipll1", 0, 1, 4, }, /* PISBUS */ { TMPV770X_CLK_PIPLL1_DIV2, "pipll1_div2", "pipll1", 0, 1, 2, }, /* PICOBUS_CLK */ { TMPV770X_CLK_PIPLL1_DIV1, "pipll1_div1", "pipll1", 0, 1, 1, }, /* PIDNNPLL */ /* CONN_CLK, PIMBUS, PICRC0/1 */ { TMPV770X_CLK_PIDNNPLL_DIV1, "pidnnpll_div1", "pidnnpll", 0, 1, 1, }, { TMPV770X_CLK_PIREFCLK, "pirefclk", "osc2-clk", 0, 1, 1, }, { TMPV770X_CLK_WDTCLK, "wdtclk", "osc2-clk", 0, 1, 1, }, }; static const struct visconti_clk_gate_table pietherpll_clk_gate_tables[] = { /* pietherpll */ { TMPV770X_CLK_PIETHER_2P5M, "piether_2p5m", pietherplls_parent_data, ARRAY_SIZE(pietherplls_parent_data), CLK_SET_RATE_PARENT, 0x34, 0x134, 4, 200, TMPV770X_RESET_PIETHER_2P5M, }, { TMPV770X_CLK_PIETHER_25M, "piether_25m", pietherplls_parent_data, ARRAY_SIZE(pietherplls_parent_data), CLK_SET_RATE_PARENT, 0x34, 0x134, 5, 20, TMPV770X_RESET_PIETHER_25M, }, { TMPV770X_CLK_PIETHER_50M, "piether_50m", pietherplls_parent_data, ARRAY_SIZE(pietherplls_parent_data), CLK_SET_RATE_PARENT, 0x34, 0x134, 6, 10, TMPV770X_RESET_PIETHER_50M, }, { TMPV770X_CLK_PIETHER_125M, "piether_125m", pietherplls_parent_data, ARRAY_SIZE(pietherplls_parent_data), CLK_SET_RATE_PARENT, 0x34, 0x134, 7, 4, TMPV770X_RESET_PIETHER_125M, }, }; static const struct visconti_clk_gate_table clk_gate_tables[] = { { TMPV770X_CLK_HOX, "hox", clks_parent_data, ARRAY_SIZE(clks_parent_data), CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 0x4c, 0x14c, 0, 1, TMPV770X_RESET_HOX, }, { TMPV770X_CLK_PCIE_MSTR, "pcie_mstr", clks_parent_data, ARRAY_SIZE(clks_parent_data), CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 0x38, 0x138, 0, 1, TMPV770X_RESET_PCIE_MSTR, }, { TMPV770X_CLK_PCIE_AUX, "pcie_aux", clks_parent_data, ARRAY_SIZE(clks_parent_data), CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 0x38, 0x138, 1, 24, TMPV770X_RESET_PCIE_AUX, }, { TMPV770X_CLK_PIINTC, "piintc", clks_parent_data, ARRAY_SIZE(clks_parent_data), CLK_IGNORE_UNUSED, 0x8, 0x108, 0, 2, //FIX!! TMPV770X_RESET_PIINTC,}, { TMPV770X_CLK_PIETHER_BUS, "piether_bus", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x34, 0x134, 0, 2, TMPV770X_RESET_PIETHER_BUS, }, /* BUS_CLK */ { TMPV770X_CLK_PISPI0, "pispi0", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x28, 0x128, 0, 2, TMPV770X_RESET_PISPI0, }, { TMPV770X_CLK_PISPI1, "pispi1", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x28, 0x128, 1, 2, TMPV770X_RESET_PISPI1, }, { TMPV770X_CLK_PISPI2, "pispi2", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x28, 0x128, 2, 2, TMPV770X_RESET_PISPI2, }, { TMPV770X_CLK_PISPI3, "pispi3", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x28, 0x128, 3, 2, TMPV770X_RESET_PISPI3,}, { TMPV770X_CLK_PISPI4, "pispi4", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x28, 0x128, 4, 2, TMPV770X_RESET_PISPI4, }, { TMPV770X_CLK_PISPI5, "pispi5", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x28, 0x128, 5, 2, TMPV770X_RESET_PISPI5}, { TMPV770X_CLK_PISPI6, "pispi6", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x28, 0x128, 6, 2, TMPV770X_RESET_PISPI6,}, { TMPV770X_CLK_PIUART0, "piuart0", clks_parent_data, ARRAY_SIZE(clks_parent_data), //CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 0x2c, 0x12c, 0, 4, 0, 0x2c, 0x12c, 0, 4, TMPV770X_RESET_PIUART0,}, { TMPV770X_CLK_PIUART1, "piuart1", clks_parent_data, ARRAY_SIZE(clks_parent_data), //CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 0x2c, 0x12c, 1, 4, 0, 0x2c, 0x12c, 1, 4, TMPV770X_RESET_PIUART1, }, { TMPV770X_CLK_PIUART2, "piuart2", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x2c, 0x12c, 2, 4, TMPV770X_RESET_PIUART2, }, { TMPV770X_CLK_PIUART3, "piuart3", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x2c, 0x12c, 3, 4, TMPV770X_RESET_PIUART3, }, { TMPV770X_CLK_PII2C0, "pii2c0", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 0, 4, TMPV770X_RESET_PII2C0, }, { TMPV770X_CLK_PII2C1, "pii2c1", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 1, 4, TMPV770X_RESET_PII2C1, }, { TMPV770X_CLK_PII2C2, "pii2c2", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 2, 4, TMPV770X_RESET_PII2C2, }, { TMPV770X_CLK_PII2C3, "pii2c3", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 3, 4, TMPV770X_RESET_PII2C3,}, { TMPV770X_CLK_PII2C4, "pii2c4", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 4, 4, TMPV770X_RESET_PII2C4, }, { TMPV770X_CLK_PII2C5, "pii2c5", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 5, 4, TMPV770X_RESET_PII2C5, }, { TMPV770X_CLK_PII2C6, "pii2c6", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 6, 4, TMPV770X_RESET_PII2C6, }, { TMPV770X_CLK_PII2C7, "pii2c7", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 7, 4, TMPV770X_RESET_PII2C7, }, { TMPV770X_CLK_PII2C8, "pii2c8", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x30, 0x130, 8, 4, TMPV770X_RESET_PII2C8, }, /* PIPCMIF */ { TMPV770X_CLK_PIPCMIF, "pipcmif", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x64, 0x164, 0, 4, TMPV770X_RESET_PIPCMIF, }, /* PISYSTEM */ { TMPV770X_CLK_WRCK, "wrck", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x68, 0x168, 9, 32, NO_RESET, }, { TMPV770X_CLK_PICKMON, "pickmon", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x10, 0x110, 8, 4, TMPV770X_RESET_PICKMON, }, { TMPV770X_CLK_SBUSCLK, "sbusclk", clks_parent_data, ARRAY_SIZE(clks_parent_data), 0, 0x14, 0x114, 0, 4, TMPV770X_RESET_SBUSCLK, }, }; static const struct visconti_reset_data clk_reset_data[] = { [TMPV770X_RESET_PIETHER_2P5M] = { 0x434, 0x534, 4, }, [TMPV770X_RESET_PIETHER_25M] = { 0x434, 0x534, 5, }, [TMPV770X_RESET_PIETHER_50M] = { 0x434, 0x534, 6, }, [TMPV770X_RESET_PIETHER_125M] = { 0x434, 0x534, 7, }, [TMPV770X_RESET_HOX] = { 0x44c, 0x54c, 0, }, [TMPV770X_RESET_PCIE_MSTR] = { 0x438, 0x538, 0, }, [TMPV770X_RESET_PCIE_AUX] = { 0x438, 0x538, 1, }, [TMPV770X_RESET_PIINTC] = { 0x408, 0x508, 0, }, [TMPV770X_RESET_PIETHER_BUS] = { 0x434, 0x534, 0, }, [TMPV770X_RESET_PISPI0] = { 0x428, 0x528, 0, }, [TMPV770X_RESET_PISPI1] = { 0x428, 0x528, 1, }, [TMPV770X_RESET_PISPI2] = { 0x428, 0x528, 2, }, [TMPV770X_RESET_PISPI3] = { 0x428, 0x528, 3, }, [TMPV770X_RESET_PISPI4] = { 0x428, 0x528, 4, }, [TMPV770X_RESET_PISPI5] = { 0x428, 0x528, 5, }, [TMPV770X_RESET_PISPI6] = { 0x428, 0x528, 6, }, [TMPV770X_RESET_PIUART0] = { 0x42c, 0x52c, 0, }, [TMPV770X_RESET_PIUART1] = { 0x42c, 0x52c, 1, }, [TMPV770X_RESET_PIUART2] = { 0x42c, 0x52c, 2, }, [TMPV770X_RESET_PIUART3] = { 0x42c, 0x52c, 3, }, [TMPV770X_RESET_PII2C0] = { 0x430, 0x530, 0, }, [TMPV770X_RESET_PII2C1] = { 0x430, 0x530, 1, }, [TMPV770X_RESET_PII2C2] = { 0x430, 0x530, 2, }, [TMPV770X_RESET_PII2C3] = { 0x430, 0x530, 3, }, [TMPV770X_RESET_PII2C4] = { 0x430, 0x530, 4, }, [TMPV770X_RESET_PII2C5] = { 0x430, 0x530, 5, }, [TMPV770X_RESET_PII2C6] = { 0x430, 0x530, 6, }, [TMPV770X_RESET_PII2C7] = { 0x430, 0x530, 7, }, [TMPV770X_RESET_PII2C8] = { 0x430, 0x530, 8, }, [TMPV770X_RESET_PIPCMIF] = { 0x464, 0x564, 0, }, [TMPV770X_RESET_PICKMON] = { 0x410, 0x510, 8, }, [TMPV770X_RESET_SBUSCLK] = { 0x414, 0x514, 0, }, }; static int visconti_clk_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct visconti_clk_provider *ctx; struct device *dev = &pdev->dev; struct regmap *regmap; int ret, i; regmap = syscon_node_to_regmap(np); if (IS_ERR(regmap)) return PTR_ERR(regmap); ctx = visconti_init_clk(dev, regmap, TMPV770X_NR_CLK); if (IS_ERR(ctx)) return PTR_ERR(ctx); ret = visconti_register_reset_controller(dev, regmap, clk_reset_data, TMPV770X_NR_RESET, &visconti_reset_ops, &tmpv770x_rst_lock); if (ret) { dev_err(dev, "Failed to register reset controller: %d\n", ret); return ret; } for (i = 0; i < (ARRAY_SIZE(fixed_clk_tables)); i++) ctx->clk_data.hws[fixed_clk_tables[i].id] = clk_hw_register_fixed_factor(NULL, fixed_clk_tables[i].name, fixed_clk_tables[i].parent, fixed_clk_tables[i].flag, fixed_clk_tables[i].mult, fixed_clk_tables[i].div); ret = visconti_clk_register_gates(ctx, clk_gate_tables, ARRAY_SIZE(clk_gate_tables), clk_reset_data, &tmpv770x_clk_lock); if (ret) { dev_err(dev, "Failed to register main clock gate: %d\n", ret); return ret; } ret = visconti_clk_register_gates(ctx, pietherpll_clk_gate_tables, ARRAY_SIZE(pietherpll_clk_gate_tables), clk_reset_data, &tmpv770x_clk_lock); if (ret) { dev_err(dev, "Failed to register pietherpll clock gate: %d\n", ret); return ret; } return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, &ctx->clk_data); } static const struct of_device_id visconti_clk_ids[] = { { .compatible = "toshiba,tmpv7708-pismu", }, { } }; static struct platform_driver visconti_clk_driver = { .probe = visconti_clk_probe, .driver = { .name = "visconti-clk", .of_match_table = visconti_clk_ids, }, }; builtin_platform_driver(visconti_clk_driver);
linux-master
drivers/clk/visconti/clkc-tmpv770x.c
// SPDX-License-Identifier: GPL-2.0-only /* * Toshiba Visconti ARM SoC reset controller * * Copyright (c) 2021 TOSHIBA CORPORATION * Copyright (c) 2021 Toshiba Electronic Devices & Storage Corporation * * Nobuhiro Iwamatsu <[email protected]> */ #include <linux/delay.h> #include <linux/device.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> #include <linux/slab.h> #include "reset.h" static inline struct visconti_reset *to_visconti_reset(struct reset_controller_dev *rcdev) { return container_of(rcdev, struct visconti_reset, rcdev); } static int visconti_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) { struct visconti_reset *reset = to_visconti_reset(rcdev); const struct visconti_reset_data *data = &reset->resets[id]; u32 rst = BIT(data->rs_idx); unsigned long flags; int ret; spin_lock_irqsave(reset->lock, flags); ret = regmap_update_bits(reset->regmap, data->rson_offset, rst, rst); spin_unlock_irqrestore(reset->lock, flags); return ret; } static int visconti_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) { struct visconti_reset *reset = to_visconti_reset(rcdev); const struct visconti_reset_data *data = &reset->resets[id]; u32 rst = BIT(data->rs_idx); unsigned long flags; int ret; spin_lock_irqsave(reset->lock, flags); ret = regmap_update_bits(reset->regmap, data->rsoff_offset, rst, rst); spin_unlock_irqrestore(reset->lock, flags); return ret; } static int visconti_reset_reset(struct reset_controller_dev *rcdev, unsigned long id) { visconti_reset_assert(rcdev, id); udelay(1); visconti_reset_deassert(rcdev, id); return 0; } static int visconti_reset_status(struct reset_controller_dev *rcdev, unsigned long id) { struct visconti_reset *reset = to_visconti_reset(rcdev); const struct visconti_reset_data *data = &reset->resets[id]; unsigned long flags; u32 reg; int ret; spin_lock_irqsave(reset->lock, flags); ret = regmap_read(reset->regmap, data->rson_offset, &reg); spin_unlock_irqrestore(reset->lock, flags); if (ret) return ret; return !(reg & data->rs_idx); } const struct reset_control_ops visconti_reset_ops = { .assert = visconti_reset_assert, .deassert = visconti_reset_deassert, .reset = visconti_reset_reset, .status = visconti_reset_status, }; int visconti_register_reset_controller(struct device *dev, struct regmap *regmap, const struct visconti_reset_data *resets, unsigned int num_resets, const struct reset_control_ops *reset_ops, spinlock_t *lock) { struct visconti_reset *reset; reset = devm_kzalloc(dev, sizeof(*reset), GFP_KERNEL); if (!reset) return -ENOMEM; reset->regmap = regmap; reset->resets = resets; reset->rcdev.ops = reset_ops; reset->rcdev.nr_resets = num_resets; reset->rcdev.of_node = dev->of_node; reset->lock = lock; return devm_reset_controller_register(dev, &reset->rcdev); }
linux-master
drivers/clk/visconti/reset.c
// SPDX-License-Identifier: GPL-2.0-only /* * Toshiba Visconti PLL controller * * Copyright (c) 2021 TOSHIBA CORPORATION * Copyright (c) 2021 Toshiba Electronic Devices & Storage Corporation * * Nobuhiro Iwamatsu <[email protected]> */ #include <linux/clk-provider.h> #include <linux/of_address.h> #include <linux/slab.h> #include <dt-bindings/clock/toshiba,tmpv770x.h> #include "pll.h" static DEFINE_SPINLOCK(tmpv770x_pll_lock); static const struct visconti_pll_rate_table pipll0_rates[] __initconst = { VISCONTI_PLL_RATE(840000000, 0x1, 0x0, 0x1, 0x54, 0x000000, 0x2, 0x1), VISCONTI_PLL_RATE(780000000, 0x1, 0x0, 0x1, 0x4e, 0x000000, 0x2, 0x1), VISCONTI_PLL_RATE(600000000, 0x1, 0x0, 0x1, 0x3c, 0x000000, 0x2, 0x1), { /* sentinel */ }, }; static const struct visconti_pll_rate_table piddrcpll_rates[] __initconst = { VISCONTI_PLL_RATE(780000000, 0x1, 0x0, 0x1, 0x4e, 0x000000, 0x2, 0x1), VISCONTI_PLL_RATE(760000000, 0x1, 0x0, 0x1, 0x4c, 0x000000, 0x2, 0x1), { /* sentinel */ }, }; static const struct visconti_pll_rate_table pivoifpll_rates[] __initconst = { VISCONTI_PLL_RATE(165000000, 0x1, 0x0, 0x1, 0x42, 0x000000, 0x4, 0x2), VISCONTI_PLL_RATE(148500000, 0x1, 0x1, 0x1, 0x3b, 0x666666, 0x4, 0x2), VISCONTI_PLL_RATE(96000000, 0x1, 0x0, 0x1, 0x30, 0x000000, 0x5, 0x2), VISCONTI_PLL_RATE(74250000, 0x1, 0x1, 0x1, 0x3b, 0x666666, 0x4, 0x4), VISCONTI_PLL_RATE(54000000, 0x1, 0x0, 0x1, 0x36, 0x000000, 0x5, 0x4), VISCONTI_PLL_RATE(48000000, 0x1, 0x0, 0x1, 0x30, 0x000000, 0x5, 0x4), VISCONTI_PLL_RATE(35750000, 0x1, 0x1, 0x1, 0x32, 0x0ccccc, 0x7, 0x4), { /* sentinel */ }, }; static const struct visconti_pll_rate_table piimgerpll_rates[] __initconst = { VISCONTI_PLL_RATE(165000000, 0x1, 0x0, 0x1, 0x42, 0x000000, 0x4, 0x2), VISCONTI_PLL_RATE(96000000, 0x1, 0x0, 0x1, 0x30, 0x000000, 0x5, 0x2), VISCONTI_PLL_RATE(54000000, 0x1, 0x0, 0x1, 0x36, 0x000000, 0x5, 0x4), VISCONTI_PLL_RATE(48000000, 0x1, 0x0, 0x1, 0x30, 0x000000, 0x5, 0x4), { /* sentinel */ }, }; static const struct visconti_pll_info pll_info[] __initconst = { { TMPV770X_PLL_PIPLL0, "pipll0", "osc2-clk", 0x0, pipll0_rates }, { TMPV770X_PLL_PIDDRCPLL, "piddrcpll", "osc2-clk", 0x500, piddrcpll_rates }, { TMPV770X_PLL_PIVOIFPLL, "pivoifpll", "osc2-clk", 0x600, pivoifpll_rates }, { TMPV770X_PLL_PIIMGERPLL, "piimgerpll", "osc2-clk", 0x700, piimgerpll_rates }, }; static void __init tmpv770x_setup_plls(struct device_node *np) { struct visconti_pll_provider *ctx; void __iomem *reg_base; reg_base = of_iomap(np, 0); if (!reg_base) return; ctx = visconti_init_pll(np, reg_base, TMPV770X_NR_PLL); if (IS_ERR(ctx)) { iounmap(reg_base); return; } ctx->clk_data.hws[TMPV770X_PLL_PIPLL1] = clk_hw_register_fixed_rate(NULL, "pipll1", NULL, 0, 600000000); ctx->clk_data.hws[TMPV770X_PLL_PIDNNPLL] = clk_hw_register_fixed_rate(NULL, "pidnnpll", NULL, 0, 500000000); ctx->clk_data.hws[TMPV770X_PLL_PIETHERPLL] = clk_hw_register_fixed_rate(NULL, "pietherpll", NULL, 0, 500000000); visconti_register_plls(ctx, pll_info, ARRAY_SIZE(pll_info), &tmpv770x_pll_lock); } CLK_OF_DECLARE(tmpv770x_plls, "toshiba,tmpv7708-pipllct", tmpv770x_setup_plls);
linux-master
drivers/clk/visconti/pll-tmpv770x.c
// SPDX-License-Identifier: GPL-2.0-only /* * Toshiba Visconti PLL driver * * Copyright (c) 2021 TOSHIBA CORPORATION * Copyright (c) 2021 Toshiba Electronic Devices & Storage Corporation * * Nobuhiro Iwamatsu <[email protected]> */ #include <linux/bitfield.h> #include <linux/clk-provider.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/io.h> #include "pll.h" struct visconti_pll { struct clk_hw hw; void __iomem *pll_base; spinlock_t *lock; unsigned long flags; const struct visconti_pll_rate_table *rate_table; size_t rate_count; struct visconti_pll_provider *ctx; }; #define PLL_CONF_REG 0x0000 #define PLL_CTRL_REG 0x0004 #define PLL_FRACMODE_REG 0x0010 #define PLL_INTIN_REG 0x0014 #define PLL_FRACIN_REG 0x0018 #define PLL_REFDIV_REG 0x001c #define PLL_POSTDIV_REG 0x0020 #define PLL_CONFIG_SEL BIT(0) #define PLL_PLLEN BIT(4) #define PLL_BYPASS BIT(16) #define PLL_INTIN_MASK GENMASK(11, 0) #define PLL_FRACIN_MASK GENMASK(23, 0) #define PLL_REFDIV_MASK GENMASK(5, 0) #define PLL_POSTDIV_MASK GENMASK(2, 0) #define PLL0_FRACMODE_DACEN BIT(4) #define PLL0_FRACMODE_DSMEN BIT(0) #define PLL_CREATE_FRACMODE(table) (table->dacen << 4 | table->dsmen) #define PLL_CREATE_OSTDIV(table) (table->postdiv2 << 4 | table->postdiv1) static inline struct visconti_pll *to_visconti_pll(struct clk_hw *hw) { return container_of(hw, struct visconti_pll, hw); } static void visconti_pll_get_params(struct visconti_pll *pll, struct visconti_pll_rate_table *rate_table) { u32 postdiv, val; val = readl(pll->pll_base + PLL_FRACMODE_REG); rate_table->dacen = FIELD_GET(PLL0_FRACMODE_DACEN, val); rate_table->dsmen = FIELD_GET(PLL0_FRACMODE_DSMEN, val); rate_table->fracin = readl(pll->pll_base + PLL_FRACIN_REG) & PLL_FRACIN_MASK; rate_table->intin = readl(pll->pll_base + PLL_INTIN_REG) & PLL_INTIN_MASK; rate_table->refdiv = readl(pll->pll_base + PLL_REFDIV_REG) & PLL_REFDIV_MASK; postdiv = readl(pll->pll_base + PLL_POSTDIV_REG); rate_table->postdiv1 = postdiv & PLL_POSTDIV_MASK; rate_table->postdiv2 = (postdiv >> 4) & PLL_POSTDIV_MASK; } static const struct visconti_pll_rate_table *visconti_get_pll_settings(struct visconti_pll *pll, unsigned long rate) { const struct visconti_pll_rate_table *rate_table = pll->rate_table; int i; for (i = 0; i < pll->rate_count; i++) if (rate == rate_table[i].rate) return &rate_table[i]; return NULL; } static unsigned long visconti_get_pll_rate_from_data(struct visconti_pll *pll, const struct visconti_pll_rate_table *rate) { const struct visconti_pll_rate_table *rate_table = pll->rate_table; int i; for (i = 0; i < pll->rate_count; i++) if (memcmp(&rate_table[i].dacen, &rate->dacen, sizeof(*rate) - sizeof(unsigned long)) == 0) return rate_table[i].rate; /* set default */ return rate_table[0].rate; } static long visconti_pll_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct visconti_pll *pll = to_visconti_pll(hw); const struct visconti_pll_rate_table *rate_table = pll->rate_table; int i; /* Assumming rate_table is in descending order */ for (i = 0; i < pll->rate_count; i++) if (rate >= rate_table[i].rate) return rate_table[i].rate; /* return minimum supported value */ return rate_table[i - 1].rate; } static unsigned long visconti_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct visconti_pll *pll = to_visconti_pll(hw); struct visconti_pll_rate_table rate_table; memset(&rate_table, 0, sizeof(rate_table)); visconti_pll_get_params(pll, &rate_table); return visconti_get_pll_rate_from_data(pll, &rate_table); } static int visconti_pll_set_params(struct visconti_pll *pll, const struct visconti_pll_rate_table *rate_table) { writel(PLL_CREATE_FRACMODE(rate_table), pll->pll_base + PLL_FRACMODE_REG); writel(PLL_CREATE_OSTDIV(rate_table), pll->pll_base + PLL_POSTDIV_REG); writel(rate_table->intin, pll->pll_base + PLL_INTIN_REG); writel(rate_table->fracin, pll->pll_base + PLL_FRACIN_REG); writel(rate_table->refdiv, pll->pll_base + PLL_REFDIV_REG); return 0; } static int visconti_pll_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct visconti_pll *pll = to_visconti_pll(hw); const struct visconti_pll_rate_table *rate_table; rate_table = visconti_get_pll_settings(pll, rate); if (!rate_table) return -EINVAL; return visconti_pll_set_params(pll, rate_table); } static int visconti_pll_is_enabled(struct clk_hw *hw) { struct visconti_pll *pll = to_visconti_pll(hw); u32 reg; reg = readl(pll->pll_base + PLL_CTRL_REG); return (reg & PLL_PLLEN); } static int visconti_pll_enable(struct clk_hw *hw) { struct visconti_pll *pll = to_visconti_pll(hw); const struct visconti_pll_rate_table *rate_table = pll->rate_table; unsigned long flags; u32 reg; if (visconti_pll_is_enabled(hw)) return 0; spin_lock_irqsave(pll->lock, flags); writel(PLL_CONFIG_SEL, pll->pll_base + PLL_CONF_REG); reg = readl(pll->pll_base + PLL_CTRL_REG); reg |= PLL_BYPASS; writel(reg, pll->pll_base + PLL_CTRL_REG); visconti_pll_set_params(pll, &rate_table[0]); reg = readl(pll->pll_base + PLL_CTRL_REG); reg &= ~PLL_PLLEN; writel(reg, pll->pll_base + PLL_CTRL_REG); udelay(1); reg = readl(pll->pll_base + PLL_CTRL_REG); reg |= PLL_PLLEN; writel(reg, pll->pll_base + PLL_CTRL_REG); udelay(40); reg = readl(pll->pll_base + PLL_CTRL_REG); reg &= ~PLL_BYPASS; writel(reg, pll->pll_base + PLL_CTRL_REG); spin_unlock_irqrestore(pll->lock, flags); return 0; } static void visconti_pll_disable(struct clk_hw *hw) { struct visconti_pll *pll = to_visconti_pll(hw); unsigned long flags; u32 reg; if (!visconti_pll_is_enabled(hw)) return; spin_lock_irqsave(pll->lock, flags); writel(PLL_CONFIG_SEL, pll->pll_base + PLL_CONF_REG); reg = readl(pll->pll_base + PLL_CTRL_REG); reg |= PLL_BYPASS; writel(reg, pll->pll_base + PLL_CTRL_REG); reg = readl(pll->pll_base + PLL_CTRL_REG); reg &= ~PLL_PLLEN; writel(reg, pll->pll_base + PLL_CTRL_REG); spin_unlock_irqrestore(pll->lock, flags); } static const struct clk_ops visconti_pll_ops = { .enable = visconti_pll_enable, .disable = visconti_pll_disable, .is_enabled = visconti_pll_is_enabled, .round_rate = visconti_pll_round_rate, .recalc_rate = visconti_pll_recalc_rate, .set_rate = visconti_pll_set_rate, }; static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx, const char *name, const char *parent_name, int offset, const struct visconti_pll_rate_table *rate_table, spinlock_t *lock) { struct clk_init_data init; struct visconti_pll *pll; struct clk_hw *pll_hw_clk; size_t len; int ret; pll = kzalloc(sizeof(*pll), GFP_KERNEL); if (!pll) return ERR_PTR(-ENOMEM); init.name = name; init.flags = CLK_IGNORE_UNUSED; init.parent_names = &parent_name; init.num_parents = 1; for (len = 0; rate_table[len].rate != 0; ) len++; pll->rate_count = len; pll->rate_table = kmemdup(rate_table, pll->rate_count * sizeof(struct visconti_pll_rate_table), GFP_KERNEL); WARN(!pll->rate_table, "%s: could not allocate rate table for %s\n", __func__, name); init.ops = &visconti_pll_ops; pll->hw.init = &init; pll->pll_base = ctx->reg_base + offset; pll->lock = lock; pll->ctx = ctx; pll_hw_clk = &pll->hw; ret = clk_hw_register(NULL, &pll->hw); if (ret) { pr_err("failed to register pll clock %s : %d\n", name, ret); kfree(pll->rate_table); kfree(pll); pll_hw_clk = ERR_PTR(ret); } return pll_hw_clk; } static void visconti_pll_add_lookup(struct visconti_pll_provider *ctx, struct clk_hw *hw_clk, unsigned int id) { if (id) ctx->clk_data.hws[id] = hw_clk; } void __init visconti_register_plls(struct visconti_pll_provider *ctx, const struct visconti_pll_info *list, unsigned int nr_plls, spinlock_t *lock) { int idx; for (idx = 0; idx < nr_plls; idx++, list++) { struct clk_hw *clk; clk = visconti_register_pll(ctx, list->name, list->parent, list->base_reg, list->rate_table, lock); if (IS_ERR(clk)) { pr_err("failed to register clock %s\n", list->name); continue; } visconti_pll_add_lookup(ctx, clk, list->id); } } struct visconti_pll_provider * __init visconti_init_pll(struct device_node *np, void __iomem *base, unsigned long nr_plls) { struct visconti_pll_provider *ctx; int i; ctx = kzalloc(struct_size(ctx, clk_data.hws, nr_plls), GFP_KERNEL); if (!ctx) return ERR_PTR(-ENOMEM); for (i = 0; i < nr_plls; ++i) ctx->clk_data.hws[i] = ERR_PTR(-ENOENT); ctx->node = np; ctx->reg_base = base; ctx->clk_data.num = nr_plls; return ctx; }
linux-master
drivers/clk/visconti/pll.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * clkgen-mux.c: ST GEN-MUX Clock driver * * Copyright (C) 2014 STMicroelectronics (R&D) Limited * * Authors: Stephen Gallimore <[email protected]> * Pankaj Dev <[email protected]> */ #include <linux/slab.h> #include <linux/io.h> #include <linux/of_address.h> #include <linux/clk.h> #include <linux/clk-provider.h> #include "clkgen.h" static const char ** __init clkgen_mux_get_parents(struct device_node *np, int *num_parents) { const char **parents; unsigned int nparents; nparents = of_clk_get_parent_count(np); if (WARN_ON(!nparents)) return ERR_PTR(-EINVAL); parents = kcalloc(nparents, sizeof(const char *), GFP_KERNEL); if (!parents) return ERR_PTR(-ENOMEM); *num_parents = of_clk_parent_fill(np, parents, nparents); return parents; } struct clkgen_mux_data { u32 offset; u8 shift; u8 width; spinlock_t *lock; unsigned long clk_flags; u8 mux_flags; }; static struct clkgen_mux_data stih407_a9_mux_data = { .offset = 0x1a4, .shift = 0, .width = 2, .lock = &clkgen_a9_lock, }; static void __init st_of_clkgen_mux_setup(struct device_node *np, struct clkgen_mux_data *data) { struct clk *clk; void __iomem *reg; const char **parents; int num_parents = 0; struct device_node *parent_np; /* * First check for reg property within the node to keep backward * compatibility, then if reg doesn't exist look at the parent node */ reg = of_iomap(np, 0); if (!reg) { parent_np = of_get_parent(np); reg = of_iomap(parent_np, 0); of_node_put(parent_np); if (!reg) { pr_err("%s: Failed to get base address\n", __func__); return; } } parents = clkgen_mux_get_parents(np, &num_parents); if (IS_ERR(parents)) { pr_err("%s: Failed to get parents (%ld)\n", __func__, PTR_ERR(parents)); goto err_parents; } clk = clk_register_mux(NULL, np->name, parents, num_parents, data->clk_flags | CLK_SET_RATE_PARENT, reg + data->offset, data->shift, data->width, data->mux_flags, data->lock); if (IS_ERR(clk)) goto err; pr_debug("%s: parent %s rate %u\n", __clk_get_name(clk), __clk_get_name(clk_get_parent(clk)), (unsigned int)clk_get_rate(clk)); kfree(parents); of_clk_add_provider(np, of_clk_src_simple_get, clk); return; err: kfree(parents); err_parents: iounmap(reg); } static void __init st_of_clkgen_a9_mux_setup(struct device_node *np) { st_of_clkgen_mux_setup(np, &stih407_a9_mux_data); } CLK_OF_DECLARE(clkgen_a9mux, "st,stih407-clkgen-a9-mux", st_of_clkgen_a9_mux_setup);
linux-master
drivers/clk/st/clkgen-mux.c
// SPDX-License-Identifier: GPL-2.0-only /* * clk-flexgen.c * * Copyright (C) ST-Microelectronics SA 2013 * Author: Maxime Coquelin <[email protected]> for ST-Microelectronics. */ #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/io.h> #include <linux/err.h> #include <linux/string.h> #include <linux/of.h> #include <linux/of_address.h> struct clkgen_clk_out { const char *name; unsigned long flags; }; struct clkgen_data { unsigned long flags; bool mode; const struct clkgen_clk_out *outputs; const unsigned int outputs_nb; }; struct flexgen { struct clk_hw hw; /* Crossbar */ struct clk_mux mux; /* Pre-divisor's gate */ struct clk_gate pgate; /* Pre-divisor */ struct clk_divider pdiv; /* Final divisor's gate */ struct clk_gate fgate; /* Final divisor */ struct clk_divider fdiv; /* Asynchronous mode control */ struct clk_gate sync; /* hw control flags */ bool control_mode; }; #define to_flexgen(_hw) container_of(_hw, struct flexgen, hw) #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw) static int flexgen_enable(struct clk_hw *hw) { struct flexgen *flexgen = to_flexgen(hw); struct clk_hw *pgate_hw = &flexgen->pgate.hw; struct clk_hw *fgate_hw = &flexgen->fgate.hw; __clk_hw_set_clk(pgate_hw, hw); __clk_hw_set_clk(fgate_hw, hw); clk_gate_ops.enable(pgate_hw); clk_gate_ops.enable(fgate_hw); pr_debug("%s: flexgen output enabled\n", clk_hw_get_name(hw)); return 0; } static void flexgen_disable(struct clk_hw *hw) { struct flexgen *flexgen = to_flexgen(hw); struct clk_hw *fgate_hw = &flexgen->fgate.hw; /* disable only the final gate */ __clk_hw_set_clk(fgate_hw, hw); clk_gate_ops.disable(fgate_hw); pr_debug("%s: flexgen output disabled\n", clk_hw_get_name(hw)); } static int flexgen_is_enabled(struct clk_hw *hw) { struct flexgen *flexgen = to_flexgen(hw); struct clk_hw *fgate_hw = &flexgen->fgate.hw; __clk_hw_set_clk(fgate_hw, hw); if (!clk_gate_ops.is_enabled(fgate_hw)) return 0; return 1; } static u8 flexgen_get_parent(struct clk_hw *hw) { struct flexgen *flexgen = to_flexgen(hw); struct clk_hw *mux_hw = &flexgen->mux.hw; __clk_hw_set_clk(mux_hw, hw); return clk_mux_ops.get_parent(mux_hw); } static int flexgen_set_parent(struct clk_hw *hw, u8 index) { struct flexgen *flexgen = to_flexgen(hw); struct clk_hw *mux_hw = &flexgen->mux.hw; __clk_hw_set_clk(mux_hw, hw); return clk_mux_ops.set_parent(mux_hw, index); } static inline unsigned long clk_best_div(unsigned long parent_rate, unsigned long rate) { return parent_rate / rate + ((rate > (2*(parent_rate % rate))) ? 0 : 1); } static int flexgen_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { unsigned long div; /* Round div according to exact prate and wished rate */ div = clk_best_div(req->best_parent_rate, req->rate); if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { req->best_parent_rate = req->rate * div; return 0; } req->rate = req->best_parent_rate / div; return 0; } static unsigned long flexgen_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct flexgen *flexgen = to_flexgen(hw); struct clk_hw *pdiv_hw = &flexgen->pdiv.hw; struct clk_hw *fdiv_hw = &flexgen->fdiv.hw; unsigned long mid_rate; __clk_hw_set_clk(pdiv_hw, hw); __clk_hw_set_clk(fdiv_hw, hw); mid_rate = clk_divider_ops.recalc_rate(pdiv_hw, parent_rate); return clk_divider_ops.recalc_rate(fdiv_hw, mid_rate); } static int flexgen_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct flexgen *flexgen = to_flexgen(hw); struct clk_hw *pdiv_hw = &flexgen->pdiv.hw; struct clk_hw *fdiv_hw = &flexgen->fdiv.hw; struct clk_hw *sync_hw = &flexgen->sync.hw; struct clk_gate *config = to_clk_gate(sync_hw); unsigned long div = 0; int ret = 0; u32 reg; __clk_hw_set_clk(pdiv_hw, hw); __clk_hw_set_clk(fdiv_hw, hw); if (flexgen->control_mode) { reg = readl(config->reg); reg &= ~BIT(config->bit_idx); writel(reg, config->reg); } div = clk_best_div(parent_rate, rate); /* * pdiv is mainly targeted for low freq results, while fdiv * should be used for div <= 64. The other way round can * lead to 'duty cycle' issues. */ if (div <= 64) { clk_divider_ops.set_rate(pdiv_hw, parent_rate, parent_rate); ret = clk_divider_ops.set_rate(fdiv_hw, rate, rate * div); } else { clk_divider_ops.set_rate(fdiv_hw, parent_rate, parent_rate); ret = clk_divider_ops.set_rate(pdiv_hw, rate, rate * div); } return ret; } static const struct clk_ops flexgen_ops = { .enable = flexgen_enable, .disable = flexgen_disable, .is_enabled = flexgen_is_enabled, .get_parent = flexgen_get_parent, .set_parent = flexgen_set_parent, .determine_rate = flexgen_determine_rate, .recalc_rate = flexgen_recalc_rate, .set_rate = flexgen_set_rate, }; static struct clk *clk_register_flexgen(const char *name, const char **parent_names, u8 num_parents, void __iomem *reg, spinlock_t *lock, u32 idx, unsigned long flexgen_flags, bool mode) { struct flexgen *fgxbar; struct clk *clk; struct clk_init_data init; u32 xbar_shift; void __iomem *xbar_reg, *fdiv_reg; fgxbar = kzalloc(sizeof(struct flexgen), GFP_KERNEL); if (!fgxbar) return ERR_PTR(-ENOMEM); init.name = name; init.ops = &flexgen_ops; init.flags = CLK_GET_RATE_NOCACHE | flexgen_flags; init.parent_names = parent_names; init.num_parents = num_parents; xbar_reg = reg + 0x18 + (idx & ~0x3); xbar_shift = (idx % 4) * 0x8; fdiv_reg = reg + 0x164 + idx * 4; /* Crossbar element config */ fgxbar->mux.lock = lock; fgxbar->mux.mask = BIT(6) - 1; fgxbar->mux.reg = xbar_reg; fgxbar->mux.shift = xbar_shift; fgxbar->mux.table = NULL; /* Pre-divider's gate config (in xbar register)*/ fgxbar->pgate.lock = lock; fgxbar->pgate.reg = xbar_reg; fgxbar->pgate.bit_idx = xbar_shift + 6; /* Pre-divider config */ fgxbar->pdiv.lock = lock; fgxbar->pdiv.reg = reg + 0x58 + idx * 4; fgxbar->pdiv.width = 10; /* Final divider's gate config */ fgxbar->fgate.lock = lock; fgxbar->fgate.reg = fdiv_reg; fgxbar->fgate.bit_idx = 6; /* Final divider config */ fgxbar->fdiv.lock = lock; fgxbar->fdiv.reg = fdiv_reg; fgxbar->fdiv.width = 6; /* Final divider sync config */ fgxbar->sync.lock = lock; fgxbar->sync.reg = fdiv_reg; fgxbar->sync.bit_idx = 7; fgxbar->control_mode = mode; fgxbar->hw.init = &init; clk = clk_register(NULL, &fgxbar->hw); if (IS_ERR(clk)) kfree(fgxbar); else pr_debug("%s: parent %s rate %u\n", __clk_get_name(clk), __clk_get_name(clk_get_parent(clk)), (unsigned int)clk_get_rate(clk)); return clk; } static const char ** __init flexgen_get_parents(struct device_node *np, int *num_parents) { const char **parents; unsigned int nparents; nparents = of_clk_get_parent_count(np); if (WARN_ON(!nparents)) return NULL; parents = kcalloc(nparents, sizeof(const char *), GFP_KERNEL); if (!parents) return NULL; *num_parents = of_clk_parent_fill(np, parents, nparents); return parents; } static const struct clkgen_data clkgen_audio = { .flags = CLK_SET_RATE_PARENT, }; static const struct clkgen_data clkgen_video = { .flags = CLK_SET_RATE_PARENT, .mode = 1, }; static const struct clkgen_clk_out clkgen_stih407_a0_clk_out[] = { /* This clk needs to be on so that memory interface is accessible */ { .name = "clk-ic-lmi0", .flags = CLK_IS_CRITICAL }, }; static const struct clkgen_data clkgen_stih407_a0 = { .outputs = clkgen_stih407_a0_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih407_a0_clk_out), }; static const struct clkgen_clk_out clkgen_stih410_a0_clk_out[] = { /* Those clks need to be on so that memory interface is accessible */ { .name = "clk-ic-lmi0", .flags = CLK_IS_CRITICAL }, { .name = "clk-ic-lmi1", .flags = CLK_IS_CRITICAL }, }; static const struct clkgen_data clkgen_stih410_a0 = { .outputs = clkgen_stih410_a0_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih410_a0_clk_out), }; static const struct clkgen_clk_out clkgen_stih407_c0_clk_out[] = { { .name = "clk-icn-gpu", }, { .name = "clk-fdma", }, { .name = "clk-nand", }, { .name = "clk-hva", }, { .name = "clk-proc-stfe", }, { .name = "clk-proc-tp", }, { .name = "clk-rx-icn-dmu", }, { .name = "clk-rx-icn-hva", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-cpu", .flags = CLK_IS_CRITICAL }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-tx-icn-dmu", .flags = CLK_IS_CRITICAL }, { .name = "clk-mmc-0", }, { .name = "clk-mmc-1", }, { .name = "clk-jpegdec", }, /* This clk needs to be on to keep A9 running */ { .name = "clk-ext2fa9", .flags = CLK_IS_CRITICAL }, { .name = "clk-ic-bdisp-0", }, { .name = "clk-ic-bdisp-1", }, { .name = "clk-pp-dmu", }, { .name = "clk-vid-dmu", }, { .name = "clk-dss-lpc", }, { .name = "clk-st231-aud-0", }, { .name = "clk-st231-gp-1", }, { .name = "clk-st231-dmu", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-lmi", .flags = CLK_IS_CRITICAL }, { .name = "clk-tx-icn-disp-1", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-sbc", .flags = CLK_IS_CRITICAL }, { .name = "clk-stfe-frc2", }, { .name = "clk-eth-phy", }, { .name = "clk-eth-ref-phyclk", }, { .name = "clk-flash-promip", }, { .name = "clk-main-disp", }, { .name = "clk-aux-disp", }, { .name = "clk-compo-dvp", }, }; static const struct clkgen_data clkgen_stih407_c0 = { .outputs = clkgen_stih407_c0_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih407_c0_clk_out), }; static const struct clkgen_clk_out clkgen_stih410_c0_clk_out[] = { { .name = "clk-icn-gpu", }, { .name = "clk-fdma", }, { .name = "clk-nand", }, { .name = "clk-hva", }, { .name = "clk-proc-stfe", }, { .name = "clk-proc-tp", }, { .name = "clk-rx-icn-dmu", }, { .name = "clk-rx-icn-hva", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-cpu", .flags = CLK_IS_CRITICAL }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-tx-icn-dmu", .flags = CLK_IS_CRITICAL }, { .name = "clk-mmc-0", }, { .name = "clk-mmc-1", }, { .name = "clk-jpegdec", }, /* This clk needs to be on to keep A9 running */ { .name = "clk-ext2fa9", .flags = CLK_IS_CRITICAL }, { .name = "clk-ic-bdisp-0", }, { .name = "clk-ic-bdisp-1", }, { .name = "clk-pp-dmu", }, { .name = "clk-vid-dmu", }, { .name = "clk-dss-lpc", }, { .name = "clk-st231-aud-0", }, { .name = "clk-st231-gp-1", }, { .name = "clk-st231-dmu", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-lmi", .flags = CLK_IS_CRITICAL }, { .name = "clk-tx-icn-disp-1", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-sbc", .flags = CLK_IS_CRITICAL }, { .name = "clk-stfe-frc2", }, { .name = "clk-eth-phy", }, { .name = "clk-eth-ref-phyclk", }, { .name = "clk-flash-promip", }, { .name = "clk-main-disp", }, { .name = "clk-aux-disp", }, { .name = "clk-compo-dvp", }, { .name = "clk-tx-icn-hades", }, { .name = "clk-rx-icn-hades", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-reg-16", .flags = CLK_IS_CRITICAL }, { .name = "clk-pp-hades", }, { .name = "clk-clust-hades", }, { .name = "clk-hwpe-hades", }, { .name = "clk-fc-hades", }, }; static const struct clkgen_data clkgen_stih410_c0 = { .outputs = clkgen_stih410_c0_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih410_c0_clk_out), }; static const struct clkgen_clk_out clkgen_stih418_c0_clk_out[] = { { .name = "clk-icn-gpu", }, { .name = "clk-fdma", }, { .name = "clk-nand", }, { .name = "clk-hva", }, { .name = "clk-proc-stfe", }, { .name = "clk-tp", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-rx-icn-dmu", .flags = CLK_IS_CRITICAL }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-rx-icn-hva", .flags = CLK_IS_CRITICAL }, { .name = "clk-icn-cpu", .flags = CLK_IS_CRITICAL }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-tx-icn-dmu", .flags = CLK_IS_CRITICAL }, { .name = "clk-mmc-0", }, { .name = "clk-mmc-1", }, { .name = "clk-jpegdec", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-reg", .flags = CLK_IS_CRITICAL }, { .name = "clk-proc-bdisp-0", }, { .name = "clk-proc-bdisp-1", }, { .name = "clk-pp-dmu", }, { .name = "clk-vid-dmu", }, { .name = "clk-dss-lpc", }, { .name = "clk-st231-aud-0", }, { .name = "clk-st231-gp-1", }, { .name = "clk-st231-dmu", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-lmi", .flags = CLK_IS_CRITICAL }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-tx-icn-1", .flags = CLK_IS_CRITICAL }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-sbc", .flags = CLK_IS_CRITICAL }, { .name = "clk-stfe-frc2", }, { .name = "clk-eth-phyref", }, { .name = "clk-eth-ref-phyclk", }, { .name = "clk-flash-promip", }, { .name = "clk-main-disp", }, { .name = "clk-aux-disp", }, { .name = "clk-compo-dvp", }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-tx-icn-hades", .flags = CLK_IS_CRITICAL }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-rx-icn-hades", .flags = CLK_IS_CRITICAL }, /* This clk needs to be on to keep bus interconnect alive */ { .name = "clk-icn-reg-16", .flags = CLK_IS_CRITICAL }, { .name = "clk-pp-hevc", }, { .name = "clk-clust-hevc", }, { .name = "clk-hwpe-hevc", }, { .name = "clk-fc-hevc", }, { .name = "clk-proc-mixer", }, { .name = "clk-proc-sc", }, { .name = "clk-avsp-hevc", }, }; static const struct clkgen_data clkgen_stih418_c0 = { .outputs = clkgen_stih418_c0_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih418_c0_clk_out), }; static const struct clkgen_clk_out clkgen_stih407_d0_clk_out[] = { { .name = "clk-pcm-0", }, { .name = "clk-pcm-1", }, { .name = "clk-pcm-2", }, { .name = "clk-spdiff", }, }; static const struct clkgen_data clkgen_stih407_d0 = { .flags = CLK_SET_RATE_PARENT, .outputs = clkgen_stih407_d0_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih407_d0_clk_out), }; static const struct clkgen_clk_out clkgen_stih410_d0_clk_out[] = { { .name = "clk-pcm-0", }, { .name = "clk-pcm-1", }, { .name = "clk-pcm-2", }, { .name = "clk-spdiff", }, { .name = "clk-pcmr10-master", }, { .name = "clk-usb2-phy", }, }; static const struct clkgen_data clkgen_stih410_d0 = { .flags = CLK_SET_RATE_PARENT, .outputs = clkgen_stih410_d0_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih410_d0_clk_out), }; static const struct clkgen_clk_out clkgen_stih407_d2_clk_out[] = { { .name = "clk-pix-main-disp", }, { .name = "clk-pix-pip", }, { .name = "clk-pix-gdp1", }, { .name = "clk-pix-gdp2", }, { .name = "clk-pix-gdp3", }, { .name = "clk-pix-gdp4", }, { .name = "clk-pix-aux-disp", }, { .name = "clk-denc", }, { .name = "clk-pix-hddac", }, { .name = "clk-hddac", }, { .name = "clk-sddac", }, { .name = "clk-pix-dvo", }, { .name = "clk-dvo", }, { .name = "clk-pix-hdmi", }, { .name = "clk-tmds-hdmi", }, { .name = "clk-ref-hdmiphy", }, }; static const struct clkgen_data clkgen_stih407_d2 = { .outputs = clkgen_stih407_d2_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih407_d2_clk_out), .flags = CLK_SET_RATE_PARENT, .mode = 1, }; static const struct clkgen_clk_out clkgen_stih418_d2_clk_out[] = { { .name = "clk-pix-main-disp", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "clk-tmds-hdmi-div2", }, { .name = "clk-pix-aux-disp", }, { .name = "clk-denc", }, { .name = "clk-pix-hddac", }, { .name = "clk-hddac", }, { .name = "clk-sddac", }, { .name = "clk-pix-dvo", }, { .name = "clk-dvo", }, { .name = "clk-pix-hdmi", }, { .name = "clk-tmds-hdmi", }, { .name = "clk-ref-hdmiphy", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "", }, { .name = "clk-vp9", }, }; static const struct clkgen_data clkgen_stih418_d2 = { .outputs = clkgen_stih418_d2_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih418_d2_clk_out), .flags = CLK_SET_RATE_PARENT, .mode = 1, }; static const struct clkgen_clk_out clkgen_stih407_d3_clk_out[] = { { .name = "clk-stfe-frc1", }, { .name = "clk-tsout-0", }, { .name = "clk-tsout-1", }, { .name = "clk-mchi", }, { .name = "clk-vsens-compo", }, { .name = "clk-frc1-remote", }, { .name = "clk-lpc-0", }, { .name = "clk-lpc-1", }, }; static const struct clkgen_data clkgen_stih407_d3 = { .outputs = clkgen_stih407_d3_clk_out, .outputs_nb = ARRAY_SIZE(clkgen_stih407_d3_clk_out), }; static const struct of_device_id flexgen_of_match[] = { { .compatible = "st,flexgen-audio", .data = &clkgen_audio, }, { .compatible = "st,flexgen-video", .data = &clkgen_video, }, { .compatible = "st,flexgen-stih407-a0", .data = &clkgen_stih407_a0, }, { .compatible = "st,flexgen-stih410-a0", .data = &clkgen_stih410_a0, }, { .compatible = "st,flexgen-stih407-c0", .data = &clkgen_stih407_c0, }, { .compatible = "st,flexgen-stih410-c0", .data = &clkgen_stih410_c0, }, { .compatible = "st,flexgen-stih418-c0", .data = &clkgen_stih418_c0, }, { .compatible = "st,flexgen-stih407-d0", .data = &clkgen_stih407_d0, }, { .compatible = "st,flexgen-stih410-d0", .data = &clkgen_stih410_d0, }, { .compatible = "st,flexgen-stih407-d2", .data = &clkgen_stih407_d2, }, { .compatible = "st,flexgen-stih418-d2", .data = &clkgen_stih418_d2, }, { .compatible = "st,flexgen-stih407-d3", .data = &clkgen_stih407_d3, }, {} }; static void __init st_of_flexgen_setup(struct device_node *np) { struct device_node *pnode; void __iomem *reg; struct clk_onecell_data *clk_data; const char **parents; int num_parents, i; spinlock_t *rlock = NULL; const struct of_device_id *match; struct clkgen_data *data = NULL; unsigned long flex_flags = 0; int ret; bool clk_mode = 0; const char *clk_name; pnode = of_get_parent(np); if (!pnode) return; reg = of_iomap(pnode, 0); of_node_put(pnode); if (!reg) return; parents = flexgen_get_parents(np, &num_parents); if (!parents) { iounmap(reg); return; } match = of_match_node(flexgen_of_match, np); if (match) { data = (struct clkgen_data *)match->data; flex_flags = data->flags; clk_mode = data->mode; } clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); if (!clk_data) goto err; /* First try to get output information from the compatible data */ if (!data || !data->outputs_nb || !data->outputs) { ret = of_property_count_strings(np, "clock-output-names"); if (ret <= 0) { pr_err("%s: Failed to get number of output clocks (%d)", __func__, clk_data->clk_num); goto err; } clk_data->clk_num = ret; } else clk_data->clk_num = data->outputs_nb; clk_data->clks = kcalloc(clk_data->clk_num, sizeof(struct clk *), GFP_KERNEL); if (!clk_data->clks) goto err; rlock = kzalloc(sizeof(spinlock_t), GFP_KERNEL); if (!rlock) goto err; spin_lock_init(rlock); for (i = 0; i < clk_data->clk_num; i++) { struct clk *clk; if (!data || !data->outputs_nb || !data->outputs) { if (of_property_read_string_index(np, "clock-output-names", i, &clk_name)) break; flex_flags &= ~CLK_IS_CRITICAL; of_clk_detect_critical(np, i, &flex_flags); } else { clk_name = data->outputs[i].name; flex_flags = data->flags | data->outputs[i].flags; } /* * If we read an empty clock name then the output is unused */ if (*clk_name == '\0') continue; clk = clk_register_flexgen(clk_name, parents, num_parents, reg, rlock, i, flex_flags, clk_mode); if (IS_ERR(clk)) goto err; clk_data->clks[i] = clk; } kfree(parents); of_clk_add_provider(np, of_clk_src_onecell_get, clk_data); return; err: iounmap(reg); if (clk_data) kfree(clk_data->clks); kfree(clk_data); kfree(parents); kfree(rlock); } CLK_OF_DECLARE(flexgen, "st,flexgen", st_of_flexgen_setup);
linux-master
drivers/clk/st/clk-flexgen.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2014 STMicroelectronics (R&D) Limited */ /* * Authors: * Stephen Gallimore <[email protected]>, * Pankaj Dev <[email protected]>. */ #include <linux/slab.h> #include <linux/of_address.h> #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/iopoll.h> #include "clkgen.h" static DEFINE_SPINLOCK(clkgena_c32_odf_lock); DEFINE_SPINLOCK(clkgen_a9_lock); /* * PLL configuration register bits for PLL3200 C32 */ #define C32_NDIV_MASK (0xff) #define C32_IDF_MASK (0x7) #define C32_ODF_MASK (0x3f) #define C32_LDF_MASK (0x7f) #define C32_CP_MASK (0x1f) #define C32_MAX_ODFS (4) /* * PLL configuration register bits for PLL4600 C28 */ #define C28_NDIV_MASK (0xff) #define C28_IDF_MASK (0x7) #define C28_ODF_MASK (0x3f) struct clkgen_pll_data { struct clkgen_field pdn_status; struct clkgen_field pdn_ctrl; struct clkgen_field locked_status; struct clkgen_field mdiv; struct clkgen_field ndiv; struct clkgen_field pdiv; struct clkgen_field idf; struct clkgen_field ldf; struct clkgen_field cp; unsigned int num_odfs; struct clkgen_field odf[C32_MAX_ODFS]; struct clkgen_field odf_gate[C32_MAX_ODFS]; bool switch2pll_en; struct clkgen_field switch2pll; spinlock_t *lock; const struct clk_ops *ops; }; struct clkgen_clk_out { const char *name; unsigned long flags; }; struct clkgen_pll_data_clks { struct clkgen_pll_data *data; const struct clkgen_clk_out *outputs; }; static const struct clk_ops stm_pll3200c32_ops; static const struct clk_ops stm_pll3200c32_a9_ops; static const struct clk_ops stm_pll4600c28_ops; static const struct clkgen_pll_data st_pll3200c32_cx_0 = { /* 407 C0 PLL0 */ .pdn_status = CLKGEN_FIELD(0x2a0, 0x1, 8), .pdn_ctrl = CLKGEN_FIELD(0x2a0, 0x1, 8), .locked_status = CLKGEN_FIELD(0x2a0, 0x1, 24), .ndiv = CLKGEN_FIELD(0x2a4, C32_NDIV_MASK, 16), .idf = CLKGEN_FIELD(0x2a4, C32_IDF_MASK, 0x0), .num_odfs = 1, .odf = { CLKGEN_FIELD(0x2b4, C32_ODF_MASK, 0) }, .odf_gate = { CLKGEN_FIELD(0x2b4, 0x1, 6) }, .ops = &stm_pll3200c32_ops, }; static const struct clkgen_pll_data_clks st_pll3200c32_cx_0_legacy_data = { .data = (struct clkgen_pll_data *)&st_pll3200c32_cx_0, }; static const struct clkgen_clk_out st_pll3200c32_ax_0_clks[] = { { .name = "clk-s-a0-pll-odf-0", }, }; static const struct clkgen_pll_data_clks st_pll3200c32_a0_data = { .data = (struct clkgen_pll_data *)&st_pll3200c32_cx_0, .outputs = st_pll3200c32_ax_0_clks, }; static const struct clkgen_clk_out st_pll3200c32_cx_0_clks[] = { { .name = "clk-s-c0-pll0-odf-0", }, }; static const struct clkgen_pll_data_clks st_pll3200c32_c0_data = { .data = (struct clkgen_pll_data *)&st_pll3200c32_cx_0, .outputs = st_pll3200c32_cx_0_clks, }; static const struct clkgen_pll_data st_pll3200c32_cx_1 = { /* 407 C0 PLL1 */ .pdn_status = CLKGEN_FIELD(0x2c8, 0x1, 8), .pdn_ctrl = CLKGEN_FIELD(0x2c8, 0x1, 8), .locked_status = CLKGEN_FIELD(0x2c8, 0x1, 24), .ndiv = CLKGEN_FIELD(0x2cc, C32_NDIV_MASK, 16), .idf = CLKGEN_FIELD(0x2cc, C32_IDF_MASK, 0x0), .num_odfs = 1, .odf = { CLKGEN_FIELD(0x2dc, C32_ODF_MASK, 0) }, .odf_gate = { CLKGEN_FIELD(0x2dc, 0x1, 6) }, .ops = &stm_pll3200c32_ops, }; static const struct clkgen_pll_data_clks st_pll3200c32_cx_1_legacy_data = { .data = (struct clkgen_pll_data *)&st_pll3200c32_cx_1, }; static const struct clkgen_clk_out st_pll3200c32_cx_1_clks[] = { { .name = "clk-s-c0-pll1-odf-0", }, }; static const struct clkgen_pll_data_clks st_pll3200c32_c1_data = { .data = (struct clkgen_pll_data *)&st_pll3200c32_cx_1, .outputs = st_pll3200c32_cx_1_clks, }; static const struct clkgen_pll_data st_pll3200c32_407_a9 = { /* 407 A9 */ .pdn_status = CLKGEN_FIELD(0x1a8, 0x1, 0), .pdn_ctrl = CLKGEN_FIELD(0x1a8, 0x1, 0), .locked_status = CLKGEN_FIELD(0x87c, 0x1, 0), .ndiv = CLKGEN_FIELD(0x1b0, C32_NDIV_MASK, 0), .idf = CLKGEN_FIELD(0x1a8, C32_IDF_MASK, 25), .num_odfs = 1, .odf = { CLKGEN_FIELD(0x1b0, C32_ODF_MASK, 8) }, .odf_gate = { CLKGEN_FIELD(0x1ac, 0x1, 28) }, .switch2pll_en = true, .cp = CLKGEN_FIELD(0x1a8, C32_CP_MASK, 1), .switch2pll = CLKGEN_FIELD(0x1a4, 0x1, 1), .lock = &clkgen_a9_lock, .ops = &stm_pll3200c32_a9_ops, }; static const struct clkgen_clk_out st_pll3200c32_407_a9_clks[] = { { .name = "clockgen-a9-pll-odf", }, }; static const struct clkgen_pll_data_clks st_pll3200c32_407_a9_data = { .data = (struct clkgen_pll_data *)&st_pll3200c32_407_a9, .outputs = st_pll3200c32_407_a9_clks, }; static struct clkgen_pll_data st_pll4600c28_418_a9 = { /* 418 A9 */ .pdn_status = CLKGEN_FIELD(0x1a8, 0x1, 0), .pdn_ctrl = CLKGEN_FIELD(0x1a8, 0x1, 0), .locked_status = CLKGEN_FIELD(0x87c, 0x1, 0), .ndiv = CLKGEN_FIELD(0x1b0, C28_NDIV_MASK, 0), .idf = CLKGEN_FIELD(0x1a8, C28_IDF_MASK, 25), .num_odfs = 1, .odf = { CLKGEN_FIELD(0x1b0, C28_ODF_MASK, 8) }, .odf_gate = { CLKGEN_FIELD(0x1ac, 0x1, 28) }, .switch2pll_en = true, .switch2pll = CLKGEN_FIELD(0x1a4, 0x1, 1), .lock = &clkgen_a9_lock, .ops = &stm_pll4600c28_ops, }; static const struct clkgen_clk_out st_pll4600c28_418_a9_clks[] = { { .name = "clockgen-a9-pll-odf", }, }; static const struct clkgen_pll_data_clks st_pll4600c28_418_a9_data = { .data = (struct clkgen_pll_data *)&st_pll4600c28_418_a9, .outputs = st_pll4600c28_418_a9_clks, }; /** * DOC: Clock Generated by PLL, rate set and enabled by bootloader * * Traits of this clock: * prepare - clk_(un)prepare only ensures parent is (un)prepared * enable - clk_enable/disable only ensures parent is enabled * rate - rate is fixed. No clk_set_rate support * parent - fixed parent. No clk_set_parent support */ /* * PLL clock that is integrated in the ClockGenA instances on the STiH415 * and STiH416. * * @hw: handle between common and hardware-specific interfaces. * @regs_base: base of the PLL configuration register(s). * */ struct clkgen_pll { struct clk_hw hw; struct clkgen_pll_data *data; void __iomem *regs_base; spinlock_t *lock; u32 ndiv; u32 idf; u32 cp; }; #define to_clkgen_pll(_hw) container_of(_hw, struct clkgen_pll, hw) struct stm_pll { unsigned long mdiv; unsigned long ndiv; unsigned long pdiv; unsigned long odf; unsigned long idf; unsigned long ldf; unsigned long cp; }; static int clkgen_pll_is_locked(struct clk_hw *hw) { struct clkgen_pll *pll = to_clkgen_pll(hw); u32 locked = CLKGEN_READ(pll, locked_status); return !!locked; } static int clkgen_pll_is_enabled(struct clk_hw *hw) { struct clkgen_pll *pll = to_clkgen_pll(hw); u32 poweroff = CLKGEN_READ(pll, pdn_status); return !poweroff; } static int __clkgen_pll_enable(struct clk_hw *hw) { struct clkgen_pll *pll = to_clkgen_pll(hw); void __iomem *base = pll->regs_base; struct clkgen_field *field = &pll->data->locked_status; int ret = 0; u32 reg; if (clkgen_pll_is_enabled(hw)) return 0; CLKGEN_WRITE(pll, pdn_ctrl, 0); ret = readl_relaxed_poll_timeout(base + field->offset, reg, !!((reg >> field->shift) & field->mask), 0, 10000); if (!ret) { if (pll->data->switch2pll_en) CLKGEN_WRITE(pll, switch2pll, 0); pr_debug("%s:%s enabled\n", __clk_get_name(hw->clk), __func__); } return ret; } static int clkgen_pll_enable(struct clk_hw *hw) { struct clkgen_pll *pll = to_clkgen_pll(hw); unsigned long flags = 0; int ret = 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); ret = __clkgen_pll_enable(hw); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return ret; } static void __clkgen_pll_disable(struct clk_hw *hw) { struct clkgen_pll *pll = to_clkgen_pll(hw); if (!clkgen_pll_is_enabled(hw)) return; if (pll->data->switch2pll_en) CLKGEN_WRITE(pll, switch2pll, 1); CLKGEN_WRITE(pll, pdn_ctrl, 1); pr_debug("%s:%s disabled\n", __clk_get_name(hw->clk), __func__); } static void clkgen_pll_disable(struct clk_hw *hw) { struct clkgen_pll *pll = to_clkgen_pll(hw); unsigned long flags = 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); __clkgen_pll_disable(hw); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); } static int clk_pll3200c32_get_params(unsigned long input, unsigned long output, struct stm_pll *pll) { unsigned long i, n; unsigned long deviation = ~0; unsigned long new_freq; long new_deviation; /* Charge pump table: highest ndiv value for cp=6 to 25 */ static const unsigned char cp_table[] = { 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192 }; /* Output clock range: 800Mhz to 1600Mhz */ if (output < 800000000 || output > 1600000000) return -EINVAL; input /= 1000; output /= 1000; for (i = 1; i <= 7 && deviation; i++) { n = i * output / (2 * input); /* Checks */ if (n < 8) continue; if (n > 200) break; new_freq = (input * 2 * n) / i; new_deviation = abs(new_freq - output); if (!new_deviation || new_deviation < deviation) { pll->idf = i; pll->ndiv = n; deviation = new_deviation; } } if (deviation == ~0) /* No solution found */ return -EINVAL; /* Computing recommended charge pump value */ for (pll->cp = 6; pll->ndiv > cp_table[pll->cp-6]; (pll->cp)++) ; return 0; } static int clk_pll3200c32_get_rate(unsigned long input, struct stm_pll *pll, unsigned long *rate) { if (!pll->idf) pll->idf = 1; *rate = ((2 * (input / 1000) * pll->ndiv) / pll->idf) * 1000; return 0; } static unsigned long recalc_stm_pll3200c32(struct clk_hw *hw, unsigned long parent_rate) { struct clkgen_pll *pll = to_clkgen_pll(hw); unsigned long ndiv, idf; unsigned long rate = 0; if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw)) return 0; ndiv = CLKGEN_READ(pll, ndiv); idf = CLKGEN_READ(pll, idf); if (idf) /* Note: input is divided to avoid overflow */ rate = ((2 * (parent_rate/1000) * ndiv) / idf) * 1000; pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate); return rate; } static long round_rate_stm_pll3200c32(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct stm_pll params; if (!clk_pll3200c32_get_params(*prate, rate, &params)) clk_pll3200c32_get_rate(*prate, &params, &rate); else { pr_debug("%s: %s rate %ld Invalid\n", __func__, __clk_get_name(hw->clk), rate); return 0; } pr_debug("%s: %s new rate %ld [ndiv=%u] [idf=%u]\n", __func__, __clk_get_name(hw->clk), rate, (unsigned int)params.ndiv, (unsigned int)params.idf); return rate; } static int set_rate_stm_pll3200c32(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clkgen_pll *pll = to_clkgen_pll(hw); struct stm_pll params; long hwrate = 0; unsigned long flags = 0; if (!rate || !parent_rate) return -EINVAL; if (!clk_pll3200c32_get_params(parent_rate, rate, &params)) clk_pll3200c32_get_rate(parent_rate, &params, &hwrate); pr_debug("%s: %s new rate %ld [ndiv=0x%x] [idf=0x%x]\n", __func__, __clk_get_name(hw->clk), hwrate, (unsigned int)params.ndiv, (unsigned int)params.idf); if (!hwrate) return -EINVAL; pll->ndiv = params.ndiv; pll->idf = params.idf; pll->cp = params.cp; __clkgen_pll_disable(hw); if (pll->lock) spin_lock_irqsave(pll->lock, flags); CLKGEN_WRITE(pll, ndiv, pll->ndiv); CLKGEN_WRITE(pll, idf, pll->idf); CLKGEN_WRITE(pll, cp, pll->cp); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); __clkgen_pll_enable(hw); return 0; } /* PLL output structure * FVCO >> /2 >> FVCOBY2 (no output) * |> Divider (ODF) >> PHI * * FVCOby2 output = (input * 2 * NDIV) / IDF (assuming FRAC_CONTROL==L) * * Rules: * 4Mhz <= INFF input <= 350Mhz * 4Mhz <= INFIN (INFF / IDF) <= 50Mhz * 19.05Mhz <= FVCOby2 output (PHI w ODF=1) <= 3000Mhz * 1 <= i (register/dec value for IDF) <= 7 * 8 <= n (register/dec value for NDIV) <= 246 */ static int clk_pll4600c28_get_params(unsigned long input, unsigned long output, struct stm_pll *pll) { unsigned long i, infin, n; unsigned long deviation = ~0; unsigned long new_freq, new_deviation; /* Output clock range: 19Mhz to 3000Mhz */ if (output < 19000000 || output > 3000000000u) return -EINVAL; /* For better jitter, IDF should be smallest and NDIV must be maximum */ for (i = 1; i <= 7 && deviation; i++) { /* INFIN checks */ infin = input / i; if (infin < 4000000 || infin > 50000000) continue; /* Invalid case */ n = output / (infin * 2); if (n < 8 || n > 246) continue; /* Invalid case */ if (n < 246) n++; /* To work around 'y' when n=x.y */ for (; n >= 8 && deviation; n--) { new_freq = infin * 2 * n; if (new_freq < output) break; /* Optimization: shorting loop */ new_deviation = new_freq - output; if (!new_deviation || new_deviation < deviation) { pll->idf = i; pll->ndiv = n; deviation = new_deviation; } } } if (deviation == ~0) /* No solution found */ return -EINVAL; return 0; } static int clk_pll4600c28_get_rate(unsigned long input, struct stm_pll *pll, unsigned long *rate) { if (!pll->idf) pll->idf = 1; *rate = (input / pll->idf) * 2 * pll->ndiv; return 0; } static unsigned long recalc_stm_pll4600c28(struct clk_hw *hw, unsigned long parent_rate) { struct clkgen_pll *pll = to_clkgen_pll(hw); struct stm_pll params; unsigned long rate; if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw)) return 0; params.ndiv = CLKGEN_READ(pll, ndiv); params.idf = CLKGEN_READ(pll, idf); clk_pll4600c28_get_rate(parent_rate, &params, &rate); pr_debug("%s:%s rate %lu\n", __clk_get_name(hw->clk), __func__, rate); return rate; } static long round_rate_stm_pll4600c28(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct stm_pll params; if (!clk_pll4600c28_get_params(*prate, rate, &params)) { clk_pll4600c28_get_rate(*prate, &params, &rate); } else { pr_debug("%s: %s rate %ld Invalid\n", __func__, __clk_get_name(hw->clk), rate); return 0; } pr_debug("%s: %s new rate %ld [ndiv=%u] [idf=%u]\n", __func__, __clk_get_name(hw->clk), rate, (unsigned int)params.ndiv, (unsigned int)params.idf); return rate; } static int set_rate_stm_pll4600c28(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clkgen_pll *pll = to_clkgen_pll(hw); struct stm_pll params; long hwrate; unsigned long flags = 0; if (!rate || !parent_rate) return -EINVAL; if (!clk_pll4600c28_get_params(parent_rate, rate, &params)) { clk_pll4600c28_get_rate(parent_rate, &params, &hwrate); } else { pr_debug("%s: %s rate %ld Invalid\n", __func__, __clk_get_name(hw->clk), rate); return -EINVAL; } pr_debug("%s: %s new rate %ld [ndiv=0x%x] [idf=0x%x]\n", __func__, __clk_get_name(hw->clk), hwrate, (unsigned int)params.ndiv, (unsigned int)params.idf); if (!hwrate) return -EINVAL; pll->ndiv = params.ndiv; pll->idf = params.idf; __clkgen_pll_disable(hw); if (pll->lock) spin_lock_irqsave(pll->lock, flags); CLKGEN_WRITE(pll, ndiv, pll->ndiv); CLKGEN_WRITE(pll, idf, pll->idf); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); __clkgen_pll_enable(hw); return 0; } static const struct clk_ops stm_pll3200c32_ops = { .enable = clkgen_pll_enable, .disable = clkgen_pll_disable, .is_enabled = clkgen_pll_is_enabled, .recalc_rate = recalc_stm_pll3200c32, }; static const struct clk_ops stm_pll3200c32_a9_ops = { .enable = clkgen_pll_enable, .disable = clkgen_pll_disable, .is_enabled = clkgen_pll_is_enabled, .recalc_rate = recalc_stm_pll3200c32, .round_rate = round_rate_stm_pll3200c32, .set_rate = set_rate_stm_pll3200c32, }; static const struct clk_ops stm_pll4600c28_ops = { .enable = clkgen_pll_enable, .disable = clkgen_pll_disable, .is_enabled = clkgen_pll_is_enabled, .recalc_rate = recalc_stm_pll4600c28, .round_rate = round_rate_stm_pll4600c28, .set_rate = set_rate_stm_pll4600c28, }; static struct clk * __init clkgen_pll_register(const char *parent_name, struct clkgen_pll_data *pll_data, void __iomem *reg, unsigned long pll_flags, const char *clk_name, spinlock_t *lock) { struct clkgen_pll *pll; struct clk *clk; struct clk_init_data init; pll = kzalloc(sizeof(*pll), GFP_KERNEL); if (!pll) return ERR_PTR(-ENOMEM); init.name = clk_name; init.ops = pll_data->ops; init.flags = pll_flags | CLK_GET_RATE_NOCACHE; init.parent_names = &parent_name; init.num_parents = 1; pll->data = pll_data; pll->regs_base = reg; pll->hw.init = &init; pll->lock = lock; clk = clk_register(NULL, &pll->hw); if (IS_ERR(clk)) { kfree(pll); return clk; } pr_debug("%s: parent %s rate %lu\n", __clk_get_name(clk), __clk_get_name(clk_get_parent(clk)), clk_get_rate(clk)); return clk; } static void __iomem * __init clkgen_get_register_base( struct device_node *np) { struct device_node *pnode; void __iomem *reg = NULL; pnode = of_get_parent(np); if (!pnode) return NULL; reg = of_iomap(pnode, 0); of_node_put(pnode); return reg; } static struct clk * __init clkgen_odf_register(const char *parent_name, void __iomem *reg, struct clkgen_pll_data *pll_data, unsigned long pll_flags, int odf, spinlock_t *odf_lock, const char *odf_name) { struct clk *clk; unsigned long flags; struct clk_gate *gate; struct clk_divider *div; flags = pll_flags | CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT; gate = kzalloc(sizeof(*gate), GFP_KERNEL); if (!gate) return ERR_PTR(-ENOMEM); gate->flags = CLK_GATE_SET_TO_DISABLE; gate->reg = reg + pll_data->odf_gate[odf].offset; gate->bit_idx = pll_data->odf_gate[odf].shift; gate->lock = odf_lock; div = kzalloc(sizeof(*div), GFP_KERNEL); if (!div) { kfree(gate); return ERR_PTR(-ENOMEM); } div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO; div->reg = reg + pll_data->odf[odf].offset; div->shift = pll_data->odf[odf].shift; div->width = fls(pll_data->odf[odf].mask); div->lock = odf_lock; clk = clk_register_composite(NULL, odf_name, &parent_name, 1, NULL, NULL, &div->hw, &clk_divider_ops, &gate->hw, &clk_gate_ops, flags); if (IS_ERR(clk)) return clk; pr_debug("%s: parent %s rate %lu\n", __clk_get_name(clk), __clk_get_name(clk_get_parent(clk)), clk_get_rate(clk)); return clk; } static void __init clkgen_c32_pll_setup(struct device_node *np, struct clkgen_pll_data_clks *datac) { struct clk *clk; const char *parent_name, *pll_name; void __iomem *pll_base; int num_odfs, odf; struct clk_onecell_data *clk_data; unsigned long pll_flags = 0; parent_name = of_clk_get_parent_name(np, 0); if (!parent_name) return; pll_base = clkgen_get_register_base(np); if (!pll_base) return; of_clk_detect_critical(np, 0, &pll_flags); clk = clkgen_pll_register(parent_name, datac->data, pll_base, pll_flags, np->name, datac->data->lock); if (IS_ERR(clk)) return; pll_name = __clk_get_name(clk); num_odfs = datac->data->num_odfs; clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); if (!clk_data) return; clk_data->clk_num = num_odfs; clk_data->clks = kcalloc(clk_data->clk_num, sizeof(struct clk *), GFP_KERNEL); if (!clk_data->clks) goto err; for (odf = 0; odf < num_odfs; odf++) { struct clk *clk; const char *clk_name; unsigned long odf_flags = 0; if (datac->outputs) { clk_name = datac->outputs[odf].name; odf_flags = datac->outputs[odf].flags; } else { if (of_property_read_string_index(np, "clock-output-names", odf, &clk_name)) return; of_clk_detect_critical(np, odf, &odf_flags); } clk = clkgen_odf_register(pll_name, pll_base, datac->data, odf_flags, odf, &clkgena_c32_odf_lock, clk_name); if (IS_ERR(clk)) goto err; clk_data->clks[odf] = clk; } of_clk_add_provider(np, of_clk_src_onecell_get, clk_data); return; err: kfree(pll_name); kfree(clk_data->clks); kfree(clk_data); } static void __init clkgen_c32_pll0_setup(struct device_node *np) { clkgen_c32_pll_setup(np, (struct clkgen_pll_data_clks *) &st_pll3200c32_cx_0_legacy_data); } CLK_OF_DECLARE(c32_pll0, "st,clkgen-pll0", clkgen_c32_pll0_setup); static void __init clkgen_c32_pll0_a0_setup(struct device_node *np) { clkgen_c32_pll_setup(np, (struct clkgen_pll_data_clks *) &st_pll3200c32_a0_data); } CLK_OF_DECLARE(c32_pll0_a0, "st,clkgen-pll0-a0", clkgen_c32_pll0_a0_setup); static void __init clkgen_c32_pll0_c0_setup(struct device_node *np) { clkgen_c32_pll_setup(np, (struct clkgen_pll_data_clks *) &st_pll3200c32_c0_data); } CLK_OF_DECLARE(c32_pll0_c0, "st,clkgen-pll0-c0", clkgen_c32_pll0_c0_setup); static void __init clkgen_c32_pll1_setup(struct device_node *np) { clkgen_c32_pll_setup(np, (struct clkgen_pll_data_clks *) &st_pll3200c32_cx_1_legacy_data); } CLK_OF_DECLARE(c32_pll1, "st,clkgen-pll1", clkgen_c32_pll1_setup); static void __init clkgen_c32_pll1_c0_setup(struct device_node *np) { clkgen_c32_pll_setup(np, (struct clkgen_pll_data_clks *) &st_pll3200c32_c1_data); } CLK_OF_DECLARE(c32_pll1_c0, "st,clkgen-pll1-c0", clkgen_c32_pll1_c0_setup); static void __init clkgen_c32_plla9_setup(struct device_node *np) { clkgen_c32_pll_setup(np, (struct clkgen_pll_data_clks *) &st_pll3200c32_407_a9_data); } CLK_OF_DECLARE(c32_plla9, "st,stih407-clkgen-plla9", clkgen_c32_plla9_setup); static void __init clkgen_c28_plla9_setup(struct device_node *np) { clkgen_c32_pll_setup(np, (struct clkgen_pll_data_clks *) &st_pll4600c28_418_a9_data); } CLK_OF_DECLARE(c28_plla9, "st,stih418-clkgen-plla9", clkgen_c28_plla9_setup);
linux-master
drivers/clk/st/clkgen-pll.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2014 STMicroelectronics R&D Ltd */ /* * Authors: * Stephen Gallimore <[email protected]>, * Pankaj Dev <[email protected]>. */ #include <linux/slab.h> #include <linux/of_address.h> #include <linux/clk.h> #include <linux/clk-provider.h> #include "clkgen.h" /* * Maximum input clock to the PLL before we divide it down by 2 * although in reality in actual systems this has never been seen to * be used. */ #define QUADFS_NDIV_THRESHOLD 30000000 #define PLL_BW_GOODREF (0L) #define PLL_BW_VBADREF (1L) #define PLL_BW_BADREF (2L) #define PLL_BW_VGOODREF (3L) #define QUADFS_MAX_CHAN 4 struct stm_fs { unsigned long ndiv; unsigned long mdiv; unsigned long pe; unsigned long sdiv; unsigned long nsdiv; }; struct clkgen_quadfs_data { bool reset_present; bool bwfilter_present; bool lockstatus_present; bool powerup_polarity; bool standby_polarity; bool nsdiv_present; bool nrst_present; struct clkgen_field ndiv; struct clkgen_field ref_bw; struct clkgen_field nreset; struct clkgen_field npda; struct clkgen_field lock_status; struct clkgen_field nrst[QUADFS_MAX_CHAN]; struct clkgen_field nsb[QUADFS_MAX_CHAN]; struct clkgen_field en[QUADFS_MAX_CHAN]; struct clkgen_field mdiv[QUADFS_MAX_CHAN]; struct clkgen_field pe[QUADFS_MAX_CHAN]; struct clkgen_field sdiv[QUADFS_MAX_CHAN]; struct clkgen_field nsdiv[QUADFS_MAX_CHAN]; const struct clk_ops *pll_ops; int (*get_params)(unsigned long, unsigned long, struct stm_fs *); int (*get_rate)(unsigned long , const struct stm_fs *, unsigned long *); }; struct clkgen_clk_out { const char *name; unsigned long flags; }; struct clkgen_quadfs_data_clks { struct clkgen_quadfs_data *data; const struct clkgen_clk_out *outputs; }; static const struct clk_ops st_quadfs_pll_c32_ops; static int clk_fs660c32_dig_get_params(unsigned long input, unsigned long output, struct stm_fs *fs); static int clk_fs660c32_dig_get_rate(unsigned long, const struct stm_fs *, unsigned long *); static const struct clkgen_quadfs_data st_fs660c32_C = { .nrst_present = true, .nrst = { CLKGEN_FIELD(0x2f0, 0x1, 0), CLKGEN_FIELD(0x2f0, 0x1, 1), CLKGEN_FIELD(0x2f0, 0x1, 2), CLKGEN_FIELD(0x2f0, 0x1, 3) }, .npda = CLKGEN_FIELD(0x2f0, 0x1, 12), .nsb = { CLKGEN_FIELD(0x2f0, 0x1, 8), CLKGEN_FIELD(0x2f0, 0x1, 9), CLKGEN_FIELD(0x2f0, 0x1, 10), CLKGEN_FIELD(0x2f0, 0x1, 11) }, .nsdiv_present = true, .nsdiv = { CLKGEN_FIELD(0x304, 0x1, 24), CLKGEN_FIELD(0x308, 0x1, 24), CLKGEN_FIELD(0x30c, 0x1, 24), CLKGEN_FIELD(0x310, 0x1, 24) }, .mdiv = { CLKGEN_FIELD(0x304, 0x1f, 15), CLKGEN_FIELD(0x308, 0x1f, 15), CLKGEN_FIELD(0x30c, 0x1f, 15), CLKGEN_FIELD(0x310, 0x1f, 15) }, .en = { CLKGEN_FIELD(0x2fc, 0x1, 0), CLKGEN_FIELD(0x2fc, 0x1, 1), CLKGEN_FIELD(0x2fc, 0x1, 2), CLKGEN_FIELD(0x2fc, 0x1, 3) }, .ndiv = CLKGEN_FIELD(0x2f4, 0x7, 16), .pe = { CLKGEN_FIELD(0x304, 0x7fff, 0), CLKGEN_FIELD(0x308, 0x7fff, 0), CLKGEN_FIELD(0x30c, 0x7fff, 0), CLKGEN_FIELD(0x310, 0x7fff, 0) }, .sdiv = { CLKGEN_FIELD(0x304, 0xf, 20), CLKGEN_FIELD(0x308, 0xf, 20), CLKGEN_FIELD(0x30c, 0xf, 20), CLKGEN_FIELD(0x310, 0xf, 20) }, .lockstatus_present = true, .lock_status = CLKGEN_FIELD(0x2f0, 0x1, 24), .powerup_polarity = 1, .standby_polarity = 1, .pll_ops = &st_quadfs_pll_c32_ops, .get_params = clk_fs660c32_dig_get_params, .get_rate = clk_fs660c32_dig_get_rate, }; static const struct clkgen_clk_out st_fs660c32_C_clks[] = { { .name = "clk-s-c0-fs0-ch0", }, { .name = "clk-s-c0-fs0-ch1", }, { .name = "clk-s-c0-fs0-ch2", }, { .name = "clk-s-c0-fs0-ch3", }, }; static const struct clkgen_quadfs_data_clks st_fs660c32_C_data = { .data = (struct clkgen_quadfs_data *)&st_fs660c32_C, .outputs = st_fs660c32_C_clks, }; static const struct clkgen_quadfs_data st_fs660c32_D = { .nrst_present = true, .nrst = { CLKGEN_FIELD(0x2a0, 0x1, 0), CLKGEN_FIELD(0x2a0, 0x1, 1), CLKGEN_FIELD(0x2a0, 0x1, 2), CLKGEN_FIELD(0x2a0, 0x1, 3) }, .ndiv = CLKGEN_FIELD(0x2a4, 0x7, 16), .pe = { CLKGEN_FIELD(0x2b4, 0x7fff, 0), CLKGEN_FIELD(0x2b8, 0x7fff, 0), CLKGEN_FIELD(0x2bc, 0x7fff, 0), CLKGEN_FIELD(0x2c0, 0x7fff, 0) }, .sdiv = { CLKGEN_FIELD(0x2b4, 0xf, 20), CLKGEN_FIELD(0x2b8, 0xf, 20), CLKGEN_FIELD(0x2bc, 0xf, 20), CLKGEN_FIELD(0x2c0, 0xf, 20) }, .npda = CLKGEN_FIELD(0x2a0, 0x1, 12), .nsb = { CLKGEN_FIELD(0x2a0, 0x1, 8), CLKGEN_FIELD(0x2a0, 0x1, 9), CLKGEN_FIELD(0x2a0, 0x1, 10), CLKGEN_FIELD(0x2a0, 0x1, 11) }, .nsdiv_present = true, .nsdiv = { CLKGEN_FIELD(0x2b4, 0x1, 24), CLKGEN_FIELD(0x2b8, 0x1, 24), CLKGEN_FIELD(0x2bc, 0x1, 24), CLKGEN_FIELD(0x2c0, 0x1, 24) }, .mdiv = { CLKGEN_FIELD(0x2b4, 0x1f, 15), CLKGEN_FIELD(0x2b8, 0x1f, 15), CLKGEN_FIELD(0x2bc, 0x1f, 15), CLKGEN_FIELD(0x2c0, 0x1f, 15) }, .en = { CLKGEN_FIELD(0x2ac, 0x1, 0), CLKGEN_FIELD(0x2ac, 0x1, 1), CLKGEN_FIELD(0x2ac, 0x1, 2), CLKGEN_FIELD(0x2ac, 0x1, 3) }, .lockstatus_present = true, .lock_status = CLKGEN_FIELD(0x2A0, 0x1, 24), .powerup_polarity = 1, .standby_polarity = 1, .pll_ops = &st_quadfs_pll_c32_ops, .get_params = clk_fs660c32_dig_get_params, .get_rate = clk_fs660c32_dig_get_rate,}; static const struct clkgen_quadfs_data_clks st_fs660c32_D_data = { .data = (struct clkgen_quadfs_data *)&st_fs660c32_D, }; static const struct clkgen_clk_out st_fs660c32_D0_clks[] = { { .name = "clk-s-d0-fs0-ch0", }, { .name = "clk-s-d0-fs0-ch1", }, { .name = "clk-s-d0-fs0-ch2", }, { .name = "clk-s-d0-fs0-ch3", }, }; static const struct clkgen_quadfs_data_clks st_fs660c32_D0_data = { .data = (struct clkgen_quadfs_data *)&st_fs660c32_D, .outputs = st_fs660c32_D0_clks, }; static const struct clkgen_clk_out st_fs660c32_D2_clks[] = { { .name = "clk-s-d2-fs0-ch0", }, { .name = "clk-s-d2-fs0-ch1", }, { .name = "clk-s-d2-fs0-ch2", }, { .name = "clk-s-d2-fs0-ch3", }, }; static const struct clkgen_quadfs_data_clks st_fs660c32_D2_data = { .data = (struct clkgen_quadfs_data *)&st_fs660c32_D, .outputs = st_fs660c32_D2_clks, }; static const struct clkgen_clk_out st_fs660c32_D3_clks[] = { { .name = "clk-s-d3-fs0-ch0", }, { .name = "clk-s-d3-fs0-ch1", }, { .name = "clk-s-d3-fs0-ch2", }, { .name = "clk-s-d3-fs0-ch3", }, }; static const struct clkgen_quadfs_data_clks st_fs660c32_D3_data = { .data = (struct clkgen_quadfs_data *)&st_fs660c32_D, .outputs = st_fs660c32_D3_clks, }; /** * DOC: A Frequency Synthesizer that multiples its input clock by a fixed factor * * Traits of this clock: * prepare - clk_(un)prepare only ensures parent is (un)prepared * enable - clk_enable and clk_disable are functional & control the Fsyn * rate - inherits rate from parent. set_rate/round_rate/recalc_rate * parent - fixed parent. No clk_set_parent support */ /** * struct st_clk_quadfs_pll - A pll which outputs a fixed multiplier of * its parent clock, found inside a type of * ST quad channel frequency synthesizer block * * @hw: handle between common and hardware-specific interfaces. * @regs_base: base address of the configuration registers. * @lock: spinlock. * @data: local driver data * @ndiv: regmap field for the ndiv control. */ struct st_clk_quadfs_pll { struct clk_hw hw; void __iomem *regs_base; spinlock_t *lock; struct clkgen_quadfs_data *data; u32 ndiv; }; #define to_quadfs_pll(_hw) container_of(_hw, struct st_clk_quadfs_pll, hw) static int quadfs_pll_enable(struct clk_hw *hw) { struct st_clk_quadfs_pll *pll = to_quadfs_pll(hw); unsigned long flags = 0, timeout = jiffies + msecs_to_jiffies(10); if (pll->lock) spin_lock_irqsave(pll->lock, flags); /* * Bring block out of reset if we have reset control. */ if (pll->data->reset_present) CLKGEN_WRITE(pll, nreset, 1); /* * Use a fixed input clock noise bandwidth filter for the moment */ if (pll->data->bwfilter_present) CLKGEN_WRITE(pll, ref_bw, PLL_BW_GOODREF); CLKGEN_WRITE(pll, ndiv, pll->ndiv); /* * Power up the PLL */ CLKGEN_WRITE(pll, npda, !pll->data->powerup_polarity); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); if (pll->data->lockstatus_present) while (!CLKGEN_READ(pll, lock_status)) { if (time_after(jiffies, timeout)) return -ETIMEDOUT; cpu_relax(); } return 0; } static void quadfs_pll_disable(struct clk_hw *hw) { struct st_clk_quadfs_pll *pll = to_quadfs_pll(hw); unsigned long flags = 0; if (pll->lock) spin_lock_irqsave(pll->lock, flags); /* * Powerdown the PLL and then put block into soft reset if we have * reset control. */ CLKGEN_WRITE(pll, npda, pll->data->powerup_polarity); if (pll->data->reset_present) CLKGEN_WRITE(pll, nreset, 0); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); } static int quadfs_pll_is_enabled(struct clk_hw *hw) { struct st_clk_quadfs_pll *pll = to_quadfs_pll(hw); u32 npda = CLKGEN_READ(pll, npda); return pll->data->powerup_polarity ? !npda : !!npda; } static int clk_fs660c32_vco_get_rate(unsigned long input, struct stm_fs *fs, unsigned long *rate) { unsigned long nd = fs->ndiv + 16; /* ndiv value */ *rate = input * nd; return 0; } static unsigned long quadfs_pll_fs660c32_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct st_clk_quadfs_pll *pll = to_quadfs_pll(hw); unsigned long rate = 0; struct stm_fs params; params.ndiv = CLKGEN_READ(pll, ndiv); if (clk_fs660c32_vco_get_rate(parent_rate, &params, &rate)) pr_err("%s:%s error calculating rate\n", clk_hw_get_name(hw), __func__); pll->ndiv = params.ndiv; return rate; } static int clk_fs660c32_vco_get_params(unsigned long input, unsigned long output, struct stm_fs *fs) { /* Formula VCO frequency = (fin x ndiv) / pdiv ndiv = VCOfreq * pdiv / fin */ unsigned long pdiv = 1, n; /* Output clock range: 384Mhz to 660Mhz */ if (output < 384000000 || output > 660000000) return -EINVAL; if (input > 40000000) /* This means that PDIV would be 2 instead of 1. Not supported today. */ return -EINVAL; input /= 1000; output /= 1000; n = output * pdiv / input; if (n < 16) n = 16; fs->ndiv = n - 16; /* Converting formula value to reg value */ return 0; } static long quadfs_pll_fs660c32_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct stm_fs params; if (clk_fs660c32_vco_get_params(*prate, rate, &params)) return rate; clk_fs660c32_vco_get_rate(*prate, &params, &rate); pr_debug("%s: %s new rate %ld [ndiv=%u]\n", __func__, clk_hw_get_name(hw), rate, (unsigned int)params.ndiv); return rate; } static int quadfs_pll_fs660c32_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct st_clk_quadfs_pll *pll = to_quadfs_pll(hw); struct stm_fs params; long hwrate = 0; unsigned long flags = 0; int ret; if (!rate || !parent_rate) return -EINVAL; ret = clk_fs660c32_vco_get_params(parent_rate, rate, &params); if (ret) return ret; clk_fs660c32_vco_get_rate(parent_rate, &params, &hwrate); pr_debug("%s: %s new rate %ld [ndiv=0x%x]\n", __func__, clk_hw_get_name(hw), hwrate, (unsigned int)params.ndiv); if (!hwrate) return -EINVAL; pll->ndiv = params.ndiv; if (pll->lock) spin_lock_irqsave(pll->lock, flags); CLKGEN_WRITE(pll, ndiv, pll->ndiv); if (pll->lock) spin_unlock_irqrestore(pll->lock, flags); return 0; } static const struct clk_ops st_quadfs_pll_c32_ops = { .enable = quadfs_pll_enable, .disable = quadfs_pll_disable, .is_enabled = quadfs_pll_is_enabled, .recalc_rate = quadfs_pll_fs660c32_recalc_rate, .round_rate = quadfs_pll_fs660c32_round_rate, .set_rate = quadfs_pll_fs660c32_set_rate, }; static struct clk * __init st_clk_register_quadfs_pll( const char *name, const char *parent_name, struct clkgen_quadfs_data *quadfs, void __iomem *reg, spinlock_t *lock) { struct st_clk_quadfs_pll *pll; struct clk *clk; struct clk_init_data init; /* * Sanity check required pointers. */ if (WARN_ON(!name || !parent_name)) return ERR_PTR(-EINVAL); pll = kzalloc(sizeof(*pll), GFP_KERNEL); if (!pll) return ERR_PTR(-ENOMEM); init.name = name; init.ops = quadfs->pll_ops; init.flags = CLK_GET_RATE_NOCACHE; init.parent_names = &parent_name; init.num_parents = 1; pll->data = quadfs; pll->regs_base = reg; pll->lock = lock; pll->hw.init = &init; clk = clk_register(NULL, &pll->hw); if (IS_ERR(clk)) kfree(pll); return clk; } /** * DOC: A digital frequency synthesizer * * Traits of this clock: * prepare - clk_(un)prepare only ensures parent is (un)prepared * enable - clk_enable and clk_disable are functional * rate - set rate is functional * parent - fixed parent. No clk_set_parent support */ /* * struct st_clk_quadfs_fsynth - One clock output from a four channel digital * frequency synthesizer (fsynth) block. * * @hw: handle between common and hardware-specific interfaces * * @nsb: regmap field in the output control register for the digital * standby of this fsynth channel. This control is active low so * the channel is in standby when the control bit is cleared. * * @nsdiv: regmap field in the output control register for * for the optional divide by 3 of this fsynth channel. This control * is active low so the divide by 3 is active when the control bit is * cleared and the divide is bypassed when the bit is set. */ struct st_clk_quadfs_fsynth { struct clk_hw hw; void __iomem *regs_base; spinlock_t *lock; struct clkgen_quadfs_data *data; u32 chan; /* * Cached hardware values from set_rate so we can program the * hardware in enable. There are two reasons for this: * * 1. The registers may not be writable until the parent has been * enabled. * * 2. It restores the clock rate when a driver does an enable * on PM restore, after a suspend to RAM has lost the hardware * setup. */ u32 md; u32 pe; u32 sdiv; u32 nsdiv; }; #define to_quadfs_fsynth(_hw) \ container_of(_hw, struct st_clk_quadfs_fsynth, hw) static void quadfs_fsynth_program_enable(struct st_clk_quadfs_fsynth *fs) { /* * Pulse the program enable register lsb to make the hardware take * notice of the new md/pe values with a glitchless transition. */ CLKGEN_WRITE(fs, en[fs->chan], 1); CLKGEN_WRITE(fs, en[fs->chan], 0); } static void quadfs_fsynth_program_rate(struct st_clk_quadfs_fsynth *fs) { unsigned long flags = 0; /* * Ensure the md/pe parameters are ignored while we are * reprogramming them so we can get a glitchless change * when fine tuning the speed of a running clock. */ CLKGEN_WRITE(fs, en[fs->chan], 0); CLKGEN_WRITE(fs, mdiv[fs->chan], fs->md); CLKGEN_WRITE(fs, pe[fs->chan], fs->pe); CLKGEN_WRITE(fs, sdiv[fs->chan], fs->sdiv); if (fs->lock) spin_lock_irqsave(fs->lock, flags); if (fs->data->nsdiv_present) CLKGEN_WRITE(fs, nsdiv[fs->chan], fs->nsdiv); if (fs->lock) spin_unlock_irqrestore(fs->lock, flags); } static int quadfs_fsynth_enable(struct clk_hw *hw) { struct st_clk_quadfs_fsynth *fs = to_quadfs_fsynth(hw); unsigned long flags = 0; pr_debug("%s: %s\n", __func__, clk_hw_get_name(hw)); quadfs_fsynth_program_rate(fs); if (fs->lock) spin_lock_irqsave(fs->lock, flags); CLKGEN_WRITE(fs, nsb[fs->chan], !fs->data->standby_polarity); if (fs->data->nrst_present) CLKGEN_WRITE(fs, nrst[fs->chan], 0); if (fs->lock) spin_unlock_irqrestore(fs->lock, flags); quadfs_fsynth_program_enable(fs); return 0; } static void quadfs_fsynth_disable(struct clk_hw *hw) { struct st_clk_quadfs_fsynth *fs = to_quadfs_fsynth(hw); unsigned long flags = 0; pr_debug("%s: %s\n", __func__, clk_hw_get_name(hw)); if (fs->lock) spin_lock_irqsave(fs->lock, flags); CLKGEN_WRITE(fs, nsb[fs->chan], fs->data->standby_polarity); if (fs->lock) spin_unlock_irqrestore(fs->lock, flags); } static int quadfs_fsynth_is_enabled(struct clk_hw *hw) { struct st_clk_quadfs_fsynth *fs = to_quadfs_fsynth(hw); u32 nsb = CLKGEN_READ(fs, nsb[fs->chan]); pr_debug("%s: %s enable bit = 0x%x\n", __func__, clk_hw_get_name(hw), nsb); return fs->data->standby_polarity ? !nsb : !!nsb; } #define P20 (uint64_t)(1 << 20) static int clk_fs660c32_dig_get_rate(unsigned long input, const struct stm_fs *fs, unsigned long *rate) { unsigned long s = (1 << fs->sdiv); unsigned long ns; uint64_t res; /* * 'nsdiv' is a register value ('BIN') which is translated * to a decimal value according to following rules. * * nsdiv ns.dec * 0 3 * 1 1 */ ns = (fs->nsdiv == 1) ? 1 : 3; res = (P20 * (32 + fs->mdiv) + 32 * fs->pe) * s * ns; *rate = (unsigned long)div64_u64(input * P20 * 32, res); return 0; } static int clk_fs660c32_get_pe(int m, int si, unsigned long *deviation, signed long input, unsigned long output, uint64_t *p, struct stm_fs *fs) { unsigned long new_freq, new_deviation; struct stm_fs fs_tmp; uint64_t val; val = (uint64_t)output << si; *p = (uint64_t)input * P20 - (32LL + (uint64_t)m) * val * (P20 / 32LL); *p = div64_u64(*p, val); if (*p > 32767LL) return 1; fs_tmp.mdiv = (unsigned long) m; fs_tmp.pe = (unsigned long)*p; fs_tmp.sdiv = si; fs_tmp.nsdiv = 1; clk_fs660c32_dig_get_rate(input, &fs_tmp, &new_freq); new_deviation = abs(output - new_freq); if (new_deviation < *deviation) { fs->mdiv = m; fs->pe = (unsigned long)*p; fs->sdiv = si; fs->nsdiv = 1; *deviation = new_deviation; } return 0; } static int clk_fs660c32_dig_get_params(unsigned long input, unsigned long output, struct stm_fs *fs) { int si; /* sdiv_reg (8 downto 0) */ int m; /* md value */ unsigned long new_freq, new_deviation; /* initial condition to say: "infinite deviation" */ unsigned long deviation = ~0; uint64_t p, p1, p2; /* pe value */ int r1, r2; struct stm_fs fs_tmp; for (si = 0; (si <= 8) && deviation; si++) { /* Boundary test to avoid useless iteration */ r1 = clk_fs660c32_get_pe(0, si, &deviation, input, output, &p1, fs); r2 = clk_fs660c32_get_pe(31, si, &deviation, input, output, &p2, fs); /* No solution */ if (r1 && r2 && (p1 > p2)) continue; /* Try to find best deviation */ for (m = 1; (m < 31) && deviation; m++) clk_fs660c32_get_pe(m, si, &deviation, input, output, &p, fs); } if (deviation == ~0) /* No solution found */ return -1; /* pe fine tuning if deviation not 0: +/- 2 around computed pe value */ if (deviation) { fs_tmp.mdiv = fs->mdiv; fs_tmp.sdiv = fs->sdiv; fs_tmp.nsdiv = fs->nsdiv; if (fs->pe > 2) p2 = fs->pe - 2; else p2 = 0; for (; p2 < 32768ll && (p2 <= (fs->pe + 2)); p2++) { fs_tmp.pe = (unsigned long)p2; clk_fs660c32_dig_get_rate(input, &fs_tmp, &new_freq); new_deviation = abs(output - new_freq); /* Check if this is a better solution */ if (new_deviation < deviation) { fs->pe = (unsigned long)p2; deviation = new_deviation; } } } return 0; } static int quadfs_fsynt_get_hw_value_for_recalc(struct st_clk_quadfs_fsynth *fs, struct stm_fs *params) { /* * Get the initial hardware values for recalc_rate */ params->mdiv = CLKGEN_READ(fs, mdiv[fs->chan]); params->pe = CLKGEN_READ(fs, pe[fs->chan]); params->sdiv = CLKGEN_READ(fs, sdiv[fs->chan]); if (fs->data->nsdiv_present) params->nsdiv = CLKGEN_READ(fs, nsdiv[fs->chan]); else params->nsdiv = 1; /* * If All are NULL then assume no clock rate is programmed. */ if (!params->mdiv && !params->pe && !params->sdiv) return 1; fs->md = params->mdiv; fs->pe = params->pe; fs->sdiv = params->sdiv; fs->nsdiv = params->nsdiv; return 0; } static long quadfs_find_best_rate(struct clk_hw *hw, unsigned long drate, unsigned long prate, struct stm_fs *params) { struct st_clk_quadfs_fsynth *fs = to_quadfs_fsynth(hw); int (*clk_fs_get_rate)(unsigned long , const struct stm_fs *, unsigned long *); int (*clk_fs_get_params)(unsigned long, unsigned long, struct stm_fs *); unsigned long rate = 0; clk_fs_get_rate = fs->data->get_rate; clk_fs_get_params = fs->data->get_params; if (!clk_fs_get_params(prate, drate, params)) clk_fs_get_rate(prate, params, &rate); return rate; } static unsigned long quadfs_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct st_clk_quadfs_fsynth *fs = to_quadfs_fsynth(hw); unsigned long rate = 0; struct stm_fs params; int (*clk_fs_get_rate)(unsigned long , const struct stm_fs *, unsigned long *); clk_fs_get_rate = fs->data->get_rate; if (quadfs_fsynt_get_hw_value_for_recalc(fs, &params)) return 0; if (clk_fs_get_rate(parent_rate, &params, &rate)) { pr_err("%s:%s error calculating rate\n", clk_hw_get_name(hw), __func__); } pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate); return rate; } static long quadfs_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct stm_fs params; rate = quadfs_find_best_rate(hw, rate, *prate, &params); pr_debug("%s: %s new rate %ld [sdiv=0x%x,md=0x%x,pe=0x%x,nsdiv3=%u]\n", __func__, clk_hw_get_name(hw), rate, (unsigned int)params.sdiv, (unsigned int)params.mdiv, (unsigned int)params.pe, (unsigned int)params.nsdiv); return rate; } static void quadfs_program_and_enable(struct st_clk_quadfs_fsynth *fs, struct stm_fs *params) { fs->md = params->mdiv; fs->pe = params->pe; fs->sdiv = params->sdiv; fs->nsdiv = params->nsdiv; /* * In some integrations you can only change the fsynth programming when * the parent entity containing it is enabled. */ quadfs_fsynth_program_rate(fs); quadfs_fsynth_program_enable(fs); } static int quadfs_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct st_clk_quadfs_fsynth *fs = to_quadfs_fsynth(hw); struct stm_fs params; long hwrate; if (!rate || !parent_rate) return -EINVAL; memset(&params, 0, sizeof(struct stm_fs)); hwrate = quadfs_find_best_rate(hw, rate, parent_rate, &params); if (!hwrate) return -EINVAL; quadfs_program_and_enable(fs, &params); return 0; } static const struct clk_ops st_quadfs_ops = { .enable = quadfs_fsynth_enable, .disable = quadfs_fsynth_disable, .is_enabled = quadfs_fsynth_is_enabled, .round_rate = quadfs_round_rate, .set_rate = quadfs_set_rate, .recalc_rate = quadfs_recalc_rate, }; static struct clk * __init st_clk_register_quadfs_fsynth( const char *name, const char *parent_name, struct clkgen_quadfs_data *quadfs, void __iomem *reg, u32 chan, unsigned long flags, spinlock_t *lock) { struct st_clk_quadfs_fsynth *fs; struct clk *clk; struct clk_init_data init; /* * Sanity check required pointers, note that nsdiv3 is optional. */ if (WARN_ON(!name || !parent_name)) return ERR_PTR(-EINVAL); fs = kzalloc(sizeof(*fs), GFP_KERNEL); if (!fs) return ERR_PTR(-ENOMEM); init.name = name; init.ops = &st_quadfs_ops; init.flags = flags | CLK_GET_RATE_NOCACHE; init.parent_names = &parent_name; init.num_parents = 1; fs->data = quadfs; fs->regs_base = reg; fs->chan = chan; fs->lock = lock; fs->hw.init = &init; clk = clk_register(NULL, &fs->hw); if (IS_ERR(clk)) kfree(fs); return clk; } static void __init st_of_create_quadfs_fsynths( struct device_node *np, const char *pll_name, struct clkgen_quadfs_data_clks *quadfs, void __iomem *reg, spinlock_t *lock) { struct clk_onecell_data *clk_data; int fschan; clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); if (!clk_data) return; clk_data->clk_num = QUADFS_MAX_CHAN; clk_data->clks = kcalloc(QUADFS_MAX_CHAN, sizeof(struct clk *), GFP_KERNEL); if (!clk_data->clks) { kfree(clk_data); return; } for (fschan = 0; fschan < QUADFS_MAX_CHAN; fschan++) { struct clk *clk; const char *clk_name; unsigned long flags = 0; if (quadfs->outputs) { clk_name = quadfs->outputs[fschan].name; flags = quadfs->outputs[fschan].flags; } else { if (of_property_read_string_index(np, "clock-output-names", fschan, &clk_name)) break; of_clk_detect_critical(np, fschan, &flags); } /* * If we read an empty clock name then the channel is unused */ if (*clk_name == '\0') continue; clk = st_clk_register_quadfs_fsynth(clk_name, pll_name, quadfs->data, reg, fschan, flags, lock); /* * If there was an error registering this clock output, clean * up and move on to the next one. */ if (!IS_ERR(clk)) { clk_data->clks[fschan] = clk; pr_debug("%s: parent %s rate %u\n", __clk_get_name(clk), __clk_get_name(clk_get_parent(clk)), (unsigned int)clk_get_rate(clk)); } } of_clk_add_provider(np, of_clk_src_onecell_get, clk_data); } static void __init st_of_quadfs_setup(struct device_node *np, struct clkgen_quadfs_data_clks *datac) { struct clk *clk; const char *pll_name, *clk_parent_name; void __iomem *reg; spinlock_t *lock; struct device_node *parent_np; /* * First check for reg property within the node to keep backward * compatibility, then if reg doesn't exist look at the parent node */ reg = of_iomap(np, 0); if (!reg) { parent_np = of_get_parent(np); reg = of_iomap(parent_np, 0); of_node_put(parent_np); if (!reg) { pr_err("%s: Failed to get base address\n", __func__); return; } } clk_parent_name = of_clk_get_parent_name(np, 0); if (!clk_parent_name) return; pll_name = kasprintf(GFP_KERNEL, "%pOFn.pll", np); if (!pll_name) return; lock = kzalloc(sizeof(*lock), GFP_KERNEL); if (!lock) goto err_exit; spin_lock_init(lock); clk = st_clk_register_quadfs_pll(pll_name, clk_parent_name, datac->data, reg, lock); if (IS_ERR(clk)) { kfree(lock); goto err_exit; } else pr_debug("%s: parent %s rate %u\n", __clk_get_name(clk), __clk_get_name(clk_get_parent(clk)), (unsigned int)clk_get_rate(clk)); st_of_create_quadfs_fsynths(np, pll_name, datac, reg, lock); err_exit: kfree(pll_name); /* No longer need local copy of the PLL name */ } static void __init st_of_quadfs660C_setup(struct device_node *np) { st_of_quadfs_setup(np, (struct clkgen_quadfs_data_clks *) &st_fs660c32_C_data); } CLK_OF_DECLARE(quadfs660C, "st,quadfs-pll", st_of_quadfs660C_setup); static void __init st_of_quadfs660D_setup(struct device_node *np) { st_of_quadfs_setup(np, (struct clkgen_quadfs_data_clks *) &st_fs660c32_D_data); } CLK_OF_DECLARE(quadfs660D, "st,quadfs", st_of_quadfs660D_setup); static void __init st_of_quadfs660D0_setup(struct device_node *np) { st_of_quadfs_setup(np, (struct clkgen_quadfs_data_clks *) &st_fs660c32_D0_data); } CLK_OF_DECLARE(quadfs660D0, "st,quadfs-d0", st_of_quadfs660D0_setup); static void __init st_of_quadfs660D2_setup(struct device_node *np) { st_of_quadfs_setup(np, (struct clkgen_quadfs_data_clks *) &st_fs660c32_D2_data); } CLK_OF_DECLARE(quadfs660D2, "st,quadfs-d2", st_of_quadfs660D2_setup); static void __init st_of_quadfs660D3_setup(struct device_node *np) { st_of_quadfs_setup(np, (struct clkgen_quadfs_data_clks *) &st_fs660c32_D3_data); } CLK_OF_DECLARE(quadfs660D3, "st,quadfs-d3", st_of_quadfs660D3_setup);
linux-master
drivers/clk/st/clkgen-fsyn.c
// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (c) 2019 Amlogic, Inc. All rights reserved. * Author: Jian Hu <[email protected]> * * Copyright (c) 2023, SberDevices. All Rights Reserved. * Author: Dmitry Rokosov <[email protected]> */ #include <linux/clk-provider.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include "a1-pll.h" #include "clk-regmap.h" #include "meson-clkc-utils.h" #include <dt-bindings/clock/amlogic,a1-pll-clkc.h> static struct clk_regmap fixed_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = ANACTRL_FIXPLL_CTRL0, .shift = 28, .width = 1, }, .m = { .reg_off = ANACTRL_FIXPLL_CTRL0, .shift = 0, .width = 8, }, .n = { .reg_off = ANACTRL_FIXPLL_CTRL0, .shift = 10, .width = 5, }, .frac = { .reg_off = ANACTRL_FIXPLL_CTRL1, .shift = 0, .width = 19, }, .l = { .reg_off = ANACTRL_FIXPLL_STS, .shift = 31, .width = 1, }, .rst = { .reg_off = ANACTRL_FIXPLL_CTRL0, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "fixpll_in", }, .num_parents = 1, }, }; static struct clk_regmap fixed_pll = { .data = &(struct clk_regmap_gate_data){ .offset = ANACTRL_FIXPLL_CTRL0, .bit_idx = 20, }, .hw.init = &(struct clk_init_data) { .name = "fixed_pll", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &fixed_pll_dco.hw }, .num_parents = 1, }, }; static const struct pll_mult_range hifi_pll_mult_range = { .min = 32, .max = 64, }; static const struct reg_sequence hifi_init_regs[] = { { .reg = ANACTRL_HIFIPLL_CTRL1, .def = 0x01800000 }, { .reg = ANACTRL_HIFIPLL_CTRL2, .def = 0x00001100 }, { .reg = ANACTRL_HIFIPLL_CTRL3, .def = 0x100a1100 }, { .reg = ANACTRL_HIFIPLL_CTRL4, .def = 0x00302000 }, { .reg = ANACTRL_HIFIPLL_CTRL0, .def = 0x01f18000 }, }; static struct clk_regmap hifi_pll = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = ANACTRL_HIFIPLL_CTRL0, .shift = 28, .width = 1, }, .m = { .reg_off = ANACTRL_HIFIPLL_CTRL0, .shift = 0, .width = 8, }, .n = { .reg_off = ANACTRL_HIFIPLL_CTRL0, .shift = 10, .width = 5, }, .frac = { .reg_off = ANACTRL_HIFIPLL_CTRL1, .shift = 0, .width = 19, }, .l = { .reg_off = ANACTRL_HIFIPLL_STS, .shift = 31, .width = 1, }, .current_en = { .reg_off = ANACTRL_HIFIPLL_CTRL0, .shift = 26, .width = 1, }, .l_detect = { .reg_off = ANACTRL_HIFIPLL_CTRL2, .shift = 6, .width = 1, }, .range = &hifi_pll_mult_range, .init_regs = hifi_init_regs, .init_count = ARRAY_SIZE(hifi_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "hifi_pll", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "hifipll_in", }, .num_parents = 1, }, }; static struct clk_fixed_factor fclk_div2_div = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "fclk_div2_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap fclk_div2 = { .data = &(struct clk_regmap_gate_data){ .offset = ANACTRL_FIXPLL_CTRL0, .bit_idx = 21, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &fclk_div2_div.hw }, .num_parents = 1, /* * This clock is used by DDR clock in BL2 firmware * and is required by the platform to operate correctly. * Until the following condition are met, we need this clock to * be marked as critical: * a) Mark the clock used by a firmware resource, if possible * b) CCF has a clock hand-off mechanism to make the sure the * clock stays on until the proper driver comes along */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_fixed_factor fclk_div3_div = { .mult = 1, .div = 3, .hw.init = &(struct clk_init_data){ .name = "fclk_div3_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap fclk_div3 = { .data = &(struct clk_regmap_gate_data){ .offset = ANACTRL_FIXPLL_CTRL0, .bit_idx = 22, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div3", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &fclk_div3_div.hw }, .num_parents = 1, /* * This clock is used by APB bus which is set in boot ROM code * and is required by the platform to operate correctly. */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_fixed_factor fclk_div5_div = { .mult = 1, .div = 5, .hw.init = &(struct clk_init_data){ .name = "fclk_div5_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap fclk_div5 = { .data = &(struct clk_regmap_gate_data){ .offset = ANACTRL_FIXPLL_CTRL0, .bit_idx = 23, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div5", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &fclk_div5_div.hw }, .num_parents = 1, /* * This clock is used by AXI bus which setted in Romcode * and is required by the platform to operate correctly. */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_fixed_factor fclk_div7_div = { .mult = 1, .div = 7, .hw.init = &(struct clk_init_data){ .name = "fclk_div7_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap fclk_div7 = { .data = &(struct clk_regmap_gate_data){ .offset = ANACTRL_FIXPLL_CTRL0, .bit_idx = 24, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div7", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &fclk_div7_div.hw }, .num_parents = 1, }, }; /* Array of all clocks registered by this provider */ static struct clk_hw *a1_pll_hw_clks[] = { [CLKID_FIXED_PLL_DCO] = &fixed_pll_dco.hw, [CLKID_FIXED_PLL] = &fixed_pll.hw, [CLKID_FCLK_DIV2_DIV] = &fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &fclk_div3_div.hw, [CLKID_FCLK_DIV5_DIV] = &fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &fclk_div7_div.hw, [CLKID_FCLK_DIV2] = &fclk_div2.hw, [CLKID_FCLK_DIV3] = &fclk_div3.hw, [CLKID_FCLK_DIV5] = &fclk_div5.hw, [CLKID_FCLK_DIV7] = &fclk_div7.hw, [CLKID_HIFI_PLL] = &hifi_pll.hw, }; static struct clk_regmap *const a1_pll_regmaps[] = { &fixed_pll_dco, &fixed_pll, &fclk_div2, &fclk_div3, &fclk_div5, &fclk_div7, &hifi_pll, }; static struct regmap_config a1_pll_regmap_cfg = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, }; static struct meson_clk_hw_data a1_pll_clks = { .hws = a1_pll_hw_clks, .num = ARRAY_SIZE(a1_pll_hw_clks), }; static int meson_a1_pll_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; void __iomem *base; struct regmap *map; int clkid, i, err; base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) return dev_err_probe(dev, PTR_ERR(base), "can't ioremap resource\n"); map = devm_regmap_init_mmio(dev, base, &a1_pll_regmap_cfg); if (IS_ERR(map)) return dev_err_probe(dev, PTR_ERR(map), "can't init regmap mmio region\n"); /* Populate regmap for the regmap backed clocks */ for (i = 0; i < ARRAY_SIZE(a1_pll_regmaps); i++) a1_pll_regmaps[i]->map = map; /* Register clocks */ for (clkid = 0; clkid < a1_pll_clks.num; clkid++) { err = devm_clk_hw_register(dev, a1_pll_clks.hws[clkid]); if (err) return dev_err_probe(dev, err, "clock[%d] registration failed\n", clkid); } return devm_of_clk_add_hw_provider(dev, meson_clk_hw_get, &a1_pll_clks); } static const struct of_device_id a1_pll_clkc_match_table[] = { { .compatible = "amlogic,a1-pll-clkc", }, {} }; MODULE_DEVICE_TABLE(of, a1_pll_clkc_match_table); static struct platform_driver a1_pll_clkc_driver = { .probe = meson_a1_pll_probe, .driver = { .name = "a1-pll-clkc", .of_match_table = a1_pll_clkc_match_table, }, }; module_platform_driver(a1_pll_clkc_driver); MODULE_AUTHOR("Jian Hu <[email protected]>"); MODULE_AUTHOR("Dmitry Rokosov <[email protected]>"); MODULE_LICENSE("GPL");
linux-master
drivers/clk/meson/a1-pll.c
// SPDX-License-Identifier: (GPL-2.0 OR MIT) /* * Copyright (c) 2018 BayLibre, SAS. * Author: Jerome Brunet <[email protected]> */ #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/init.h> #include <linux/module.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/reset.h> #include <linux/reset-controller.h> #include <linux/slab.h> #include "meson-clkc-utils.h" #include "axg-audio.h" #include "clk-regmap.h" #include "clk-phase.h" #include "sclk-div.h" #include <dt-bindings/clock/axg-audio-clkc.h> #define AUD_GATE(_name, _reg, _bit, _pname, _iflags) { \ .data = &(struct clk_regmap_gate_data){ \ .offset = (_reg), \ .bit_idx = (_bit), \ }, \ .hw.init = &(struct clk_init_data) { \ .name = "aud_"#_name, \ .ops = &clk_regmap_gate_ops, \ .parent_names = (const char *[]){ #_pname }, \ .num_parents = 1, \ .flags = CLK_DUTY_CYCLE_PARENT | (_iflags), \ }, \ } #define AUD_MUX(_name, _reg, _mask, _shift, _dflags, _pdata, _iflags) { \ .data = &(struct clk_regmap_mux_data){ \ .offset = (_reg), \ .mask = (_mask), \ .shift = (_shift), \ .flags = (_dflags), \ }, \ .hw.init = &(struct clk_init_data){ \ .name = "aud_"#_name, \ .ops = &clk_regmap_mux_ops, \ .parent_data = _pdata, \ .num_parents = ARRAY_SIZE(_pdata), \ .flags = CLK_DUTY_CYCLE_PARENT | (_iflags), \ }, \ } #define AUD_DIV(_name, _reg, _shift, _width, _dflags, _pname, _iflags) { \ .data = &(struct clk_regmap_div_data){ \ .offset = (_reg), \ .shift = (_shift), \ .width = (_width), \ .flags = (_dflags), \ }, \ .hw.init = &(struct clk_init_data){ \ .name = "aud_"#_name, \ .ops = &clk_regmap_divider_ops, \ .parent_names = (const char *[]){ #_pname }, \ .num_parents = 1, \ .flags = (_iflags), \ }, \ } #define AUD_PCLK_GATE(_name, _reg, _bit) { \ .data = &(struct clk_regmap_gate_data){ \ .offset = (_reg), \ .bit_idx = (_bit), \ }, \ .hw.init = &(struct clk_init_data) { \ .name = "aud_"#_name, \ .ops = &clk_regmap_gate_ops, \ .parent_names = (const char *[]){ "aud_top" }, \ .num_parents = 1, \ }, \ } #define AUD_SCLK_DIV(_name, _reg, _div_shift, _div_width, \ _hi_shift, _hi_width, _pname, _iflags) { \ .data = &(struct meson_sclk_div_data) { \ .div = { \ .reg_off = (_reg), \ .shift = (_div_shift), \ .width = (_div_width), \ }, \ .hi = { \ .reg_off = (_reg), \ .shift = (_hi_shift), \ .width = (_hi_width), \ }, \ }, \ .hw.init = &(struct clk_init_data) { \ .name = "aud_"#_name, \ .ops = &meson_sclk_div_ops, \ .parent_names = (const char *[]){ #_pname }, \ .num_parents = 1, \ .flags = (_iflags), \ }, \ } #define AUD_TRIPHASE(_name, _reg, _width, _shift0, _shift1, _shift2, \ _pname, _iflags) { \ .data = &(struct meson_clk_triphase_data) { \ .ph0 = { \ .reg_off = (_reg), \ .shift = (_shift0), \ .width = (_width), \ }, \ .ph1 = { \ .reg_off = (_reg), \ .shift = (_shift1), \ .width = (_width), \ }, \ .ph2 = { \ .reg_off = (_reg), \ .shift = (_shift2), \ .width = (_width), \ }, \ }, \ .hw.init = &(struct clk_init_data) { \ .name = "aud_"#_name, \ .ops = &meson_clk_triphase_ops, \ .parent_names = (const char *[]){ #_pname }, \ .num_parents = 1, \ .flags = CLK_DUTY_CYCLE_PARENT | (_iflags), \ }, \ } #define AUD_PHASE(_name, _reg, _width, _shift, _pname, _iflags) { \ .data = &(struct meson_clk_phase_data) { \ .ph = { \ .reg_off = (_reg), \ .shift = (_shift), \ .width = (_width), \ }, \ }, \ .hw.init = &(struct clk_init_data) { \ .name = "aud_"#_name, \ .ops = &meson_clk_phase_ops, \ .parent_names = (const char *[]){ #_pname }, \ .num_parents = 1, \ .flags = (_iflags), \ }, \ } #define AUD_SCLK_WS(_name, _reg, _width, _shift_ph, _shift_ws, _pname, \ _iflags) { \ .data = &(struct meson_sclk_ws_inv_data) { \ .ph = { \ .reg_off = (_reg), \ .shift = (_shift_ph), \ .width = (_width), \ }, \ .ws = { \ .reg_off = (_reg), \ .shift = (_shift_ws), \ .width = (_width), \ }, \ }, \ .hw.init = &(struct clk_init_data) { \ .name = "aud_"#_name, \ .ops = &meson_clk_phase_ops, \ .parent_names = (const char *[]){ #_pname }, \ .num_parents = 1, \ .flags = (_iflags), \ }, \ } /* Audio Master Clocks */ static const struct clk_parent_data mst_mux_parent_data[] = { { .fw_name = "mst_in0", }, { .fw_name = "mst_in1", }, { .fw_name = "mst_in2", }, { .fw_name = "mst_in3", }, { .fw_name = "mst_in4", }, { .fw_name = "mst_in5", }, { .fw_name = "mst_in6", }, { .fw_name = "mst_in7", }, }; #define AUD_MST_MUX(_name, _reg, _flag) \ AUD_MUX(_name##_sel, _reg, 0x7, 24, _flag, \ mst_mux_parent_data, 0) #define AUD_MST_DIV(_name, _reg, _flag) \ AUD_DIV(_name##_div, _reg, 0, 16, _flag, \ aud_##_name##_sel, CLK_SET_RATE_PARENT) #define AUD_MST_MCLK_GATE(_name, _reg) \ AUD_GATE(_name, _reg, 31, aud_##_name##_div, \ CLK_SET_RATE_PARENT) #define AUD_MST_MCLK_MUX(_name, _reg) \ AUD_MST_MUX(_name, _reg, CLK_MUX_ROUND_CLOSEST) #define AUD_MST_MCLK_DIV(_name, _reg) \ AUD_MST_DIV(_name, _reg, CLK_DIVIDER_ROUND_CLOSEST) #define AUD_MST_SYS_MUX(_name, _reg) \ AUD_MST_MUX(_name, _reg, 0) #define AUD_MST_SYS_DIV(_name, _reg) \ AUD_MST_DIV(_name, _reg, 0) /* Sample Clocks */ #define AUD_MST_SCLK_PRE_EN(_name, _reg) \ AUD_GATE(mst_##_name##_sclk_pre_en, _reg, 31, \ aud_mst_##_name##_mclk, 0) #define AUD_MST_SCLK_DIV(_name, _reg) \ AUD_SCLK_DIV(mst_##_name##_sclk_div, _reg, 20, 10, 0, 0, \ aud_mst_##_name##_sclk_pre_en, \ CLK_SET_RATE_PARENT) #define AUD_MST_SCLK_POST_EN(_name, _reg) \ AUD_GATE(mst_##_name##_sclk_post_en, _reg, 30, \ aud_mst_##_name##_sclk_div, CLK_SET_RATE_PARENT) #define AUD_MST_SCLK(_name, _reg) \ AUD_TRIPHASE(mst_##_name##_sclk, _reg, 1, 0, 2, 4, \ aud_mst_##_name##_sclk_post_en, CLK_SET_RATE_PARENT) #define AUD_MST_LRCLK_DIV(_name, _reg) \ AUD_SCLK_DIV(mst_##_name##_lrclk_div, _reg, 0, 10, 10, 10, \ aud_mst_##_name##_sclk_post_en, 0) #define AUD_MST_LRCLK(_name, _reg) \ AUD_TRIPHASE(mst_##_name##_lrclk, _reg, 1, 1, 3, 5, \ aud_mst_##_name##_lrclk_div, CLK_SET_RATE_PARENT) /* TDM bit clock sources */ static const struct clk_parent_data tdm_sclk_parent_data[] = { { .name = "aud_mst_a_sclk", .index = -1, }, { .name = "aud_mst_b_sclk", .index = -1, }, { .name = "aud_mst_c_sclk", .index = -1, }, { .name = "aud_mst_d_sclk", .index = -1, }, { .name = "aud_mst_e_sclk", .index = -1, }, { .name = "aud_mst_f_sclk", .index = -1, }, { .fw_name = "slv_sclk0", }, { .fw_name = "slv_sclk1", }, { .fw_name = "slv_sclk2", }, { .fw_name = "slv_sclk3", }, { .fw_name = "slv_sclk4", }, { .fw_name = "slv_sclk5", }, { .fw_name = "slv_sclk6", }, { .fw_name = "slv_sclk7", }, { .fw_name = "slv_sclk8", }, { .fw_name = "slv_sclk9", }, }; /* TDM sample clock sources */ static const struct clk_parent_data tdm_lrclk_parent_data[] = { { .name = "aud_mst_a_lrclk", .index = -1, }, { .name = "aud_mst_b_lrclk", .index = -1, }, { .name = "aud_mst_c_lrclk", .index = -1, }, { .name = "aud_mst_d_lrclk", .index = -1, }, { .name = "aud_mst_e_lrclk", .index = -1, }, { .name = "aud_mst_f_lrclk", .index = -1, }, { .fw_name = "slv_lrclk0", }, { .fw_name = "slv_lrclk1", }, { .fw_name = "slv_lrclk2", }, { .fw_name = "slv_lrclk3", }, { .fw_name = "slv_lrclk4", }, { .fw_name = "slv_lrclk5", }, { .fw_name = "slv_lrclk6", }, { .fw_name = "slv_lrclk7", }, { .fw_name = "slv_lrclk8", }, { .fw_name = "slv_lrclk9", }, }; #define AUD_TDM_SCLK_MUX(_name, _reg) \ AUD_MUX(tdm##_name##_sclk_sel, _reg, 0xf, 24, \ CLK_MUX_ROUND_CLOSEST, tdm_sclk_parent_data, 0) #define AUD_TDM_SCLK_PRE_EN(_name, _reg) \ AUD_GATE(tdm##_name##_sclk_pre_en, _reg, 31, \ aud_tdm##_name##_sclk_sel, CLK_SET_RATE_PARENT) #define AUD_TDM_SCLK_POST_EN(_name, _reg) \ AUD_GATE(tdm##_name##_sclk_post_en, _reg, 30, \ aud_tdm##_name##_sclk_pre_en, CLK_SET_RATE_PARENT) #define AUD_TDM_SCLK(_name, _reg) \ AUD_PHASE(tdm##_name##_sclk, _reg, 1, 29, \ aud_tdm##_name##_sclk_post_en, \ CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT) #define AUD_TDM_SCLK_WS(_name, _reg) \ AUD_SCLK_WS(tdm##_name##_sclk, _reg, 1, 29, 28, \ aud_tdm##_name##_sclk_post_en, \ CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT) #define AUD_TDM_LRLCK(_name, _reg) \ AUD_MUX(tdm##_name##_lrclk, _reg, 0xf, 20, \ CLK_MUX_ROUND_CLOSEST, tdm_lrclk_parent_data, 0) /* Pad master clock sources */ static const struct clk_parent_data mclk_pad_ctrl_parent_data[] = { { .name = "aud_mst_a_mclk", .index = -1, }, { .name = "aud_mst_b_mclk", .index = -1, }, { .name = "aud_mst_c_mclk", .index = -1, }, { .name = "aud_mst_d_mclk", .index = -1, }, { .name = "aud_mst_e_mclk", .index = -1, }, { .name = "aud_mst_f_mclk", .index = -1, }, }; /* Pad bit clock sources */ static const struct clk_parent_data sclk_pad_ctrl_parent_data[] = { { .name = "aud_mst_a_sclk", .index = -1, }, { .name = "aud_mst_b_sclk", .index = -1, }, { .name = "aud_mst_c_sclk", .index = -1, }, { .name = "aud_mst_d_sclk", .index = -1, }, { .name = "aud_mst_e_sclk", .index = -1, }, { .name = "aud_mst_f_sclk", .index = -1, }, }; /* Pad sample clock sources */ static const struct clk_parent_data lrclk_pad_ctrl_parent_data[] = { { .name = "aud_mst_a_lrclk", .index = -1, }, { .name = "aud_mst_b_lrclk", .index = -1, }, { .name = "aud_mst_c_lrclk", .index = -1, }, { .name = "aud_mst_d_lrclk", .index = -1, }, { .name = "aud_mst_e_lrclk", .index = -1, }, { .name = "aud_mst_f_lrclk", .index = -1, }, }; #define AUD_TDM_PAD_CTRL(_name, _reg, _shift, _parents) \ AUD_MUX(_name, _reg, 0x7, _shift, 0, _parents, \ CLK_SET_RATE_NO_REPARENT) /* Common Clocks */ static struct clk_regmap ddr_arb = AUD_PCLK_GATE(ddr_arb, AUDIO_CLK_GATE_EN, 0); static struct clk_regmap pdm = AUD_PCLK_GATE(pdm, AUDIO_CLK_GATE_EN, 1); static struct clk_regmap tdmin_a = AUD_PCLK_GATE(tdmin_a, AUDIO_CLK_GATE_EN, 2); static struct clk_regmap tdmin_b = AUD_PCLK_GATE(tdmin_b, AUDIO_CLK_GATE_EN, 3); static struct clk_regmap tdmin_c = AUD_PCLK_GATE(tdmin_c, AUDIO_CLK_GATE_EN, 4); static struct clk_regmap tdmin_lb = AUD_PCLK_GATE(tdmin_lb, AUDIO_CLK_GATE_EN, 5); static struct clk_regmap tdmout_a = AUD_PCLK_GATE(tdmout_a, AUDIO_CLK_GATE_EN, 6); static struct clk_regmap tdmout_b = AUD_PCLK_GATE(tdmout_b, AUDIO_CLK_GATE_EN, 7); static struct clk_regmap tdmout_c = AUD_PCLK_GATE(tdmout_c, AUDIO_CLK_GATE_EN, 8); static struct clk_regmap frddr_a = AUD_PCLK_GATE(frddr_a, AUDIO_CLK_GATE_EN, 9); static struct clk_regmap frddr_b = AUD_PCLK_GATE(frddr_b, AUDIO_CLK_GATE_EN, 10); static struct clk_regmap frddr_c = AUD_PCLK_GATE(frddr_c, AUDIO_CLK_GATE_EN, 11); static struct clk_regmap toddr_a = AUD_PCLK_GATE(toddr_a, AUDIO_CLK_GATE_EN, 12); static struct clk_regmap toddr_b = AUD_PCLK_GATE(toddr_b, AUDIO_CLK_GATE_EN, 13); static struct clk_regmap toddr_c = AUD_PCLK_GATE(toddr_c, AUDIO_CLK_GATE_EN, 14); static struct clk_regmap loopback = AUD_PCLK_GATE(loopback, AUDIO_CLK_GATE_EN, 15); static struct clk_regmap spdifin = AUD_PCLK_GATE(spdifin, AUDIO_CLK_GATE_EN, 16); static struct clk_regmap spdifout = AUD_PCLK_GATE(spdifout, AUDIO_CLK_GATE_EN, 17); static struct clk_regmap resample = AUD_PCLK_GATE(resample, AUDIO_CLK_GATE_EN, 18); static struct clk_regmap power_detect = AUD_PCLK_GATE(power_detect, AUDIO_CLK_GATE_EN, 19); static struct clk_regmap spdifout_clk_sel = AUD_MST_MCLK_MUX(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL); static struct clk_regmap pdm_dclk_sel = AUD_MST_MCLK_MUX(pdm_dclk, AUDIO_CLK_PDMIN_CTRL0); static struct clk_regmap spdifin_clk_sel = AUD_MST_SYS_MUX(spdifin_clk, AUDIO_CLK_SPDIFIN_CTRL); static struct clk_regmap pdm_sysclk_sel = AUD_MST_SYS_MUX(pdm_sysclk, AUDIO_CLK_PDMIN_CTRL1); static struct clk_regmap spdifout_b_clk_sel = AUD_MST_MCLK_MUX(spdifout_b_clk, AUDIO_CLK_SPDIFOUT_B_CTRL); static struct clk_regmap spdifout_clk_div = AUD_MST_MCLK_DIV(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL); static struct clk_regmap pdm_dclk_div = AUD_MST_MCLK_DIV(pdm_dclk, AUDIO_CLK_PDMIN_CTRL0); static struct clk_regmap spdifin_clk_div = AUD_MST_SYS_DIV(spdifin_clk, AUDIO_CLK_SPDIFIN_CTRL); static struct clk_regmap pdm_sysclk_div = AUD_MST_SYS_DIV(pdm_sysclk, AUDIO_CLK_PDMIN_CTRL1); static struct clk_regmap spdifout_b_clk_div = AUD_MST_MCLK_DIV(spdifout_b_clk, AUDIO_CLK_SPDIFOUT_B_CTRL); static struct clk_regmap spdifout_clk = AUD_MST_MCLK_GATE(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL); static struct clk_regmap spdifin_clk = AUD_MST_MCLK_GATE(spdifin_clk, AUDIO_CLK_SPDIFIN_CTRL); static struct clk_regmap pdm_dclk = AUD_MST_MCLK_GATE(pdm_dclk, AUDIO_CLK_PDMIN_CTRL0); static struct clk_regmap pdm_sysclk = AUD_MST_MCLK_GATE(pdm_sysclk, AUDIO_CLK_PDMIN_CTRL1); static struct clk_regmap spdifout_b_clk = AUD_MST_MCLK_GATE(spdifout_b_clk, AUDIO_CLK_SPDIFOUT_B_CTRL); static struct clk_regmap mst_a_sclk_pre_en = AUD_MST_SCLK_PRE_EN(a, AUDIO_MST_A_SCLK_CTRL0); static struct clk_regmap mst_b_sclk_pre_en = AUD_MST_SCLK_PRE_EN(b, AUDIO_MST_B_SCLK_CTRL0); static struct clk_regmap mst_c_sclk_pre_en = AUD_MST_SCLK_PRE_EN(c, AUDIO_MST_C_SCLK_CTRL0); static struct clk_regmap mst_d_sclk_pre_en = AUD_MST_SCLK_PRE_EN(d, AUDIO_MST_D_SCLK_CTRL0); static struct clk_regmap mst_e_sclk_pre_en = AUD_MST_SCLK_PRE_EN(e, AUDIO_MST_E_SCLK_CTRL0); static struct clk_regmap mst_f_sclk_pre_en = AUD_MST_SCLK_PRE_EN(f, AUDIO_MST_F_SCLK_CTRL0); static struct clk_regmap mst_a_sclk_div = AUD_MST_SCLK_DIV(a, AUDIO_MST_A_SCLK_CTRL0); static struct clk_regmap mst_b_sclk_div = AUD_MST_SCLK_DIV(b, AUDIO_MST_B_SCLK_CTRL0); static struct clk_regmap mst_c_sclk_div = AUD_MST_SCLK_DIV(c, AUDIO_MST_C_SCLK_CTRL0); static struct clk_regmap mst_d_sclk_div = AUD_MST_SCLK_DIV(d, AUDIO_MST_D_SCLK_CTRL0); static struct clk_regmap mst_e_sclk_div = AUD_MST_SCLK_DIV(e, AUDIO_MST_E_SCLK_CTRL0); static struct clk_regmap mst_f_sclk_div = AUD_MST_SCLK_DIV(f, AUDIO_MST_F_SCLK_CTRL0); static struct clk_regmap mst_a_sclk_post_en = AUD_MST_SCLK_POST_EN(a, AUDIO_MST_A_SCLK_CTRL0); static struct clk_regmap mst_b_sclk_post_en = AUD_MST_SCLK_POST_EN(b, AUDIO_MST_B_SCLK_CTRL0); static struct clk_regmap mst_c_sclk_post_en = AUD_MST_SCLK_POST_EN(c, AUDIO_MST_C_SCLK_CTRL0); static struct clk_regmap mst_d_sclk_post_en = AUD_MST_SCLK_POST_EN(d, AUDIO_MST_D_SCLK_CTRL0); static struct clk_regmap mst_e_sclk_post_en = AUD_MST_SCLK_POST_EN(e, AUDIO_MST_E_SCLK_CTRL0); static struct clk_regmap mst_f_sclk_post_en = AUD_MST_SCLK_POST_EN(f, AUDIO_MST_F_SCLK_CTRL0); static struct clk_regmap mst_a_sclk = AUD_MST_SCLK(a, AUDIO_MST_A_SCLK_CTRL1); static struct clk_regmap mst_b_sclk = AUD_MST_SCLK(b, AUDIO_MST_B_SCLK_CTRL1); static struct clk_regmap mst_c_sclk = AUD_MST_SCLK(c, AUDIO_MST_C_SCLK_CTRL1); static struct clk_regmap mst_d_sclk = AUD_MST_SCLK(d, AUDIO_MST_D_SCLK_CTRL1); static struct clk_regmap mst_e_sclk = AUD_MST_SCLK(e, AUDIO_MST_E_SCLK_CTRL1); static struct clk_regmap mst_f_sclk = AUD_MST_SCLK(f, AUDIO_MST_F_SCLK_CTRL1); static struct clk_regmap mst_a_lrclk_div = AUD_MST_LRCLK_DIV(a, AUDIO_MST_A_SCLK_CTRL0); static struct clk_regmap mst_b_lrclk_div = AUD_MST_LRCLK_DIV(b, AUDIO_MST_B_SCLK_CTRL0); static struct clk_regmap mst_c_lrclk_div = AUD_MST_LRCLK_DIV(c, AUDIO_MST_C_SCLK_CTRL0); static struct clk_regmap mst_d_lrclk_div = AUD_MST_LRCLK_DIV(d, AUDIO_MST_D_SCLK_CTRL0); static struct clk_regmap mst_e_lrclk_div = AUD_MST_LRCLK_DIV(e, AUDIO_MST_E_SCLK_CTRL0); static struct clk_regmap mst_f_lrclk_div = AUD_MST_LRCLK_DIV(f, AUDIO_MST_F_SCLK_CTRL0); static struct clk_regmap mst_a_lrclk = AUD_MST_LRCLK(a, AUDIO_MST_A_SCLK_CTRL1); static struct clk_regmap mst_b_lrclk = AUD_MST_LRCLK(b, AUDIO_MST_B_SCLK_CTRL1); static struct clk_regmap mst_c_lrclk = AUD_MST_LRCLK(c, AUDIO_MST_C_SCLK_CTRL1); static struct clk_regmap mst_d_lrclk = AUD_MST_LRCLK(d, AUDIO_MST_D_SCLK_CTRL1); static struct clk_regmap mst_e_lrclk = AUD_MST_LRCLK(e, AUDIO_MST_E_SCLK_CTRL1); static struct clk_regmap mst_f_lrclk = AUD_MST_LRCLK(f, AUDIO_MST_F_SCLK_CTRL1); static struct clk_regmap tdmin_a_sclk_sel = AUD_TDM_SCLK_MUX(in_a, AUDIO_CLK_TDMIN_A_CTRL); static struct clk_regmap tdmin_b_sclk_sel = AUD_TDM_SCLK_MUX(in_b, AUDIO_CLK_TDMIN_B_CTRL); static struct clk_regmap tdmin_c_sclk_sel = AUD_TDM_SCLK_MUX(in_c, AUDIO_CLK_TDMIN_C_CTRL); static struct clk_regmap tdmin_lb_sclk_sel = AUD_TDM_SCLK_MUX(in_lb, AUDIO_CLK_TDMIN_LB_CTRL); static struct clk_regmap tdmout_a_sclk_sel = AUD_TDM_SCLK_MUX(out_a, AUDIO_CLK_TDMOUT_A_CTRL); static struct clk_regmap tdmout_b_sclk_sel = AUD_TDM_SCLK_MUX(out_b, AUDIO_CLK_TDMOUT_B_CTRL); static struct clk_regmap tdmout_c_sclk_sel = AUD_TDM_SCLK_MUX(out_c, AUDIO_CLK_TDMOUT_C_CTRL); static struct clk_regmap tdmin_a_sclk_pre_en = AUD_TDM_SCLK_PRE_EN(in_a, AUDIO_CLK_TDMIN_A_CTRL); static struct clk_regmap tdmin_b_sclk_pre_en = AUD_TDM_SCLK_PRE_EN(in_b, AUDIO_CLK_TDMIN_B_CTRL); static struct clk_regmap tdmin_c_sclk_pre_en = AUD_TDM_SCLK_PRE_EN(in_c, AUDIO_CLK_TDMIN_C_CTRL); static struct clk_regmap tdmin_lb_sclk_pre_en = AUD_TDM_SCLK_PRE_EN(in_lb, AUDIO_CLK_TDMIN_LB_CTRL); static struct clk_regmap tdmout_a_sclk_pre_en = AUD_TDM_SCLK_PRE_EN(out_a, AUDIO_CLK_TDMOUT_A_CTRL); static struct clk_regmap tdmout_b_sclk_pre_en = AUD_TDM_SCLK_PRE_EN(out_b, AUDIO_CLK_TDMOUT_B_CTRL); static struct clk_regmap tdmout_c_sclk_pre_en = AUD_TDM_SCLK_PRE_EN(out_c, AUDIO_CLK_TDMOUT_C_CTRL); static struct clk_regmap tdmin_a_sclk_post_en = AUD_TDM_SCLK_POST_EN(in_a, AUDIO_CLK_TDMIN_A_CTRL); static struct clk_regmap tdmin_b_sclk_post_en = AUD_TDM_SCLK_POST_EN(in_b, AUDIO_CLK_TDMIN_B_CTRL); static struct clk_regmap tdmin_c_sclk_post_en = AUD_TDM_SCLK_POST_EN(in_c, AUDIO_CLK_TDMIN_C_CTRL); static struct clk_regmap tdmin_lb_sclk_post_en = AUD_TDM_SCLK_POST_EN(in_lb, AUDIO_CLK_TDMIN_LB_CTRL); static struct clk_regmap tdmout_a_sclk_post_en = AUD_TDM_SCLK_POST_EN(out_a, AUDIO_CLK_TDMOUT_A_CTRL); static struct clk_regmap tdmout_b_sclk_post_en = AUD_TDM_SCLK_POST_EN(out_b, AUDIO_CLK_TDMOUT_B_CTRL); static struct clk_regmap tdmout_c_sclk_post_en = AUD_TDM_SCLK_POST_EN(out_c, AUDIO_CLK_TDMOUT_C_CTRL); static struct clk_regmap tdmin_a_sclk = AUD_TDM_SCLK(in_a, AUDIO_CLK_TDMIN_A_CTRL); static struct clk_regmap tdmin_b_sclk = AUD_TDM_SCLK(in_b, AUDIO_CLK_TDMIN_B_CTRL); static struct clk_regmap tdmin_c_sclk = AUD_TDM_SCLK(in_c, AUDIO_CLK_TDMIN_C_CTRL); static struct clk_regmap tdmin_lb_sclk = AUD_TDM_SCLK(in_lb, AUDIO_CLK_TDMIN_LB_CTRL); static struct clk_regmap tdmin_a_lrclk = AUD_TDM_LRLCK(in_a, AUDIO_CLK_TDMIN_A_CTRL); static struct clk_regmap tdmin_b_lrclk = AUD_TDM_LRLCK(in_b, AUDIO_CLK_TDMIN_B_CTRL); static struct clk_regmap tdmin_c_lrclk = AUD_TDM_LRLCK(in_c, AUDIO_CLK_TDMIN_C_CTRL); static struct clk_regmap tdmin_lb_lrclk = AUD_TDM_LRLCK(in_lb, AUDIO_CLK_TDMIN_LB_CTRL); static struct clk_regmap tdmout_a_lrclk = AUD_TDM_LRLCK(out_a, AUDIO_CLK_TDMOUT_A_CTRL); static struct clk_regmap tdmout_b_lrclk = AUD_TDM_LRLCK(out_b, AUDIO_CLK_TDMOUT_B_CTRL); static struct clk_regmap tdmout_c_lrclk = AUD_TDM_LRLCK(out_c, AUDIO_CLK_TDMOUT_C_CTRL); /* AXG Clocks */ static struct clk_regmap axg_tdmout_a_sclk = AUD_TDM_SCLK(out_a, AUDIO_CLK_TDMOUT_A_CTRL); static struct clk_regmap axg_tdmout_b_sclk = AUD_TDM_SCLK(out_b, AUDIO_CLK_TDMOUT_B_CTRL); static struct clk_regmap axg_tdmout_c_sclk = AUD_TDM_SCLK(out_c, AUDIO_CLK_TDMOUT_C_CTRL); /* AXG/G12A Clocks */ static struct clk_hw axg_aud_top = { .init = &(struct clk_init_data) { /* Provide aud_top signal name on axg and g12a */ .name = "aud_top", .ops = &(const struct clk_ops) {}, .parent_data = &(const struct clk_parent_data) { .fw_name = "pclk", }, .num_parents = 1, }, }; static struct clk_regmap mst_a_mclk_sel = AUD_MST_MCLK_MUX(mst_a_mclk, AUDIO_MCLK_A_CTRL); static struct clk_regmap mst_b_mclk_sel = AUD_MST_MCLK_MUX(mst_b_mclk, AUDIO_MCLK_B_CTRL); static struct clk_regmap mst_c_mclk_sel = AUD_MST_MCLK_MUX(mst_c_mclk, AUDIO_MCLK_C_CTRL); static struct clk_regmap mst_d_mclk_sel = AUD_MST_MCLK_MUX(mst_d_mclk, AUDIO_MCLK_D_CTRL); static struct clk_regmap mst_e_mclk_sel = AUD_MST_MCLK_MUX(mst_e_mclk, AUDIO_MCLK_E_CTRL); static struct clk_regmap mst_f_mclk_sel = AUD_MST_MCLK_MUX(mst_f_mclk, AUDIO_MCLK_F_CTRL); static struct clk_regmap mst_a_mclk_div = AUD_MST_MCLK_DIV(mst_a_mclk, AUDIO_MCLK_A_CTRL); static struct clk_regmap mst_b_mclk_div = AUD_MST_MCLK_DIV(mst_b_mclk, AUDIO_MCLK_B_CTRL); static struct clk_regmap mst_c_mclk_div = AUD_MST_MCLK_DIV(mst_c_mclk, AUDIO_MCLK_C_CTRL); static struct clk_regmap mst_d_mclk_div = AUD_MST_MCLK_DIV(mst_d_mclk, AUDIO_MCLK_D_CTRL); static struct clk_regmap mst_e_mclk_div = AUD_MST_MCLK_DIV(mst_e_mclk, AUDIO_MCLK_E_CTRL); static struct clk_regmap mst_f_mclk_div = AUD_MST_MCLK_DIV(mst_f_mclk, AUDIO_MCLK_F_CTRL); static struct clk_regmap mst_a_mclk = AUD_MST_MCLK_GATE(mst_a_mclk, AUDIO_MCLK_A_CTRL); static struct clk_regmap mst_b_mclk = AUD_MST_MCLK_GATE(mst_b_mclk, AUDIO_MCLK_B_CTRL); static struct clk_regmap mst_c_mclk = AUD_MST_MCLK_GATE(mst_c_mclk, AUDIO_MCLK_C_CTRL); static struct clk_regmap mst_d_mclk = AUD_MST_MCLK_GATE(mst_d_mclk, AUDIO_MCLK_D_CTRL); static struct clk_regmap mst_e_mclk = AUD_MST_MCLK_GATE(mst_e_mclk, AUDIO_MCLK_E_CTRL); static struct clk_regmap mst_f_mclk = AUD_MST_MCLK_GATE(mst_f_mclk, AUDIO_MCLK_F_CTRL); /* G12a clocks */ static struct clk_regmap g12a_tdm_mclk_pad_0 = AUD_TDM_PAD_CTRL( mclk_pad_0, AUDIO_MST_PAD_CTRL0, 0, mclk_pad_ctrl_parent_data); static struct clk_regmap g12a_tdm_mclk_pad_1 = AUD_TDM_PAD_CTRL( mclk_pad_1, AUDIO_MST_PAD_CTRL0, 4, mclk_pad_ctrl_parent_data); static struct clk_regmap g12a_tdm_lrclk_pad_0 = AUD_TDM_PAD_CTRL( lrclk_pad_0, AUDIO_MST_PAD_CTRL1, 16, lrclk_pad_ctrl_parent_data); static struct clk_regmap g12a_tdm_lrclk_pad_1 = AUD_TDM_PAD_CTRL( lrclk_pad_1, AUDIO_MST_PAD_CTRL1, 20, lrclk_pad_ctrl_parent_data); static struct clk_regmap g12a_tdm_lrclk_pad_2 = AUD_TDM_PAD_CTRL( lrclk_pad_2, AUDIO_MST_PAD_CTRL1, 24, lrclk_pad_ctrl_parent_data); static struct clk_regmap g12a_tdm_sclk_pad_0 = AUD_TDM_PAD_CTRL( sclk_pad_0, AUDIO_MST_PAD_CTRL1, 0, sclk_pad_ctrl_parent_data); static struct clk_regmap g12a_tdm_sclk_pad_1 = AUD_TDM_PAD_CTRL( sclk_pad_1, AUDIO_MST_PAD_CTRL1, 4, sclk_pad_ctrl_parent_data); static struct clk_regmap g12a_tdm_sclk_pad_2 = AUD_TDM_PAD_CTRL( sclk_pad_2, AUDIO_MST_PAD_CTRL1, 8, sclk_pad_ctrl_parent_data); static struct clk_regmap g12a_tdmout_a_sclk = AUD_TDM_SCLK_WS(out_a, AUDIO_CLK_TDMOUT_A_CTRL); static struct clk_regmap g12a_tdmout_b_sclk = AUD_TDM_SCLK_WS(out_b, AUDIO_CLK_TDMOUT_B_CTRL); static struct clk_regmap g12a_tdmout_c_sclk = AUD_TDM_SCLK_WS(out_c, AUDIO_CLK_TDMOUT_C_CTRL); static struct clk_regmap toram = AUD_PCLK_GATE(toram, AUDIO_CLK_GATE_EN, 20); static struct clk_regmap spdifout_b = AUD_PCLK_GATE(spdifout_b, AUDIO_CLK_GATE_EN, 21); static struct clk_regmap eqdrc = AUD_PCLK_GATE(eqdrc, AUDIO_CLK_GATE_EN, 22); /* SM1 Clocks */ static struct clk_regmap sm1_clk81_en = { .data = &(struct clk_regmap_gate_data){ .offset = AUDIO_CLK81_EN, .bit_idx = 31, }, .hw.init = &(struct clk_init_data) { .name = "aud_clk81_en", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "pclk", }, .num_parents = 1, }, }; static struct clk_regmap sm1_sysclk_a_div = { .data = &(struct clk_regmap_div_data){ .offset = AUDIO_CLK81_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data) { .name = "aud_sysclk_a_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_clk81_en.hw, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sm1_sysclk_a_en = { .data = &(struct clk_regmap_gate_data){ .offset = AUDIO_CLK81_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "aud_sysclk_a_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_sysclk_a_div.hw, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sm1_sysclk_b_div = { .data = &(struct clk_regmap_div_data){ .offset = AUDIO_CLK81_CTRL, .shift = 16, .width = 8, }, .hw.init = &(struct clk_init_data) { .name = "aud_sysclk_b_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_clk81_en.hw, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sm1_sysclk_b_en = { .data = &(struct clk_regmap_gate_data){ .offset = AUDIO_CLK81_CTRL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "aud_sysclk_b_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_sysclk_b_div.hw, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_hw *sm1_aud_top_parents[] = { &sm1_sysclk_a_en.hw, &sm1_sysclk_b_en.hw, }; static struct clk_regmap sm1_aud_top = { .data = &(struct clk_regmap_mux_data){ .offset = AUDIO_CLK81_CTRL, .mask = 0x1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "aud_top", .ops = &clk_regmap_mux_ops, .parent_hws = sm1_aud_top_parents, .num_parents = ARRAY_SIZE(sm1_aud_top_parents), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap resample_b = AUD_PCLK_GATE(resample_b, AUDIO_CLK_GATE_EN, 26); static struct clk_regmap tovad = AUD_PCLK_GATE(tovad, AUDIO_CLK_GATE_EN, 27); static struct clk_regmap locker = AUD_PCLK_GATE(locker, AUDIO_CLK_GATE_EN, 28); static struct clk_regmap spdifin_lb = AUD_PCLK_GATE(spdifin_lb, AUDIO_CLK_GATE_EN, 29); static struct clk_regmap frddr_d = AUD_PCLK_GATE(frddr_d, AUDIO_CLK_GATE_EN1, 0); static struct clk_regmap toddr_d = AUD_PCLK_GATE(toddr_d, AUDIO_CLK_GATE_EN1, 1); static struct clk_regmap loopback_b = AUD_PCLK_GATE(loopback_b, AUDIO_CLK_GATE_EN1, 2); static struct clk_regmap sm1_mst_a_mclk_sel = AUD_MST_MCLK_MUX(mst_a_mclk, AUDIO_SM1_MCLK_A_CTRL); static struct clk_regmap sm1_mst_b_mclk_sel = AUD_MST_MCLK_MUX(mst_b_mclk, AUDIO_SM1_MCLK_B_CTRL); static struct clk_regmap sm1_mst_c_mclk_sel = AUD_MST_MCLK_MUX(mst_c_mclk, AUDIO_SM1_MCLK_C_CTRL); static struct clk_regmap sm1_mst_d_mclk_sel = AUD_MST_MCLK_MUX(mst_d_mclk, AUDIO_SM1_MCLK_D_CTRL); static struct clk_regmap sm1_mst_e_mclk_sel = AUD_MST_MCLK_MUX(mst_e_mclk, AUDIO_SM1_MCLK_E_CTRL); static struct clk_regmap sm1_mst_f_mclk_sel = AUD_MST_MCLK_MUX(mst_f_mclk, AUDIO_SM1_MCLK_F_CTRL); static struct clk_regmap sm1_mst_a_mclk_div = AUD_MST_MCLK_DIV(mst_a_mclk, AUDIO_SM1_MCLK_A_CTRL); static struct clk_regmap sm1_mst_b_mclk_div = AUD_MST_MCLK_DIV(mst_b_mclk, AUDIO_SM1_MCLK_B_CTRL); static struct clk_regmap sm1_mst_c_mclk_div = AUD_MST_MCLK_DIV(mst_c_mclk, AUDIO_SM1_MCLK_C_CTRL); static struct clk_regmap sm1_mst_d_mclk_div = AUD_MST_MCLK_DIV(mst_d_mclk, AUDIO_SM1_MCLK_D_CTRL); static struct clk_regmap sm1_mst_e_mclk_div = AUD_MST_MCLK_DIV(mst_e_mclk, AUDIO_SM1_MCLK_E_CTRL); static struct clk_regmap sm1_mst_f_mclk_div = AUD_MST_MCLK_DIV(mst_f_mclk, AUDIO_SM1_MCLK_F_CTRL); static struct clk_regmap sm1_mst_a_mclk = AUD_MST_MCLK_GATE(mst_a_mclk, AUDIO_SM1_MCLK_A_CTRL); static struct clk_regmap sm1_mst_b_mclk = AUD_MST_MCLK_GATE(mst_b_mclk, AUDIO_SM1_MCLK_B_CTRL); static struct clk_regmap sm1_mst_c_mclk = AUD_MST_MCLK_GATE(mst_c_mclk, AUDIO_SM1_MCLK_C_CTRL); static struct clk_regmap sm1_mst_d_mclk = AUD_MST_MCLK_GATE(mst_d_mclk, AUDIO_SM1_MCLK_D_CTRL); static struct clk_regmap sm1_mst_e_mclk = AUD_MST_MCLK_GATE(mst_e_mclk, AUDIO_SM1_MCLK_E_CTRL); static struct clk_regmap sm1_mst_f_mclk = AUD_MST_MCLK_GATE(mst_f_mclk, AUDIO_SM1_MCLK_F_CTRL); static struct clk_regmap sm1_tdm_mclk_pad_0 = AUD_TDM_PAD_CTRL( tdm_mclk_pad_0, AUDIO_SM1_MST_PAD_CTRL0, 0, mclk_pad_ctrl_parent_data); static struct clk_regmap sm1_tdm_mclk_pad_1 = AUD_TDM_PAD_CTRL( tdm_mclk_pad_1, AUDIO_SM1_MST_PAD_CTRL0, 4, mclk_pad_ctrl_parent_data); static struct clk_regmap sm1_tdm_lrclk_pad_0 = AUD_TDM_PAD_CTRL( tdm_lrclk_pad_0, AUDIO_SM1_MST_PAD_CTRL1, 16, lrclk_pad_ctrl_parent_data); static struct clk_regmap sm1_tdm_lrclk_pad_1 = AUD_TDM_PAD_CTRL( tdm_lrclk_pad_1, AUDIO_SM1_MST_PAD_CTRL1, 20, lrclk_pad_ctrl_parent_data); static struct clk_regmap sm1_tdm_lrclk_pad_2 = AUD_TDM_PAD_CTRL( tdm_lrclk_pad_2, AUDIO_SM1_MST_PAD_CTRL1, 24, lrclk_pad_ctrl_parent_data); static struct clk_regmap sm1_tdm_sclk_pad_0 = AUD_TDM_PAD_CTRL( tdm_sclk_pad_0, AUDIO_SM1_MST_PAD_CTRL1, 0, sclk_pad_ctrl_parent_data); static struct clk_regmap sm1_tdm_sclk_pad_1 = AUD_TDM_PAD_CTRL( tdm_sclk_pad_1, AUDIO_SM1_MST_PAD_CTRL1, 4, sclk_pad_ctrl_parent_data); static struct clk_regmap sm1_tdm_sclk_pad_2 = AUD_TDM_PAD_CTRL( tdm_sclk_pad_2, AUDIO_SM1_MST_PAD_CTRL1, 8, sclk_pad_ctrl_parent_data); /* * Array of all clocks provided by this provider * The input clocks of the controller will be populated at runtime */ static struct clk_hw *axg_audio_hw_clks[] = { [AUD_CLKID_DDR_ARB] = &ddr_arb.hw, [AUD_CLKID_PDM] = &pdm.hw, [AUD_CLKID_TDMIN_A] = &tdmin_a.hw, [AUD_CLKID_TDMIN_B] = &tdmin_b.hw, [AUD_CLKID_TDMIN_C] = &tdmin_c.hw, [AUD_CLKID_TDMIN_LB] = &tdmin_lb.hw, [AUD_CLKID_TDMOUT_A] = &tdmout_a.hw, [AUD_CLKID_TDMOUT_B] = &tdmout_b.hw, [AUD_CLKID_TDMOUT_C] = &tdmout_c.hw, [AUD_CLKID_FRDDR_A] = &frddr_a.hw, [AUD_CLKID_FRDDR_B] = &frddr_b.hw, [AUD_CLKID_FRDDR_C] = &frddr_c.hw, [AUD_CLKID_TODDR_A] = &toddr_a.hw, [AUD_CLKID_TODDR_B] = &toddr_b.hw, [AUD_CLKID_TODDR_C] = &toddr_c.hw, [AUD_CLKID_LOOPBACK] = &loopback.hw, [AUD_CLKID_SPDIFIN] = &spdifin.hw, [AUD_CLKID_SPDIFOUT] = &spdifout.hw, [AUD_CLKID_RESAMPLE] = &resample.hw, [AUD_CLKID_POWER_DETECT] = &power_detect.hw, [AUD_CLKID_MST_A_MCLK_SEL] = &mst_a_mclk_sel.hw, [AUD_CLKID_MST_B_MCLK_SEL] = &mst_b_mclk_sel.hw, [AUD_CLKID_MST_C_MCLK_SEL] = &mst_c_mclk_sel.hw, [AUD_CLKID_MST_D_MCLK_SEL] = &mst_d_mclk_sel.hw, [AUD_CLKID_MST_E_MCLK_SEL] = &mst_e_mclk_sel.hw, [AUD_CLKID_MST_F_MCLK_SEL] = &mst_f_mclk_sel.hw, [AUD_CLKID_MST_A_MCLK_DIV] = &mst_a_mclk_div.hw, [AUD_CLKID_MST_B_MCLK_DIV] = &mst_b_mclk_div.hw, [AUD_CLKID_MST_C_MCLK_DIV] = &mst_c_mclk_div.hw, [AUD_CLKID_MST_D_MCLK_DIV] = &mst_d_mclk_div.hw, [AUD_CLKID_MST_E_MCLK_DIV] = &mst_e_mclk_div.hw, [AUD_CLKID_MST_F_MCLK_DIV] = &mst_f_mclk_div.hw, [AUD_CLKID_MST_A_MCLK] = &mst_a_mclk.hw, [AUD_CLKID_MST_B_MCLK] = &mst_b_mclk.hw, [AUD_CLKID_MST_C_MCLK] = &mst_c_mclk.hw, [AUD_CLKID_MST_D_MCLK] = &mst_d_mclk.hw, [AUD_CLKID_MST_E_MCLK] = &mst_e_mclk.hw, [AUD_CLKID_MST_F_MCLK] = &mst_f_mclk.hw, [AUD_CLKID_SPDIFOUT_CLK_SEL] = &spdifout_clk_sel.hw, [AUD_CLKID_SPDIFOUT_CLK_DIV] = &spdifout_clk_div.hw, [AUD_CLKID_SPDIFOUT_CLK] = &spdifout_clk.hw, [AUD_CLKID_SPDIFIN_CLK_SEL] = &spdifin_clk_sel.hw, [AUD_CLKID_SPDIFIN_CLK_DIV] = &spdifin_clk_div.hw, [AUD_CLKID_SPDIFIN_CLK] = &spdifin_clk.hw, [AUD_CLKID_PDM_DCLK_SEL] = &pdm_dclk_sel.hw, [AUD_CLKID_PDM_DCLK_DIV] = &pdm_dclk_div.hw, [AUD_CLKID_PDM_DCLK] = &pdm_dclk.hw, [AUD_CLKID_PDM_SYSCLK_SEL] = &pdm_sysclk_sel.hw, [AUD_CLKID_PDM_SYSCLK_DIV] = &pdm_sysclk_div.hw, [AUD_CLKID_PDM_SYSCLK] = &pdm_sysclk.hw, [AUD_CLKID_MST_A_SCLK_PRE_EN] = &mst_a_sclk_pre_en.hw, [AUD_CLKID_MST_B_SCLK_PRE_EN] = &mst_b_sclk_pre_en.hw, [AUD_CLKID_MST_C_SCLK_PRE_EN] = &mst_c_sclk_pre_en.hw, [AUD_CLKID_MST_D_SCLK_PRE_EN] = &mst_d_sclk_pre_en.hw, [AUD_CLKID_MST_E_SCLK_PRE_EN] = &mst_e_sclk_pre_en.hw, [AUD_CLKID_MST_F_SCLK_PRE_EN] = &mst_f_sclk_pre_en.hw, [AUD_CLKID_MST_A_SCLK_DIV] = &mst_a_sclk_div.hw, [AUD_CLKID_MST_B_SCLK_DIV] = &mst_b_sclk_div.hw, [AUD_CLKID_MST_C_SCLK_DIV] = &mst_c_sclk_div.hw, [AUD_CLKID_MST_D_SCLK_DIV] = &mst_d_sclk_div.hw, [AUD_CLKID_MST_E_SCLK_DIV] = &mst_e_sclk_div.hw, [AUD_CLKID_MST_F_SCLK_DIV] = &mst_f_sclk_div.hw, [AUD_CLKID_MST_A_SCLK_POST_EN] = &mst_a_sclk_post_en.hw, [AUD_CLKID_MST_B_SCLK_POST_EN] = &mst_b_sclk_post_en.hw, [AUD_CLKID_MST_C_SCLK_POST_EN] = &mst_c_sclk_post_en.hw, [AUD_CLKID_MST_D_SCLK_POST_EN] = &mst_d_sclk_post_en.hw, [AUD_CLKID_MST_E_SCLK_POST_EN] = &mst_e_sclk_post_en.hw, [AUD_CLKID_MST_F_SCLK_POST_EN] = &mst_f_sclk_post_en.hw, [AUD_CLKID_MST_A_SCLK] = &mst_a_sclk.hw, [AUD_CLKID_MST_B_SCLK] = &mst_b_sclk.hw, [AUD_CLKID_MST_C_SCLK] = &mst_c_sclk.hw, [AUD_CLKID_MST_D_SCLK] = &mst_d_sclk.hw, [AUD_CLKID_MST_E_SCLK] = &mst_e_sclk.hw, [AUD_CLKID_MST_F_SCLK] = &mst_f_sclk.hw, [AUD_CLKID_MST_A_LRCLK_DIV] = &mst_a_lrclk_div.hw, [AUD_CLKID_MST_B_LRCLK_DIV] = &mst_b_lrclk_div.hw, [AUD_CLKID_MST_C_LRCLK_DIV] = &mst_c_lrclk_div.hw, [AUD_CLKID_MST_D_LRCLK_DIV] = &mst_d_lrclk_div.hw, [AUD_CLKID_MST_E_LRCLK_DIV] = &mst_e_lrclk_div.hw, [AUD_CLKID_MST_F_LRCLK_DIV] = &mst_f_lrclk_div.hw, [AUD_CLKID_MST_A_LRCLK] = &mst_a_lrclk.hw, [AUD_CLKID_MST_B_LRCLK] = &mst_b_lrclk.hw, [AUD_CLKID_MST_C_LRCLK] = &mst_c_lrclk.hw, [AUD_CLKID_MST_D_LRCLK] = &mst_d_lrclk.hw, [AUD_CLKID_MST_E_LRCLK] = &mst_e_lrclk.hw, [AUD_CLKID_MST_F_LRCLK] = &mst_f_lrclk.hw, [AUD_CLKID_TDMIN_A_SCLK_SEL] = &tdmin_a_sclk_sel.hw, [AUD_CLKID_TDMIN_B_SCLK_SEL] = &tdmin_b_sclk_sel.hw, [AUD_CLKID_TDMIN_C_SCLK_SEL] = &tdmin_c_sclk_sel.hw, [AUD_CLKID_TDMIN_LB_SCLK_SEL] = &tdmin_lb_sclk_sel.hw, [AUD_CLKID_TDMOUT_A_SCLK_SEL] = &tdmout_a_sclk_sel.hw, [AUD_CLKID_TDMOUT_B_SCLK_SEL] = &tdmout_b_sclk_sel.hw, [AUD_CLKID_TDMOUT_C_SCLK_SEL] = &tdmout_c_sclk_sel.hw, [AUD_CLKID_TDMIN_A_SCLK_PRE_EN] = &tdmin_a_sclk_pre_en.hw, [AUD_CLKID_TDMIN_B_SCLK_PRE_EN] = &tdmin_b_sclk_pre_en.hw, [AUD_CLKID_TDMIN_C_SCLK_PRE_EN] = &tdmin_c_sclk_pre_en.hw, [AUD_CLKID_TDMIN_LB_SCLK_PRE_EN] = &tdmin_lb_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_A_SCLK_PRE_EN] = &tdmout_a_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_B_SCLK_PRE_EN] = &tdmout_b_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_C_SCLK_PRE_EN] = &tdmout_c_sclk_pre_en.hw, [AUD_CLKID_TDMIN_A_SCLK_POST_EN] = &tdmin_a_sclk_post_en.hw, [AUD_CLKID_TDMIN_B_SCLK_POST_EN] = &tdmin_b_sclk_post_en.hw, [AUD_CLKID_TDMIN_C_SCLK_POST_EN] = &tdmin_c_sclk_post_en.hw, [AUD_CLKID_TDMIN_LB_SCLK_POST_EN] = &tdmin_lb_sclk_post_en.hw, [AUD_CLKID_TDMOUT_A_SCLK_POST_EN] = &tdmout_a_sclk_post_en.hw, [AUD_CLKID_TDMOUT_B_SCLK_POST_EN] = &tdmout_b_sclk_post_en.hw, [AUD_CLKID_TDMOUT_C_SCLK_POST_EN] = &tdmout_c_sclk_post_en.hw, [AUD_CLKID_TDMIN_A_SCLK] = &tdmin_a_sclk.hw, [AUD_CLKID_TDMIN_B_SCLK] = &tdmin_b_sclk.hw, [AUD_CLKID_TDMIN_C_SCLK] = &tdmin_c_sclk.hw, [AUD_CLKID_TDMIN_LB_SCLK] = &tdmin_lb_sclk.hw, [AUD_CLKID_TDMOUT_A_SCLK] = &axg_tdmout_a_sclk.hw, [AUD_CLKID_TDMOUT_B_SCLK] = &axg_tdmout_b_sclk.hw, [AUD_CLKID_TDMOUT_C_SCLK] = &axg_tdmout_c_sclk.hw, [AUD_CLKID_TDMIN_A_LRCLK] = &tdmin_a_lrclk.hw, [AUD_CLKID_TDMIN_B_LRCLK] = &tdmin_b_lrclk.hw, [AUD_CLKID_TDMIN_C_LRCLK] = &tdmin_c_lrclk.hw, [AUD_CLKID_TDMIN_LB_LRCLK] = &tdmin_lb_lrclk.hw, [AUD_CLKID_TDMOUT_A_LRCLK] = &tdmout_a_lrclk.hw, [AUD_CLKID_TDMOUT_B_LRCLK] = &tdmout_b_lrclk.hw, [AUD_CLKID_TDMOUT_C_LRCLK] = &tdmout_c_lrclk.hw, [AUD_CLKID_TOP] = &axg_aud_top, }; /* * Array of all G12A clocks provided by this provider * The input clocks of the controller will be populated at runtime */ static struct clk_hw *g12a_audio_hw_clks[] = { [AUD_CLKID_DDR_ARB] = &ddr_arb.hw, [AUD_CLKID_PDM] = &pdm.hw, [AUD_CLKID_TDMIN_A] = &tdmin_a.hw, [AUD_CLKID_TDMIN_B] = &tdmin_b.hw, [AUD_CLKID_TDMIN_C] = &tdmin_c.hw, [AUD_CLKID_TDMIN_LB] = &tdmin_lb.hw, [AUD_CLKID_TDMOUT_A] = &tdmout_a.hw, [AUD_CLKID_TDMOUT_B] = &tdmout_b.hw, [AUD_CLKID_TDMOUT_C] = &tdmout_c.hw, [AUD_CLKID_FRDDR_A] = &frddr_a.hw, [AUD_CLKID_FRDDR_B] = &frddr_b.hw, [AUD_CLKID_FRDDR_C] = &frddr_c.hw, [AUD_CLKID_TODDR_A] = &toddr_a.hw, [AUD_CLKID_TODDR_B] = &toddr_b.hw, [AUD_CLKID_TODDR_C] = &toddr_c.hw, [AUD_CLKID_LOOPBACK] = &loopback.hw, [AUD_CLKID_SPDIFIN] = &spdifin.hw, [AUD_CLKID_SPDIFOUT] = &spdifout.hw, [AUD_CLKID_RESAMPLE] = &resample.hw, [AUD_CLKID_POWER_DETECT] = &power_detect.hw, [AUD_CLKID_SPDIFOUT_B] = &spdifout_b.hw, [AUD_CLKID_MST_A_MCLK_SEL] = &mst_a_mclk_sel.hw, [AUD_CLKID_MST_B_MCLK_SEL] = &mst_b_mclk_sel.hw, [AUD_CLKID_MST_C_MCLK_SEL] = &mst_c_mclk_sel.hw, [AUD_CLKID_MST_D_MCLK_SEL] = &mst_d_mclk_sel.hw, [AUD_CLKID_MST_E_MCLK_SEL] = &mst_e_mclk_sel.hw, [AUD_CLKID_MST_F_MCLK_SEL] = &mst_f_mclk_sel.hw, [AUD_CLKID_MST_A_MCLK_DIV] = &mst_a_mclk_div.hw, [AUD_CLKID_MST_B_MCLK_DIV] = &mst_b_mclk_div.hw, [AUD_CLKID_MST_C_MCLK_DIV] = &mst_c_mclk_div.hw, [AUD_CLKID_MST_D_MCLK_DIV] = &mst_d_mclk_div.hw, [AUD_CLKID_MST_E_MCLK_DIV] = &mst_e_mclk_div.hw, [AUD_CLKID_MST_F_MCLK_DIV] = &mst_f_mclk_div.hw, [AUD_CLKID_MST_A_MCLK] = &mst_a_mclk.hw, [AUD_CLKID_MST_B_MCLK] = &mst_b_mclk.hw, [AUD_CLKID_MST_C_MCLK] = &mst_c_mclk.hw, [AUD_CLKID_MST_D_MCLK] = &mst_d_mclk.hw, [AUD_CLKID_MST_E_MCLK] = &mst_e_mclk.hw, [AUD_CLKID_MST_F_MCLK] = &mst_f_mclk.hw, [AUD_CLKID_SPDIFOUT_CLK_SEL] = &spdifout_clk_sel.hw, [AUD_CLKID_SPDIFOUT_CLK_DIV] = &spdifout_clk_div.hw, [AUD_CLKID_SPDIFOUT_CLK] = &spdifout_clk.hw, [AUD_CLKID_SPDIFOUT_B_CLK_SEL] = &spdifout_b_clk_sel.hw, [AUD_CLKID_SPDIFOUT_B_CLK_DIV] = &spdifout_b_clk_div.hw, [AUD_CLKID_SPDIFOUT_B_CLK] = &spdifout_b_clk.hw, [AUD_CLKID_SPDIFIN_CLK_SEL] = &spdifin_clk_sel.hw, [AUD_CLKID_SPDIFIN_CLK_DIV] = &spdifin_clk_div.hw, [AUD_CLKID_SPDIFIN_CLK] = &spdifin_clk.hw, [AUD_CLKID_PDM_DCLK_SEL] = &pdm_dclk_sel.hw, [AUD_CLKID_PDM_DCLK_DIV] = &pdm_dclk_div.hw, [AUD_CLKID_PDM_DCLK] = &pdm_dclk.hw, [AUD_CLKID_PDM_SYSCLK_SEL] = &pdm_sysclk_sel.hw, [AUD_CLKID_PDM_SYSCLK_DIV] = &pdm_sysclk_div.hw, [AUD_CLKID_PDM_SYSCLK] = &pdm_sysclk.hw, [AUD_CLKID_MST_A_SCLK_PRE_EN] = &mst_a_sclk_pre_en.hw, [AUD_CLKID_MST_B_SCLK_PRE_EN] = &mst_b_sclk_pre_en.hw, [AUD_CLKID_MST_C_SCLK_PRE_EN] = &mst_c_sclk_pre_en.hw, [AUD_CLKID_MST_D_SCLK_PRE_EN] = &mst_d_sclk_pre_en.hw, [AUD_CLKID_MST_E_SCLK_PRE_EN] = &mst_e_sclk_pre_en.hw, [AUD_CLKID_MST_F_SCLK_PRE_EN] = &mst_f_sclk_pre_en.hw, [AUD_CLKID_MST_A_SCLK_DIV] = &mst_a_sclk_div.hw, [AUD_CLKID_MST_B_SCLK_DIV] = &mst_b_sclk_div.hw, [AUD_CLKID_MST_C_SCLK_DIV] = &mst_c_sclk_div.hw, [AUD_CLKID_MST_D_SCLK_DIV] = &mst_d_sclk_div.hw, [AUD_CLKID_MST_E_SCLK_DIV] = &mst_e_sclk_div.hw, [AUD_CLKID_MST_F_SCLK_DIV] = &mst_f_sclk_div.hw, [AUD_CLKID_MST_A_SCLK_POST_EN] = &mst_a_sclk_post_en.hw, [AUD_CLKID_MST_B_SCLK_POST_EN] = &mst_b_sclk_post_en.hw, [AUD_CLKID_MST_C_SCLK_POST_EN] = &mst_c_sclk_post_en.hw, [AUD_CLKID_MST_D_SCLK_POST_EN] = &mst_d_sclk_post_en.hw, [AUD_CLKID_MST_E_SCLK_POST_EN] = &mst_e_sclk_post_en.hw, [AUD_CLKID_MST_F_SCLK_POST_EN] = &mst_f_sclk_post_en.hw, [AUD_CLKID_MST_A_SCLK] = &mst_a_sclk.hw, [AUD_CLKID_MST_B_SCLK] = &mst_b_sclk.hw, [AUD_CLKID_MST_C_SCLK] = &mst_c_sclk.hw, [AUD_CLKID_MST_D_SCLK] = &mst_d_sclk.hw, [AUD_CLKID_MST_E_SCLK] = &mst_e_sclk.hw, [AUD_CLKID_MST_F_SCLK] = &mst_f_sclk.hw, [AUD_CLKID_MST_A_LRCLK_DIV] = &mst_a_lrclk_div.hw, [AUD_CLKID_MST_B_LRCLK_DIV] = &mst_b_lrclk_div.hw, [AUD_CLKID_MST_C_LRCLK_DIV] = &mst_c_lrclk_div.hw, [AUD_CLKID_MST_D_LRCLK_DIV] = &mst_d_lrclk_div.hw, [AUD_CLKID_MST_E_LRCLK_DIV] = &mst_e_lrclk_div.hw, [AUD_CLKID_MST_F_LRCLK_DIV] = &mst_f_lrclk_div.hw, [AUD_CLKID_MST_A_LRCLK] = &mst_a_lrclk.hw, [AUD_CLKID_MST_B_LRCLK] = &mst_b_lrclk.hw, [AUD_CLKID_MST_C_LRCLK] = &mst_c_lrclk.hw, [AUD_CLKID_MST_D_LRCLK] = &mst_d_lrclk.hw, [AUD_CLKID_MST_E_LRCLK] = &mst_e_lrclk.hw, [AUD_CLKID_MST_F_LRCLK] = &mst_f_lrclk.hw, [AUD_CLKID_TDMIN_A_SCLK_SEL] = &tdmin_a_sclk_sel.hw, [AUD_CLKID_TDMIN_B_SCLK_SEL] = &tdmin_b_sclk_sel.hw, [AUD_CLKID_TDMIN_C_SCLK_SEL] = &tdmin_c_sclk_sel.hw, [AUD_CLKID_TDMIN_LB_SCLK_SEL] = &tdmin_lb_sclk_sel.hw, [AUD_CLKID_TDMOUT_A_SCLK_SEL] = &tdmout_a_sclk_sel.hw, [AUD_CLKID_TDMOUT_B_SCLK_SEL] = &tdmout_b_sclk_sel.hw, [AUD_CLKID_TDMOUT_C_SCLK_SEL] = &tdmout_c_sclk_sel.hw, [AUD_CLKID_TDMIN_A_SCLK_PRE_EN] = &tdmin_a_sclk_pre_en.hw, [AUD_CLKID_TDMIN_B_SCLK_PRE_EN] = &tdmin_b_sclk_pre_en.hw, [AUD_CLKID_TDMIN_C_SCLK_PRE_EN] = &tdmin_c_sclk_pre_en.hw, [AUD_CLKID_TDMIN_LB_SCLK_PRE_EN] = &tdmin_lb_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_A_SCLK_PRE_EN] = &tdmout_a_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_B_SCLK_PRE_EN] = &tdmout_b_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_C_SCLK_PRE_EN] = &tdmout_c_sclk_pre_en.hw, [AUD_CLKID_TDMIN_A_SCLK_POST_EN] = &tdmin_a_sclk_post_en.hw, [AUD_CLKID_TDMIN_B_SCLK_POST_EN] = &tdmin_b_sclk_post_en.hw, [AUD_CLKID_TDMIN_C_SCLK_POST_EN] = &tdmin_c_sclk_post_en.hw, [AUD_CLKID_TDMIN_LB_SCLK_POST_EN] = &tdmin_lb_sclk_post_en.hw, [AUD_CLKID_TDMOUT_A_SCLK_POST_EN] = &tdmout_a_sclk_post_en.hw, [AUD_CLKID_TDMOUT_B_SCLK_POST_EN] = &tdmout_b_sclk_post_en.hw, [AUD_CLKID_TDMOUT_C_SCLK_POST_EN] = &tdmout_c_sclk_post_en.hw, [AUD_CLKID_TDMIN_A_SCLK] = &tdmin_a_sclk.hw, [AUD_CLKID_TDMIN_B_SCLK] = &tdmin_b_sclk.hw, [AUD_CLKID_TDMIN_C_SCLK] = &tdmin_c_sclk.hw, [AUD_CLKID_TDMIN_LB_SCLK] = &tdmin_lb_sclk.hw, [AUD_CLKID_TDMOUT_A_SCLK] = &g12a_tdmout_a_sclk.hw, [AUD_CLKID_TDMOUT_B_SCLK] = &g12a_tdmout_b_sclk.hw, [AUD_CLKID_TDMOUT_C_SCLK] = &g12a_tdmout_c_sclk.hw, [AUD_CLKID_TDMIN_A_LRCLK] = &tdmin_a_lrclk.hw, [AUD_CLKID_TDMIN_B_LRCLK] = &tdmin_b_lrclk.hw, [AUD_CLKID_TDMIN_C_LRCLK] = &tdmin_c_lrclk.hw, [AUD_CLKID_TDMIN_LB_LRCLK] = &tdmin_lb_lrclk.hw, [AUD_CLKID_TDMOUT_A_LRCLK] = &tdmout_a_lrclk.hw, [AUD_CLKID_TDMOUT_B_LRCLK] = &tdmout_b_lrclk.hw, [AUD_CLKID_TDMOUT_C_LRCLK] = &tdmout_c_lrclk.hw, [AUD_CLKID_TDM_MCLK_PAD0] = &g12a_tdm_mclk_pad_0.hw, [AUD_CLKID_TDM_MCLK_PAD1] = &g12a_tdm_mclk_pad_1.hw, [AUD_CLKID_TDM_LRCLK_PAD0] = &g12a_tdm_lrclk_pad_0.hw, [AUD_CLKID_TDM_LRCLK_PAD1] = &g12a_tdm_lrclk_pad_1.hw, [AUD_CLKID_TDM_LRCLK_PAD2] = &g12a_tdm_lrclk_pad_2.hw, [AUD_CLKID_TDM_SCLK_PAD0] = &g12a_tdm_sclk_pad_0.hw, [AUD_CLKID_TDM_SCLK_PAD1] = &g12a_tdm_sclk_pad_1.hw, [AUD_CLKID_TDM_SCLK_PAD2] = &g12a_tdm_sclk_pad_2.hw, [AUD_CLKID_TOP] = &axg_aud_top, }; /* * Array of all SM1 clocks provided by this provider * The input clocks of the controller will be populated at runtime */ static struct clk_hw *sm1_audio_hw_clks[] = { [AUD_CLKID_DDR_ARB] = &ddr_arb.hw, [AUD_CLKID_PDM] = &pdm.hw, [AUD_CLKID_TDMIN_A] = &tdmin_a.hw, [AUD_CLKID_TDMIN_B] = &tdmin_b.hw, [AUD_CLKID_TDMIN_C] = &tdmin_c.hw, [AUD_CLKID_TDMIN_LB] = &tdmin_lb.hw, [AUD_CLKID_TDMOUT_A] = &tdmout_a.hw, [AUD_CLKID_TDMOUT_B] = &tdmout_b.hw, [AUD_CLKID_TDMOUT_C] = &tdmout_c.hw, [AUD_CLKID_FRDDR_A] = &frddr_a.hw, [AUD_CLKID_FRDDR_B] = &frddr_b.hw, [AUD_CLKID_FRDDR_C] = &frddr_c.hw, [AUD_CLKID_TODDR_A] = &toddr_a.hw, [AUD_CLKID_TODDR_B] = &toddr_b.hw, [AUD_CLKID_TODDR_C] = &toddr_c.hw, [AUD_CLKID_LOOPBACK] = &loopback.hw, [AUD_CLKID_SPDIFIN] = &spdifin.hw, [AUD_CLKID_SPDIFOUT] = &spdifout.hw, [AUD_CLKID_RESAMPLE] = &resample.hw, [AUD_CLKID_SPDIFOUT_B] = &spdifout_b.hw, [AUD_CLKID_MST_A_MCLK_SEL] = &sm1_mst_a_mclk_sel.hw, [AUD_CLKID_MST_B_MCLK_SEL] = &sm1_mst_b_mclk_sel.hw, [AUD_CLKID_MST_C_MCLK_SEL] = &sm1_mst_c_mclk_sel.hw, [AUD_CLKID_MST_D_MCLK_SEL] = &sm1_mst_d_mclk_sel.hw, [AUD_CLKID_MST_E_MCLK_SEL] = &sm1_mst_e_mclk_sel.hw, [AUD_CLKID_MST_F_MCLK_SEL] = &sm1_mst_f_mclk_sel.hw, [AUD_CLKID_MST_A_MCLK_DIV] = &sm1_mst_a_mclk_div.hw, [AUD_CLKID_MST_B_MCLK_DIV] = &sm1_mst_b_mclk_div.hw, [AUD_CLKID_MST_C_MCLK_DIV] = &sm1_mst_c_mclk_div.hw, [AUD_CLKID_MST_D_MCLK_DIV] = &sm1_mst_d_mclk_div.hw, [AUD_CLKID_MST_E_MCLK_DIV] = &sm1_mst_e_mclk_div.hw, [AUD_CLKID_MST_F_MCLK_DIV] = &sm1_mst_f_mclk_div.hw, [AUD_CLKID_MST_A_MCLK] = &sm1_mst_a_mclk.hw, [AUD_CLKID_MST_B_MCLK] = &sm1_mst_b_mclk.hw, [AUD_CLKID_MST_C_MCLK] = &sm1_mst_c_mclk.hw, [AUD_CLKID_MST_D_MCLK] = &sm1_mst_d_mclk.hw, [AUD_CLKID_MST_E_MCLK] = &sm1_mst_e_mclk.hw, [AUD_CLKID_MST_F_MCLK] = &sm1_mst_f_mclk.hw, [AUD_CLKID_SPDIFOUT_CLK_SEL] = &spdifout_clk_sel.hw, [AUD_CLKID_SPDIFOUT_CLK_DIV] = &spdifout_clk_div.hw, [AUD_CLKID_SPDIFOUT_CLK] = &spdifout_clk.hw, [AUD_CLKID_SPDIFOUT_B_CLK_SEL] = &spdifout_b_clk_sel.hw, [AUD_CLKID_SPDIFOUT_B_CLK_DIV] = &spdifout_b_clk_div.hw, [AUD_CLKID_SPDIFOUT_B_CLK] = &spdifout_b_clk.hw, [AUD_CLKID_SPDIFIN_CLK_SEL] = &spdifin_clk_sel.hw, [AUD_CLKID_SPDIFIN_CLK_DIV] = &spdifin_clk_div.hw, [AUD_CLKID_SPDIFIN_CLK] = &spdifin_clk.hw, [AUD_CLKID_PDM_DCLK_SEL] = &pdm_dclk_sel.hw, [AUD_CLKID_PDM_DCLK_DIV] = &pdm_dclk_div.hw, [AUD_CLKID_PDM_DCLK] = &pdm_dclk.hw, [AUD_CLKID_PDM_SYSCLK_SEL] = &pdm_sysclk_sel.hw, [AUD_CLKID_PDM_SYSCLK_DIV] = &pdm_sysclk_div.hw, [AUD_CLKID_PDM_SYSCLK] = &pdm_sysclk.hw, [AUD_CLKID_MST_A_SCLK_PRE_EN] = &mst_a_sclk_pre_en.hw, [AUD_CLKID_MST_B_SCLK_PRE_EN] = &mst_b_sclk_pre_en.hw, [AUD_CLKID_MST_C_SCLK_PRE_EN] = &mst_c_sclk_pre_en.hw, [AUD_CLKID_MST_D_SCLK_PRE_EN] = &mst_d_sclk_pre_en.hw, [AUD_CLKID_MST_E_SCLK_PRE_EN] = &mst_e_sclk_pre_en.hw, [AUD_CLKID_MST_F_SCLK_PRE_EN] = &mst_f_sclk_pre_en.hw, [AUD_CLKID_MST_A_SCLK_DIV] = &mst_a_sclk_div.hw, [AUD_CLKID_MST_B_SCLK_DIV] = &mst_b_sclk_div.hw, [AUD_CLKID_MST_C_SCLK_DIV] = &mst_c_sclk_div.hw, [AUD_CLKID_MST_D_SCLK_DIV] = &mst_d_sclk_div.hw, [AUD_CLKID_MST_E_SCLK_DIV] = &mst_e_sclk_div.hw, [AUD_CLKID_MST_F_SCLK_DIV] = &mst_f_sclk_div.hw, [AUD_CLKID_MST_A_SCLK_POST_EN] = &mst_a_sclk_post_en.hw, [AUD_CLKID_MST_B_SCLK_POST_EN] = &mst_b_sclk_post_en.hw, [AUD_CLKID_MST_C_SCLK_POST_EN] = &mst_c_sclk_post_en.hw, [AUD_CLKID_MST_D_SCLK_POST_EN] = &mst_d_sclk_post_en.hw, [AUD_CLKID_MST_E_SCLK_POST_EN] = &mst_e_sclk_post_en.hw, [AUD_CLKID_MST_F_SCLK_POST_EN] = &mst_f_sclk_post_en.hw, [AUD_CLKID_MST_A_SCLK] = &mst_a_sclk.hw, [AUD_CLKID_MST_B_SCLK] = &mst_b_sclk.hw, [AUD_CLKID_MST_C_SCLK] = &mst_c_sclk.hw, [AUD_CLKID_MST_D_SCLK] = &mst_d_sclk.hw, [AUD_CLKID_MST_E_SCLK] = &mst_e_sclk.hw, [AUD_CLKID_MST_F_SCLK] = &mst_f_sclk.hw, [AUD_CLKID_MST_A_LRCLK_DIV] = &mst_a_lrclk_div.hw, [AUD_CLKID_MST_B_LRCLK_DIV] = &mst_b_lrclk_div.hw, [AUD_CLKID_MST_C_LRCLK_DIV] = &mst_c_lrclk_div.hw, [AUD_CLKID_MST_D_LRCLK_DIV] = &mst_d_lrclk_div.hw, [AUD_CLKID_MST_E_LRCLK_DIV] = &mst_e_lrclk_div.hw, [AUD_CLKID_MST_F_LRCLK_DIV] = &mst_f_lrclk_div.hw, [AUD_CLKID_MST_A_LRCLK] = &mst_a_lrclk.hw, [AUD_CLKID_MST_B_LRCLK] = &mst_b_lrclk.hw, [AUD_CLKID_MST_C_LRCLK] = &mst_c_lrclk.hw, [AUD_CLKID_MST_D_LRCLK] = &mst_d_lrclk.hw, [AUD_CLKID_MST_E_LRCLK] = &mst_e_lrclk.hw, [AUD_CLKID_MST_F_LRCLK] = &mst_f_lrclk.hw, [AUD_CLKID_TDMIN_A_SCLK_SEL] = &tdmin_a_sclk_sel.hw, [AUD_CLKID_TDMIN_B_SCLK_SEL] = &tdmin_b_sclk_sel.hw, [AUD_CLKID_TDMIN_C_SCLK_SEL] = &tdmin_c_sclk_sel.hw, [AUD_CLKID_TDMIN_LB_SCLK_SEL] = &tdmin_lb_sclk_sel.hw, [AUD_CLKID_TDMOUT_A_SCLK_SEL] = &tdmout_a_sclk_sel.hw, [AUD_CLKID_TDMOUT_B_SCLK_SEL] = &tdmout_b_sclk_sel.hw, [AUD_CLKID_TDMOUT_C_SCLK_SEL] = &tdmout_c_sclk_sel.hw, [AUD_CLKID_TDMIN_A_SCLK_PRE_EN] = &tdmin_a_sclk_pre_en.hw, [AUD_CLKID_TDMIN_B_SCLK_PRE_EN] = &tdmin_b_sclk_pre_en.hw, [AUD_CLKID_TDMIN_C_SCLK_PRE_EN] = &tdmin_c_sclk_pre_en.hw, [AUD_CLKID_TDMIN_LB_SCLK_PRE_EN] = &tdmin_lb_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_A_SCLK_PRE_EN] = &tdmout_a_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_B_SCLK_PRE_EN] = &tdmout_b_sclk_pre_en.hw, [AUD_CLKID_TDMOUT_C_SCLK_PRE_EN] = &tdmout_c_sclk_pre_en.hw, [AUD_CLKID_TDMIN_A_SCLK_POST_EN] = &tdmin_a_sclk_post_en.hw, [AUD_CLKID_TDMIN_B_SCLK_POST_EN] = &tdmin_b_sclk_post_en.hw, [AUD_CLKID_TDMIN_C_SCLK_POST_EN] = &tdmin_c_sclk_post_en.hw, [AUD_CLKID_TDMIN_LB_SCLK_POST_EN] = &tdmin_lb_sclk_post_en.hw, [AUD_CLKID_TDMOUT_A_SCLK_POST_EN] = &tdmout_a_sclk_post_en.hw, [AUD_CLKID_TDMOUT_B_SCLK_POST_EN] = &tdmout_b_sclk_post_en.hw, [AUD_CLKID_TDMOUT_C_SCLK_POST_EN] = &tdmout_c_sclk_post_en.hw, [AUD_CLKID_TDMIN_A_SCLK] = &tdmin_a_sclk.hw, [AUD_CLKID_TDMIN_B_SCLK] = &tdmin_b_sclk.hw, [AUD_CLKID_TDMIN_C_SCLK] = &tdmin_c_sclk.hw, [AUD_CLKID_TDMIN_LB_SCLK] = &tdmin_lb_sclk.hw, [AUD_CLKID_TDMOUT_A_SCLK] = &g12a_tdmout_a_sclk.hw, [AUD_CLKID_TDMOUT_B_SCLK] = &g12a_tdmout_b_sclk.hw, [AUD_CLKID_TDMOUT_C_SCLK] = &g12a_tdmout_c_sclk.hw, [AUD_CLKID_TDMIN_A_LRCLK] = &tdmin_a_lrclk.hw, [AUD_CLKID_TDMIN_B_LRCLK] = &tdmin_b_lrclk.hw, [AUD_CLKID_TDMIN_C_LRCLK] = &tdmin_c_lrclk.hw, [AUD_CLKID_TDMIN_LB_LRCLK] = &tdmin_lb_lrclk.hw, [AUD_CLKID_TDMOUT_A_LRCLK] = &tdmout_a_lrclk.hw, [AUD_CLKID_TDMOUT_B_LRCLK] = &tdmout_b_lrclk.hw, [AUD_CLKID_TDMOUT_C_LRCLK] = &tdmout_c_lrclk.hw, [AUD_CLKID_TDM_MCLK_PAD0] = &sm1_tdm_mclk_pad_0.hw, [AUD_CLKID_TDM_MCLK_PAD1] = &sm1_tdm_mclk_pad_1.hw, [AUD_CLKID_TDM_LRCLK_PAD0] = &sm1_tdm_lrclk_pad_0.hw, [AUD_CLKID_TDM_LRCLK_PAD1] = &sm1_tdm_lrclk_pad_1.hw, [AUD_CLKID_TDM_LRCLK_PAD2] = &sm1_tdm_lrclk_pad_2.hw, [AUD_CLKID_TDM_SCLK_PAD0] = &sm1_tdm_sclk_pad_0.hw, [AUD_CLKID_TDM_SCLK_PAD1] = &sm1_tdm_sclk_pad_1.hw, [AUD_CLKID_TDM_SCLK_PAD2] = &sm1_tdm_sclk_pad_2.hw, [AUD_CLKID_TOP] = &sm1_aud_top.hw, [AUD_CLKID_TORAM] = &toram.hw, [AUD_CLKID_EQDRC] = &eqdrc.hw, [AUD_CLKID_RESAMPLE_B] = &resample_b.hw, [AUD_CLKID_TOVAD] = &tovad.hw, [AUD_CLKID_LOCKER] = &locker.hw, [AUD_CLKID_SPDIFIN_LB] = &spdifin_lb.hw, [AUD_CLKID_FRDDR_D] = &frddr_d.hw, [AUD_CLKID_TODDR_D] = &toddr_d.hw, [AUD_CLKID_LOOPBACK_B] = &loopback_b.hw, [AUD_CLKID_CLK81_EN] = &sm1_clk81_en.hw, [AUD_CLKID_SYSCLK_A_DIV] = &sm1_sysclk_a_div.hw, [AUD_CLKID_SYSCLK_A_EN] = &sm1_sysclk_a_en.hw, [AUD_CLKID_SYSCLK_B_DIV] = &sm1_sysclk_b_div.hw, [AUD_CLKID_SYSCLK_B_EN] = &sm1_sysclk_b_en.hw, }; /* Convenience table to populate regmap in .probe(). */ static struct clk_regmap *const axg_clk_regmaps[] = { &ddr_arb, &pdm, &tdmin_a, &tdmin_b, &tdmin_c, &tdmin_lb, &tdmout_a, &tdmout_b, &tdmout_c, &frddr_a, &frddr_b, &frddr_c, &toddr_a, &toddr_b, &toddr_c, &loopback, &spdifin, &spdifout, &resample, &power_detect, &mst_a_mclk_sel, &mst_b_mclk_sel, &mst_c_mclk_sel, &mst_d_mclk_sel, &mst_e_mclk_sel, &mst_f_mclk_sel, &mst_a_mclk_div, &mst_b_mclk_div, &mst_c_mclk_div, &mst_d_mclk_div, &mst_e_mclk_div, &mst_f_mclk_div, &mst_a_mclk, &mst_b_mclk, &mst_c_mclk, &mst_d_mclk, &mst_e_mclk, &mst_f_mclk, &spdifout_clk_sel, &spdifout_clk_div, &spdifout_clk, &spdifin_clk_sel, &spdifin_clk_div, &spdifin_clk, &pdm_dclk_sel, &pdm_dclk_div, &pdm_dclk, &pdm_sysclk_sel, &pdm_sysclk_div, &pdm_sysclk, &mst_a_sclk_pre_en, &mst_b_sclk_pre_en, &mst_c_sclk_pre_en, &mst_d_sclk_pre_en, &mst_e_sclk_pre_en, &mst_f_sclk_pre_en, &mst_a_sclk_div, &mst_b_sclk_div, &mst_c_sclk_div, &mst_d_sclk_div, &mst_e_sclk_div, &mst_f_sclk_div, &mst_a_sclk_post_en, &mst_b_sclk_post_en, &mst_c_sclk_post_en, &mst_d_sclk_post_en, &mst_e_sclk_post_en, &mst_f_sclk_post_en, &mst_a_sclk, &mst_b_sclk, &mst_c_sclk, &mst_d_sclk, &mst_e_sclk, &mst_f_sclk, &mst_a_lrclk_div, &mst_b_lrclk_div, &mst_c_lrclk_div, &mst_d_lrclk_div, &mst_e_lrclk_div, &mst_f_lrclk_div, &mst_a_lrclk, &mst_b_lrclk, &mst_c_lrclk, &mst_d_lrclk, &mst_e_lrclk, &mst_f_lrclk, &tdmin_a_sclk_sel, &tdmin_b_sclk_sel, &tdmin_c_sclk_sel, &tdmin_lb_sclk_sel, &tdmout_a_sclk_sel, &tdmout_b_sclk_sel, &tdmout_c_sclk_sel, &tdmin_a_sclk_pre_en, &tdmin_b_sclk_pre_en, &tdmin_c_sclk_pre_en, &tdmin_lb_sclk_pre_en, &tdmout_a_sclk_pre_en, &tdmout_b_sclk_pre_en, &tdmout_c_sclk_pre_en, &tdmin_a_sclk_post_en, &tdmin_b_sclk_post_en, &tdmin_c_sclk_post_en, &tdmin_lb_sclk_post_en, &tdmout_a_sclk_post_en, &tdmout_b_sclk_post_en, &tdmout_c_sclk_post_en, &tdmin_a_sclk, &tdmin_b_sclk, &tdmin_c_sclk, &tdmin_lb_sclk, &axg_tdmout_a_sclk, &axg_tdmout_b_sclk, &axg_tdmout_c_sclk, &tdmin_a_lrclk, &tdmin_b_lrclk, &tdmin_c_lrclk, &tdmin_lb_lrclk, &tdmout_a_lrclk, &tdmout_b_lrclk, &tdmout_c_lrclk, }; static struct clk_regmap *const g12a_clk_regmaps[] = { &ddr_arb, &pdm, &tdmin_a, &tdmin_b, &tdmin_c, &tdmin_lb, &tdmout_a, &tdmout_b, &tdmout_c, &frddr_a, &frddr_b, &frddr_c, &toddr_a, &toddr_b, &toddr_c, &loopback, &spdifin, &spdifout, &resample, &power_detect, &spdifout_b, &mst_a_mclk_sel, &mst_b_mclk_sel, &mst_c_mclk_sel, &mst_d_mclk_sel, &mst_e_mclk_sel, &mst_f_mclk_sel, &mst_a_mclk_div, &mst_b_mclk_div, &mst_c_mclk_div, &mst_d_mclk_div, &mst_e_mclk_div, &mst_f_mclk_div, &mst_a_mclk, &mst_b_mclk, &mst_c_mclk, &mst_d_mclk, &mst_e_mclk, &mst_f_mclk, &spdifout_clk_sel, &spdifout_clk_div, &spdifout_clk, &spdifin_clk_sel, &spdifin_clk_div, &spdifin_clk, &pdm_dclk_sel, &pdm_dclk_div, &pdm_dclk, &pdm_sysclk_sel, &pdm_sysclk_div, &pdm_sysclk, &mst_a_sclk_pre_en, &mst_b_sclk_pre_en, &mst_c_sclk_pre_en, &mst_d_sclk_pre_en, &mst_e_sclk_pre_en, &mst_f_sclk_pre_en, &mst_a_sclk_div, &mst_b_sclk_div, &mst_c_sclk_div, &mst_d_sclk_div, &mst_e_sclk_div, &mst_f_sclk_div, &mst_a_sclk_post_en, &mst_b_sclk_post_en, &mst_c_sclk_post_en, &mst_d_sclk_post_en, &mst_e_sclk_post_en, &mst_f_sclk_post_en, &mst_a_sclk, &mst_b_sclk, &mst_c_sclk, &mst_d_sclk, &mst_e_sclk, &mst_f_sclk, &mst_a_lrclk_div, &mst_b_lrclk_div, &mst_c_lrclk_div, &mst_d_lrclk_div, &mst_e_lrclk_div, &mst_f_lrclk_div, &mst_a_lrclk, &mst_b_lrclk, &mst_c_lrclk, &mst_d_lrclk, &mst_e_lrclk, &mst_f_lrclk, &tdmin_a_sclk_sel, &tdmin_b_sclk_sel, &tdmin_c_sclk_sel, &tdmin_lb_sclk_sel, &tdmout_a_sclk_sel, &tdmout_b_sclk_sel, &tdmout_c_sclk_sel, &tdmin_a_sclk_pre_en, &tdmin_b_sclk_pre_en, &tdmin_c_sclk_pre_en, &tdmin_lb_sclk_pre_en, &tdmout_a_sclk_pre_en, &tdmout_b_sclk_pre_en, &tdmout_c_sclk_pre_en, &tdmin_a_sclk_post_en, &tdmin_b_sclk_post_en, &tdmin_c_sclk_post_en, &tdmin_lb_sclk_post_en, &tdmout_a_sclk_post_en, &tdmout_b_sclk_post_en, &tdmout_c_sclk_post_en, &tdmin_a_sclk, &tdmin_b_sclk, &tdmin_c_sclk, &tdmin_lb_sclk, &g12a_tdmout_a_sclk, &g12a_tdmout_b_sclk, &g12a_tdmout_c_sclk, &tdmin_a_lrclk, &tdmin_b_lrclk, &tdmin_c_lrclk, &tdmin_lb_lrclk, &tdmout_a_lrclk, &tdmout_b_lrclk, &tdmout_c_lrclk, &spdifout_b_clk_sel, &spdifout_b_clk_div, &spdifout_b_clk, &g12a_tdm_mclk_pad_0, &g12a_tdm_mclk_pad_1, &g12a_tdm_lrclk_pad_0, &g12a_tdm_lrclk_pad_1, &g12a_tdm_lrclk_pad_2, &g12a_tdm_sclk_pad_0, &g12a_tdm_sclk_pad_1, &g12a_tdm_sclk_pad_2, &toram, &eqdrc, }; static struct clk_regmap *const sm1_clk_regmaps[] = { &ddr_arb, &pdm, &tdmin_a, &tdmin_b, &tdmin_c, &tdmin_lb, &tdmout_a, &tdmout_b, &tdmout_c, &frddr_a, &frddr_b, &frddr_c, &toddr_a, &toddr_b, &toddr_c, &loopback, &spdifin, &spdifout, &resample, &spdifout_b, &sm1_mst_a_mclk_sel, &sm1_mst_b_mclk_sel, &sm1_mst_c_mclk_sel, &sm1_mst_d_mclk_sel, &sm1_mst_e_mclk_sel, &sm1_mst_f_mclk_sel, &sm1_mst_a_mclk_div, &sm1_mst_b_mclk_div, &sm1_mst_c_mclk_div, &sm1_mst_d_mclk_div, &sm1_mst_e_mclk_div, &sm1_mst_f_mclk_div, &sm1_mst_a_mclk, &sm1_mst_b_mclk, &sm1_mst_c_mclk, &sm1_mst_d_mclk, &sm1_mst_e_mclk, &sm1_mst_f_mclk, &spdifout_clk_sel, &spdifout_clk_div, &spdifout_clk, &spdifin_clk_sel, &spdifin_clk_div, &spdifin_clk, &pdm_dclk_sel, &pdm_dclk_div, &pdm_dclk, &pdm_sysclk_sel, &pdm_sysclk_div, &pdm_sysclk, &mst_a_sclk_pre_en, &mst_b_sclk_pre_en, &mst_c_sclk_pre_en, &mst_d_sclk_pre_en, &mst_e_sclk_pre_en, &mst_f_sclk_pre_en, &mst_a_sclk_div, &mst_b_sclk_div, &mst_c_sclk_div, &mst_d_sclk_div, &mst_e_sclk_div, &mst_f_sclk_div, &mst_a_sclk_post_en, &mst_b_sclk_post_en, &mst_c_sclk_post_en, &mst_d_sclk_post_en, &mst_e_sclk_post_en, &mst_f_sclk_post_en, &mst_a_sclk, &mst_b_sclk, &mst_c_sclk, &mst_d_sclk, &mst_e_sclk, &mst_f_sclk, &mst_a_lrclk_div, &mst_b_lrclk_div, &mst_c_lrclk_div, &mst_d_lrclk_div, &mst_e_lrclk_div, &mst_f_lrclk_div, &mst_a_lrclk, &mst_b_lrclk, &mst_c_lrclk, &mst_d_lrclk, &mst_e_lrclk, &mst_f_lrclk, &tdmin_a_sclk_sel, &tdmin_b_sclk_sel, &tdmin_c_sclk_sel, &tdmin_lb_sclk_sel, &tdmout_a_sclk_sel, &tdmout_b_sclk_sel, &tdmout_c_sclk_sel, &tdmin_a_sclk_pre_en, &tdmin_b_sclk_pre_en, &tdmin_c_sclk_pre_en, &tdmin_lb_sclk_pre_en, &tdmout_a_sclk_pre_en, &tdmout_b_sclk_pre_en, &tdmout_c_sclk_pre_en, &tdmin_a_sclk_post_en, &tdmin_b_sclk_post_en, &tdmin_c_sclk_post_en, &tdmin_lb_sclk_post_en, &tdmout_a_sclk_post_en, &tdmout_b_sclk_post_en, &tdmout_c_sclk_post_en, &tdmin_a_sclk, &tdmin_b_sclk, &tdmin_c_sclk, &tdmin_lb_sclk, &g12a_tdmout_a_sclk, &g12a_tdmout_b_sclk, &g12a_tdmout_c_sclk, &tdmin_a_lrclk, &tdmin_b_lrclk, &tdmin_c_lrclk, &tdmin_lb_lrclk, &tdmout_a_lrclk, &tdmout_b_lrclk, &tdmout_c_lrclk, &spdifout_b_clk_sel, &spdifout_b_clk_div, &spdifout_b_clk, &sm1_tdm_mclk_pad_0, &sm1_tdm_mclk_pad_1, &sm1_tdm_lrclk_pad_0, &sm1_tdm_lrclk_pad_1, &sm1_tdm_lrclk_pad_2, &sm1_tdm_sclk_pad_0, &sm1_tdm_sclk_pad_1, &sm1_tdm_sclk_pad_2, &sm1_aud_top, &toram, &eqdrc, &resample_b, &tovad, &locker, &spdifin_lb, &frddr_d, &toddr_d, &loopback_b, &sm1_clk81_en, &sm1_sysclk_a_div, &sm1_sysclk_a_en, &sm1_sysclk_b_div, &sm1_sysclk_b_en, }; struct axg_audio_reset_data { struct reset_controller_dev rstc; struct regmap *map; unsigned int offset; }; static void axg_audio_reset_reg_and_bit(struct axg_audio_reset_data *rst, unsigned long id, unsigned int *reg, unsigned int *bit) { unsigned int stride = regmap_get_reg_stride(rst->map); *reg = (id / (stride * BITS_PER_BYTE)) * stride; *reg += rst->offset; *bit = id % (stride * BITS_PER_BYTE); } static int axg_audio_reset_update(struct reset_controller_dev *rcdev, unsigned long id, bool assert) { struct axg_audio_reset_data *rst = container_of(rcdev, struct axg_audio_reset_data, rstc); unsigned int offset, bit; axg_audio_reset_reg_and_bit(rst, id, &offset, &bit); regmap_update_bits(rst->map, offset, BIT(bit), assert ? BIT(bit) : 0); return 0; } static int axg_audio_reset_status(struct reset_controller_dev *rcdev, unsigned long id) { struct axg_audio_reset_data *rst = container_of(rcdev, struct axg_audio_reset_data, rstc); unsigned int val, offset, bit; axg_audio_reset_reg_and_bit(rst, id, &offset, &bit); regmap_read(rst->map, offset, &val); return !!(val & BIT(bit)); } static int axg_audio_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) { return axg_audio_reset_update(rcdev, id, true); } static int axg_audio_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) { return axg_audio_reset_update(rcdev, id, false); } static int axg_audio_reset_toggle(struct reset_controller_dev *rcdev, unsigned long id) { int ret; ret = axg_audio_reset_assert(rcdev, id); if (ret) return ret; return axg_audio_reset_deassert(rcdev, id); } static const struct reset_control_ops axg_audio_rstc_ops = { .assert = axg_audio_reset_assert, .deassert = axg_audio_reset_deassert, .reset = axg_audio_reset_toggle, .status = axg_audio_reset_status, }; static const struct regmap_config axg_audio_regmap_cfg = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, .max_register = AUDIO_CLK_SPDIFOUT_B_CTRL, }; struct audioclk_data { struct clk_regmap *const *regmap_clks; unsigned int regmap_clk_num; struct meson_clk_hw_data hw_clks; unsigned int reset_offset; unsigned int reset_num; }; static int axg_audio_clkc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; const struct audioclk_data *data; struct axg_audio_reset_data *rst; struct regmap *map; void __iomem *regs; struct clk_hw *hw; struct clk *clk; int ret, i; data = of_device_get_match_data(dev); if (!data) return -EINVAL; regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(regs)) return PTR_ERR(regs); map = devm_regmap_init_mmio(dev, regs, &axg_audio_regmap_cfg); if (IS_ERR(map)) { dev_err(dev, "failed to init regmap: %ld\n", PTR_ERR(map)); return PTR_ERR(map); } /* Get the mandatory peripheral clock */ clk = devm_clk_get_enabled(dev, "pclk"); if (IS_ERR(clk)) return PTR_ERR(clk); ret = device_reset(dev); if (ret) { dev_err_probe(dev, ret, "failed to reset device\n"); return ret; } /* Populate regmap for the regmap backed clocks */ for (i = 0; i < data->regmap_clk_num; i++) data->regmap_clks[i]->map = map; /* Take care to skip the registered input clocks */ for (i = AUD_CLKID_DDR_ARB; i < data->hw_clks.num; i++) { const char *name; hw = data->hw_clks.hws[i]; /* array might be sparse */ if (!hw) continue; name = hw->init->name; ret = devm_clk_hw_register(dev, hw); if (ret) { dev_err(dev, "failed to register clock %s\n", name); return ret; } } ret = devm_of_clk_add_hw_provider(dev, meson_clk_hw_get, (void *)&data->hw_clks); if (ret) return ret; /* Stop here if there is no reset */ if (!data->reset_num) return 0; rst = devm_kzalloc(dev, sizeof(*rst), GFP_KERNEL); if (!rst) return -ENOMEM; rst->map = map; rst->offset = data->reset_offset; rst->rstc.nr_resets = data->reset_num; rst->rstc.ops = &axg_audio_rstc_ops; rst->rstc.of_node = dev->of_node; rst->rstc.owner = THIS_MODULE; return devm_reset_controller_register(dev, &rst->rstc); } static const struct audioclk_data axg_audioclk_data = { .regmap_clks = axg_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(axg_clk_regmaps), .hw_clks = { .hws = axg_audio_hw_clks, .num = ARRAY_SIZE(axg_audio_hw_clks), }, }; static const struct audioclk_data g12a_audioclk_data = { .regmap_clks = g12a_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(g12a_clk_regmaps), .hw_clks = { .hws = g12a_audio_hw_clks, .num = ARRAY_SIZE(g12a_audio_hw_clks), }, .reset_offset = AUDIO_SW_RESET, .reset_num = 26, }; static const struct audioclk_data sm1_audioclk_data = { .regmap_clks = sm1_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(sm1_clk_regmaps), .hw_clks = { .hws = sm1_audio_hw_clks, .num = ARRAY_SIZE(sm1_audio_hw_clks), }, .reset_offset = AUDIO_SM1_SW_RESET0, .reset_num = 39, }; static const struct of_device_id clkc_match_table[] = { { .compatible = "amlogic,axg-audio-clkc", .data = &axg_audioclk_data }, { .compatible = "amlogic,g12a-audio-clkc", .data = &g12a_audioclk_data }, { .compatible = "amlogic,sm1-audio-clkc", .data = &sm1_audioclk_data }, {} }; MODULE_DEVICE_TABLE(of, clkc_match_table); static struct platform_driver axg_audio_driver = { .probe = axg_audio_clkc_probe, .driver = { .name = "axg-audio-clkc", .of_match_table = clkc_match_table, }, }; module_platform_driver(axg_audio_driver); MODULE_DESCRIPTION("Amlogic AXG/G12A/SM1 Audio Clock driver"); MODULE_AUTHOR("Jerome Brunet <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/axg-audio.c
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) /* * Copyright (c) 2016 BayLibre, SAS. * Author: Neil Armstrong <[email protected]> */ #include <linux/platform_device.h> #include <linux/mfd/syscon.h> #include <linux/module.h> #include "meson-aoclk.h" #include "clk-regmap.h" #include "clk-dualdiv.h" #include <dt-bindings/clock/gxbb-aoclkc.h> #include <dt-bindings/reset/gxbb-aoclkc.h> /* AO Configuration Clock registers offsets */ #define AO_RTI_PWR_CNTL_REG1 0x0c #define AO_RTI_PWR_CNTL_REG0 0x10 #define AO_RTI_GEN_CNTL_REG0 0x40 #define AO_OSCIN_CNTL 0x58 #define AO_CRT_CLK_CNTL1 0x68 #define AO_RTC_ALT_CLK_CNTL0 0x94 #define AO_RTC_ALT_CLK_CNTL1 0x98 #define GXBB_AO_GATE(_name, _bit) \ static struct clk_regmap _name##_ao = { \ .data = &(struct clk_regmap_gate_data) { \ .offset = AO_RTI_GEN_CNTL_REG0, \ .bit_idx = (_bit), \ }, \ .hw.init = &(struct clk_init_data) { \ .name = #_name "_ao", \ .ops = &clk_regmap_gate_ops, \ .parent_data = &(const struct clk_parent_data) { \ .fw_name = "mpeg-clk", \ }, \ .num_parents = 1, \ .flags = CLK_IGNORE_UNUSED, \ }, \ } GXBB_AO_GATE(remote, 0); GXBB_AO_GATE(i2c_master, 1); GXBB_AO_GATE(i2c_slave, 2); GXBB_AO_GATE(uart1, 3); GXBB_AO_GATE(uart2, 5); GXBB_AO_GATE(ir_blaster, 6); static struct clk_regmap ao_cts_oscin = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTI_PWR_CNTL_REG0, .bit_idx = 6, }, .hw.init = &(struct clk_init_data){ .name = "ao_cts_oscin", .ops = &clk_regmap_gate_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap ao_32k_pre = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTC_ALT_CLK_CNTL0, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "ao_32k_pre", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &ao_cts_oscin.hw }, .num_parents = 1, }, }; static const struct meson_clk_dualdiv_param gxbb_32k_div_table[] = { { .dual = 1, .n1 = 733, .m1 = 8, .n2 = 732, .m2 = 11, }, {} }; static struct clk_regmap ao_32k_div = { .data = &(struct meson_clk_dualdiv_data){ .n1 = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 0, .width = 12, }, .n2 = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 12, .width = 12, }, .m1 = { .reg_off = AO_RTC_ALT_CLK_CNTL1, .shift = 0, .width = 12, }, .m2 = { .reg_off = AO_RTC_ALT_CLK_CNTL1, .shift = 12, .width = 12, }, .dual = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 28, .width = 1, }, .table = gxbb_32k_div_table, }, .hw.init = &(struct clk_init_data){ .name = "ao_32k_div", .ops = &meson_clk_dualdiv_ops, .parent_hws = (const struct clk_hw *[]) { &ao_32k_pre.hw }, .num_parents = 1, }, }; static struct clk_regmap ao_32k_sel = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTC_ALT_CLK_CNTL1, .mask = 0x1, .shift = 24, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "ao_32k_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &ao_32k_div.hw, &ao_32k_pre.hw }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap ao_32k = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTC_ALT_CLK_CNTL0, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "ao_32k", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &ao_32k_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap ao_cts_rtc_oscin = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTI_PWR_CNTL_REG0, .mask = 0x7, .shift = 10, .table = (u32[]){ 1, 2, 3, 4 }, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "ao_cts_rtc_oscin", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "ext-32k-0", }, { .fw_name = "ext-32k-1", }, { .fw_name = "ext-32k-2", }, { .hw = &ao_32k.hw }, }, .num_parents = 4, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap ao_clk81 = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTI_PWR_CNTL_REG0, .mask = 0x1, .shift = 0, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "ao_clk81", .ops = &clk_regmap_mux_ro_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "mpeg-clk", }, { .hw = &ao_cts_rtc_oscin.hw }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap ao_cts_cec = { .data = &(struct clk_regmap_mux_data) { .offset = AO_CRT_CLK_CNTL1, .mask = 0x1, .shift = 27, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "ao_cts_cec", .ops = &clk_regmap_mux_ops, /* * FIXME: The 'fixme' parent obviously does not exist. * * ATM, CCF won't call get_parent() if num_parents is 1. It * does not allow NULL as a parent name either. * * On this particular mux, we only know the input #1 parent * but, on boot, unknown input #0 is set, so it is critical * to call .get_parent() on it * * Until CCF gets fixed, adding this fake parent that won't * ever be registered should work around the problem */ .parent_data = (const struct clk_parent_data []) { { .name = "fixme", .index = -1, }, { .hw = &ao_cts_rtc_oscin.hw }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static const unsigned int gxbb_aoclk_reset[] = { [RESET_AO_REMOTE] = 16, [RESET_AO_I2C_MASTER] = 18, [RESET_AO_I2C_SLAVE] = 19, [RESET_AO_UART1] = 17, [RESET_AO_UART2] = 22, [RESET_AO_IR_BLASTER] = 23, }; static struct clk_regmap *gxbb_aoclk[] = { &remote_ao, &i2c_master_ao, &i2c_slave_ao, &uart1_ao, &uart2_ao, &ir_blaster_ao, &ao_cts_oscin, &ao_32k_pre, &ao_32k_div, &ao_32k_sel, &ao_32k, &ao_cts_rtc_oscin, &ao_clk81, &ao_cts_cec, }; static struct clk_hw *gxbb_aoclk_hw_clks[] = { [CLKID_AO_REMOTE] = &remote_ao.hw, [CLKID_AO_I2C_MASTER] = &i2c_master_ao.hw, [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao.hw, [CLKID_AO_UART1] = &uart1_ao.hw, [CLKID_AO_UART2] = &uart2_ao.hw, [CLKID_AO_IR_BLASTER] = &ir_blaster_ao.hw, [CLKID_AO_CEC_32K] = &ao_cts_cec.hw, [CLKID_AO_CTS_OSCIN] = &ao_cts_oscin.hw, [CLKID_AO_32K_PRE] = &ao_32k_pre.hw, [CLKID_AO_32K_DIV] = &ao_32k_div.hw, [CLKID_AO_32K_SEL] = &ao_32k_sel.hw, [CLKID_AO_32K] = &ao_32k.hw, [CLKID_AO_CTS_RTC_OSCIN] = &ao_cts_rtc_oscin.hw, [CLKID_AO_CLK81] = &ao_clk81.hw, }; static const struct meson_aoclk_data gxbb_aoclkc_data = { .reset_reg = AO_RTI_GEN_CNTL_REG0, .num_reset = ARRAY_SIZE(gxbb_aoclk_reset), .reset = gxbb_aoclk_reset, .num_clks = ARRAY_SIZE(gxbb_aoclk), .clks = gxbb_aoclk, .hw_clks = { .hws = gxbb_aoclk_hw_clks, .num = ARRAY_SIZE(gxbb_aoclk_hw_clks), }, }; static const struct of_device_id gxbb_aoclkc_match_table[] = { { .compatible = "amlogic,meson-gx-aoclkc", .data = &gxbb_aoclkc_data, }, { } }; MODULE_DEVICE_TABLE(of, gxbb_aoclkc_match_table); static struct platform_driver gxbb_aoclkc_driver = { .probe = meson_aoclkc_probe, .driver = { .name = "gxbb-aoclkc", .of_match_table = gxbb_aoclkc_match_table, }, }; module_platform_driver(gxbb_aoclkc_driver); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/gxbb-aoclk.c
// SPDX-License-Identifier: (GPL-2.0 OR MIT) /* * Copyright (c) 2018 BayLibre, SAS. * Author: Jerome Brunet <[email protected]> * * Sample clock generator divider: * This HW divider gates with value 0 but is otherwise a zero based divider: * * val >= 1 * divider = val + 1 * * The duty cycle may also be set for the LR clock variant. The duty cycle * ratio is: * * hi = [0 - val] * duty_cycle = (1 + hi) / (1 + val) */ #include <linux/clk-provider.h> #include <linux/module.h> #include "clk-regmap.h" #include "sclk-div.h" static inline struct meson_sclk_div_data * meson_sclk_div_data(struct clk_regmap *clk) { return (struct meson_sclk_div_data *)clk->data; } static int sclk_div_maxval(struct meson_sclk_div_data *sclk) { return (1 << sclk->div.width) - 1; } static int sclk_div_maxdiv(struct meson_sclk_div_data *sclk) { return sclk_div_maxval(sclk) + 1; } static int sclk_div_getdiv(struct clk_hw *hw, unsigned long rate, unsigned long prate, int maxdiv) { int div = DIV_ROUND_CLOSEST_ULL((u64)prate, rate); return clamp(div, 2, maxdiv); } static int sclk_div_bestdiv(struct clk_hw *hw, unsigned long rate, unsigned long *prate, struct meson_sclk_div_data *sclk) { struct clk_hw *parent = clk_hw_get_parent(hw); int bestdiv = 0, i; unsigned long maxdiv, now, parent_now; unsigned long best = 0, best_parent = 0; if (!rate) rate = 1; maxdiv = sclk_div_maxdiv(sclk); if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) return sclk_div_getdiv(hw, rate, *prate, maxdiv); /* * The maximum divider we can use without overflowing * unsigned long in rate * i below */ maxdiv = min(ULONG_MAX / rate, maxdiv); for (i = 2; i <= maxdiv; i++) { /* * It's the most ideal case if the requested rate can be * divided from parent clock without needing to change * parent rate, so return the divider immediately. */ if (rate * i == *prate) return i; parent_now = clk_hw_round_rate(parent, rate * i); now = DIV_ROUND_UP_ULL((u64)parent_now, i); if (abs(rate - now) < abs(rate - best)) { bestdiv = i; best = now; best_parent = parent_now; } } if (!bestdiv) bestdiv = sclk_div_maxdiv(sclk); else *prate = best_parent; return bestdiv; } static int sclk_div_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); int div; div = sclk_div_bestdiv(hw, req->rate, &req->best_parent_rate, sclk); req->rate = DIV_ROUND_UP_ULL((u64)req->best_parent_rate, div); return 0; } static void sclk_apply_ratio(struct clk_regmap *clk, struct meson_sclk_div_data *sclk) { unsigned int hi = DIV_ROUND_CLOSEST(sclk->cached_div * sclk->cached_duty.num, sclk->cached_duty.den); if (hi) hi -= 1; meson_parm_write(clk->map, &sclk->hi, hi); } static int sclk_div_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); if (MESON_PARM_APPLICABLE(&sclk->hi)) { memcpy(&sclk->cached_duty, duty, sizeof(*duty)); sclk_apply_ratio(clk, sclk); } return 0; } static int sclk_div_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); int hi; if (!MESON_PARM_APPLICABLE(&sclk->hi)) { duty->num = 1; duty->den = 2; return 0; } hi = meson_parm_read(clk->map, &sclk->hi); duty->num = hi + 1; duty->den = sclk->cached_div; return 0; } static void sclk_apply_divider(struct clk_regmap *clk, struct meson_sclk_div_data *sclk) { if (MESON_PARM_APPLICABLE(&sclk->hi)) sclk_apply_ratio(clk, sclk); meson_parm_write(clk->map, &sclk->div, sclk->cached_div - 1); } static int sclk_div_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long prate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); unsigned long maxdiv = sclk_div_maxdiv(sclk); sclk->cached_div = sclk_div_getdiv(hw, rate, prate, maxdiv); if (clk_hw_is_enabled(hw)) sclk_apply_divider(clk, sclk); return 0; } static unsigned long sclk_div_recalc_rate(struct clk_hw *hw, unsigned long prate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); return DIV_ROUND_UP_ULL((u64)prate, sclk->cached_div); } static int sclk_div_enable(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); sclk_apply_divider(clk, sclk); return 0; } static void sclk_div_disable(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); meson_parm_write(clk->map, &sclk->div, 0); } static int sclk_div_is_enabled(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); if (meson_parm_read(clk->map, &sclk->div)) return 1; return 0; } static int sclk_div_init(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); unsigned int val; val = meson_parm_read(clk->map, &sclk->div); /* if the divider is initially disabled, assume max */ if (!val) sclk->cached_div = sclk_div_maxdiv(sclk); else sclk->cached_div = val + 1; sclk_div_get_duty_cycle(hw, &sclk->cached_duty); return 0; } const struct clk_ops meson_sclk_div_ops = { .recalc_rate = sclk_div_recalc_rate, .determine_rate = sclk_div_determine_rate, .set_rate = sclk_div_set_rate, .enable = sclk_div_enable, .disable = sclk_div_disable, .is_enabled = sclk_div_is_enabled, .get_duty_cycle = sclk_div_get_duty_cycle, .set_duty_cycle = sclk_div_set_duty_cycle, .init = sclk_div_init, }; EXPORT_SYMBOL_GPL(meson_sclk_div_ops); MODULE_DESCRIPTION("Amlogic Sample divider driver"); MODULE_AUTHOR("Jerome Brunet <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/sclk-div.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2018 BayLibre, SAS. * Author: Jerome Brunet <[email protected]> */ #include <linux/module.h> #include "clk-regmap.h" static int clk_regmap_gate_endisable(struct clk_hw *hw, int enable) { struct clk_regmap *clk = to_clk_regmap(hw); struct clk_regmap_gate_data *gate = clk_get_regmap_gate_data(clk); int set = gate->flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0; set ^= enable; return regmap_update_bits(clk->map, gate->offset, BIT(gate->bit_idx), set ? BIT(gate->bit_idx) : 0); } static int clk_regmap_gate_enable(struct clk_hw *hw) { return clk_regmap_gate_endisable(hw, 1); } static void clk_regmap_gate_disable(struct clk_hw *hw) { clk_regmap_gate_endisable(hw, 0); } static int clk_regmap_gate_is_enabled(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct clk_regmap_gate_data *gate = clk_get_regmap_gate_data(clk); unsigned int val; regmap_read(clk->map, gate->offset, &val); if (gate->flags & CLK_GATE_SET_TO_DISABLE) val ^= BIT(gate->bit_idx); val &= BIT(gate->bit_idx); return val ? 1 : 0; } const struct clk_ops clk_regmap_gate_ops = { .enable = clk_regmap_gate_enable, .disable = clk_regmap_gate_disable, .is_enabled = clk_regmap_gate_is_enabled, }; EXPORT_SYMBOL_GPL(clk_regmap_gate_ops); const struct clk_ops clk_regmap_gate_ro_ops = { .is_enabled = clk_regmap_gate_is_enabled, }; EXPORT_SYMBOL_GPL(clk_regmap_gate_ro_ops); static unsigned long clk_regmap_div_recalc_rate(struct clk_hw *hw, unsigned long prate) { struct clk_regmap *clk = to_clk_regmap(hw); struct clk_regmap_div_data *div = clk_get_regmap_div_data(clk); unsigned int val; int ret; ret = regmap_read(clk->map, div->offset, &val); if (ret) /* Gives a hint that something is wrong */ return 0; val >>= div->shift; val &= clk_div_mask(div->width); return divider_recalc_rate(hw, prate, val, div->table, div->flags, div->width); } static int clk_regmap_div_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_regmap *clk = to_clk_regmap(hw); struct clk_regmap_div_data *div = clk_get_regmap_div_data(clk); unsigned int val; int ret; /* if read only, just return current value */ if (div->flags & CLK_DIVIDER_READ_ONLY) { ret = regmap_read(clk->map, div->offset, &val); if (ret) return ret; val >>= div->shift; val &= clk_div_mask(div->width); return divider_ro_determine_rate(hw, req, div->table, div->width, div->flags, val); } return divider_determine_rate(hw, req, div->table, div->width, div->flags); } static int clk_regmap_div_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct clk_regmap_div_data *div = clk_get_regmap_div_data(clk); unsigned int val; int ret; ret = divider_get_val(rate, parent_rate, div->table, div->width, div->flags); if (ret < 0) return ret; val = (unsigned int)ret << div->shift; return regmap_update_bits(clk->map, div->offset, clk_div_mask(div->width) << div->shift, val); }; /* Would prefer clk_regmap_div_ro_ops but clashes with qcom */ const struct clk_ops clk_regmap_divider_ops = { .recalc_rate = clk_regmap_div_recalc_rate, .determine_rate = clk_regmap_div_determine_rate, .set_rate = clk_regmap_div_set_rate, }; EXPORT_SYMBOL_GPL(clk_regmap_divider_ops); const struct clk_ops clk_regmap_divider_ro_ops = { .recalc_rate = clk_regmap_div_recalc_rate, .determine_rate = clk_regmap_div_determine_rate, }; EXPORT_SYMBOL_GPL(clk_regmap_divider_ro_ops); static u8 clk_regmap_mux_get_parent(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct clk_regmap_mux_data *mux = clk_get_regmap_mux_data(clk); unsigned int val; int ret; ret = regmap_read(clk->map, mux->offset, &val); if (ret) return ret; val >>= mux->shift; val &= mux->mask; return clk_mux_val_to_index(hw, mux->table, mux->flags, val); } static int clk_regmap_mux_set_parent(struct clk_hw *hw, u8 index) { struct clk_regmap *clk = to_clk_regmap(hw); struct clk_regmap_mux_data *mux = clk_get_regmap_mux_data(clk); unsigned int val = clk_mux_index_to_val(mux->table, mux->flags, index); return regmap_update_bits(clk->map, mux->offset, mux->mask << mux->shift, val << mux->shift); } static int clk_regmap_mux_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_regmap *clk = to_clk_regmap(hw); struct clk_regmap_mux_data *mux = clk_get_regmap_mux_data(clk); return clk_mux_determine_rate_flags(hw, req, mux->flags); } const struct clk_ops clk_regmap_mux_ops = { .get_parent = clk_regmap_mux_get_parent, .set_parent = clk_regmap_mux_set_parent, .determine_rate = clk_regmap_mux_determine_rate, }; EXPORT_SYMBOL_GPL(clk_regmap_mux_ops); const struct clk_ops clk_regmap_mux_ro_ops = { .get_parent = clk_regmap_mux_get_parent, }; EXPORT_SYMBOL_GPL(clk_regmap_mux_ro_ops); MODULE_DESCRIPTION("Amlogic regmap backed clock driver"); MODULE_AUTHOR("Jerome Brunet <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/clk-regmap.c
// SPDX-License-Identifier: GPL-2.0+ /* * Amlogic Meson8 DDR clock controller * * Copyright (C) 2019 Martin Blumenstingl <[email protected]> */ #include <dt-bindings/clock/meson8-ddr-clkc.h> #include <linux/clk-provider.h> #include <linux/platform_device.h> #include "clk-regmap.h" #include "clk-pll.h" #define AM_DDR_PLL_CNTL 0x00 #define AM_DDR_PLL_CNTL1 0x04 #define AM_DDR_PLL_CNTL2 0x08 #define AM_DDR_PLL_CNTL3 0x0c #define AM_DDR_PLL_CNTL4 0x10 #define AM_DDR_PLL_STS 0x14 #define DDR_CLK_CNTL 0x18 #define DDR_CLK_STS 0x1c static struct clk_regmap meson8_ddr_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = AM_DDR_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = AM_DDR_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = AM_DDR_PLL_CNTL, .shift = 9, .width = 5, }, .l = { .reg_off = AM_DDR_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = AM_DDR_PLL_CNTL, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "ddr_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap meson8_ddr_pll = { .data = &(struct clk_regmap_div_data){ .offset = AM_DDR_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "ddr_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &meson8_ddr_pll_dco.hw }, .num_parents = 1, }, }; static struct clk_hw_onecell_data meson8_ddr_clk_hw_onecell_data = { .hws = { [DDR_CLKID_DDR_PLL_DCO] = &meson8_ddr_pll_dco.hw, [DDR_CLKID_DDR_PLL] = &meson8_ddr_pll.hw, }, .num = 2, }; static struct clk_regmap *const meson8_ddr_clk_regmaps[] = { &meson8_ddr_pll_dco, &meson8_ddr_pll, }; static const struct regmap_config meson8_ddr_clkc_regmap_config = { .reg_bits = 8, .val_bits = 32, .reg_stride = 4, .max_register = DDR_CLK_STS, }; static int meson8_ddr_clkc_probe(struct platform_device *pdev) { struct regmap *regmap; void __iomem *base; struct clk_hw *hw; int ret, i; base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) return PTR_ERR(base); regmap = devm_regmap_init_mmio(&pdev->dev, base, &meson8_ddr_clkc_regmap_config); if (IS_ERR(regmap)) return PTR_ERR(regmap); /* Populate regmap */ for (i = 0; i < ARRAY_SIZE(meson8_ddr_clk_regmaps); i++) meson8_ddr_clk_regmaps[i]->map = regmap; /* Register all clks */ for (i = 0; i < meson8_ddr_clk_hw_onecell_data.num; i++) { hw = meson8_ddr_clk_hw_onecell_data.hws[i]; ret = devm_clk_hw_register(&pdev->dev, hw); if (ret) { dev_err(&pdev->dev, "Clock registration failed\n"); return ret; } } return devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_onecell_get, &meson8_ddr_clk_hw_onecell_data); } static const struct of_device_id meson8_ddr_clkc_match_table[] = { { .compatible = "amlogic,meson8-ddr-clkc" }, { .compatible = "amlogic,meson8b-ddr-clkc" }, { /* sentinel */ } }; static struct platform_driver meson8_ddr_clkc_driver = { .probe = meson8_ddr_clkc_probe, .driver = { .name = "meson8-ddr-clkc", .of_match_table = meson8_ddr_clkc_match_table, }, }; builtin_platform_driver(meson8_ddr_clkc_driver);
linux-master
drivers/clk/meson/meson8-ddr.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2018 BayLibre, SAS. * Author: Neil Armstrong <[email protected]> */ #include <linux/clk-provider.h> #include <linux/module.h> #include "clk-regmap.h" #include "vid-pll-div.h" static inline struct meson_vid_pll_div_data * meson_vid_pll_div_data(struct clk_regmap *clk) { return (struct meson_vid_pll_div_data *)clk->data; } /* * This vid_pll divided is a fully programmable fractionnal divider to * achieve complex video clock rates. * * Here are provided the commonly used fraction values provided by Amlogic. */ struct vid_pll_div { unsigned int shift_val; unsigned int shift_sel; unsigned int divider; unsigned int multiplier; }; #define VID_PLL_DIV(_val, _sel, _ft, _fb) \ { \ .shift_val = (_val), \ .shift_sel = (_sel), \ .divider = (_ft), \ .multiplier = (_fb), \ } static const struct vid_pll_div vid_pll_div_table[] = { VID_PLL_DIV(0x0aaa, 0, 2, 1), /* 2/1 => /2 */ VID_PLL_DIV(0x5294, 2, 5, 2), /* 5/2 => /2.5 */ VID_PLL_DIV(0x0db6, 0, 3, 1), /* 3/1 => /3 */ VID_PLL_DIV(0x36cc, 1, 7, 2), /* 7/2 => /3.5 */ VID_PLL_DIV(0x6666, 2, 15, 4), /* 15/4 => /3.75 */ VID_PLL_DIV(0x0ccc, 0, 4, 1), /* 4/1 => /4 */ VID_PLL_DIV(0x739c, 2, 5, 1), /* 5/1 => /5 */ VID_PLL_DIV(0x0e38, 0, 6, 1), /* 6/1 => /6 */ VID_PLL_DIV(0x0000, 3, 25, 4), /* 25/4 => /6.25 */ VID_PLL_DIV(0x3c78, 1, 7, 1), /* 7/1 => /7 */ VID_PLL_DIV(0x78f0, 2, 15, 2), /* 15/2 => /7.5 */ VID_PLL_DIV(0x0fc0, 0, 12, 1), /* 12/1 => /12 */ VID_PLL_DIV(0x3f80, 1, 14, 1), /* 14/1 => /14 */ VID_PLL_DIV(0x7f80, 2, 15, 1), /* 15/1 => /15 */ }; #define to_meson_vid_pll_div(_hw) \ container_of(_hw, struct meson_vid_pll_div, hw) static const struct vid_pll_div *_get_table_val(unsigned int shift_val, unsigned int shift_sel) { int i; for (i = 0 ; i < ARRAY_SIZE(vid_pll_div_table) ; ++i) { if (vid_pll_div_table[i].shift_val == shift_val && vid_pll_div_table[i].shift_sel == shift_sel) return &vid_pll_div_table[i]; } return NULL; } static unsigned long meson_vid_pll_div_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_vid_pll_div_data *pll_div = meson_vid_pll_div_data(clk); const struct vid_pll_div *div; div = _get_table_val(meson_parm_read(clk->map, &pll_div->val), meson_parm_read(clk->map, &pll_div->sel)); if (!div || !div->divider) { pr_debug("%s: Invalid config value for vid_pll_div\n", __func__); return 0; } return DIV_ROUND_UP_ULL(parent_rate * div->multiplier, div->divider); } const struct clk_ops meson_vid_pll_div_ro_ops = { .recalc_rate = meson_vid_pll_div_recalc_rate, }; EXPORT_SYMBOL_GPL(meson_vid_pll_div_ro_ops); MODULE_DESCRIPTION("Amlogic video pll divider driver"); MODULE_AUTHOR("Neil Armstrong <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/vid-pll-div.c
// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (c) 2023 Neil Armstrong <[email protected]> */ #include <linux/of_device.h> #include <linux/clk-provider.h> #include <linux/module.h> #include "meson-clkc-utils.h" struct clk_hw *meson_clk_hw_get(struct of_phandle_args *clkspec, void *clk_hw_data) { const struct meson_clk_hw_data *data = clk_hw_data; unsigned int idx = clkspec->args[0]; if (idx >= data->num) { pr_err("%s: invalid index %u\n", __func__, idx); return ERR_PTR(-EINVAL); } return data->hws[idx]; } EXPORT_SYMBOL_GPL(meson_clk_hw_get); MODULE_LICENSE("GPL");
linux-master
drivers/clk/meson/meson-clkc-utils.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2015 Endless Mobile, Inc. * Author: Carlo Caione <[email protected]> * * Copyright (c) 2016 BayLibre, Inc. * Michael Turquette <[email protected]> */ #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/init.h> #include <linux/mfd/syscon.h> #include <linux/of_address.h> #include <linux/reset-controller.h> #include <linux/slab.h> #include <linux/regmap.h> #include "meson8b.h" #include "clk-regmap.h" #include "meson-clkc-utils.h" #include "clk-pll.h" #include "clk-mpll.h" #include <dt-bindings/clock/meson8b-clkc.h> #include <dt-bindings/reset/amlogic,meson8b-clkc-reset.h> static DEFINE_SPINLOCK(meson_clk_lock); struct meson8b_clk_reset { struct reset_controller_dev reset; struct regmap *regmap; }; static const struct pll_params_table sys_pll_params_table[] = { PLL_PARAMS(50, 1), PLL_PARAMS(51, 1), PLL_PARAMS(52, 1), PLL_PARAMS(53, 1), PLL_PARAMS(54, 1), PLL_PARAMS(55, 1), PLL_PARAMS(56, 1), PLL_PARAMS(57, 1), PLL_PARAMS(58, 1), PLL_PARAMS(59, 1), PLL_PARAMS(60, 1), PLL_PARAMS(61, 1), PLL_PARAMS(62, 1), PLL_PARAMS(63, 1), PLL_PARAMS(64, 1), PLL_PARAMS(65, 1), PLL_PARAMS(66, 1), PLL_PARAMS(67, 1), PLL_PARAMS(68, 1), PLL_PARAMS(84, 1), { /* sentinel */ }, }; static struct clk_regmap meson8b_fixed_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_MPLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_MPLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_MPLL_CNTL, .shift = 9, .width = 5, }, .frac = { .reg_off = HHI_MPLL_CNTL2, .shift = 0, .width = 12, }, .l = { .reg_off = HHI_MPLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_MPLL_CNTL, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", .name = "xtal", .index = -1, }, .num_parents = 1, }, }; static struct clk_regmap meson8b_fixed_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fixed_pll_dco.hw }, .num_parents = 1, /* * This clock won't ever change at runtime so * CLK_SET_RATE_PARENT is not required */ }, }; static struct clk_fixed_factor hdmi_pll_dco_in = { .mult = 2, .div = 1, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_dco_in", .ops = &clk_fixed_factor_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", .index = -1, }, .num_parents = 1, }, }; /* * Taken from the vendor driver for the 2970/2975MHz (both only differ in the * FRAC part in HHI_VID_PLL_CNTL2) where these values are identical for Meson8, * Meson8b and Meson8m2. This doubles the input (or output - it's not clear * which one but the result is the same) clock. The vendor driver additionally * has the following comment about: "optimise HPLL VCO 2.97GHz performance". */ static const struct reg_sequence meson8b_hdmi_pll_init_regs[] = { { .reg = HHI_VID_PLL_CNTL2, .def = 0x69c84000 }, { .reg = HHI_VID_PLL_CNTL3, .def = 0x8a46c023 }, { .reg = HHI_VID_PLL_CNTL4, .def = 0x4123b100 }, { .reg = HHI_VID_PLL_CNTL5, .def = 0x00012385 }, { .reg = HHI_VID2_PLL_CNTL2, .def = 0x0430a800 }, }; static const struct pll_params_table hdmi_pll_params_table[] = { PLL_PARAMS(40, 1), PLL_PARAMS(42, 1), PLL_PARAMS(44, 1), PLL_PARAMS(45, 1), PLL_PARAMS(49, 1), PLL_PARAMS(52, 1), PLL_PARAMS(54, 1), PLL_PARAMS(56, 1), PLL_PARAMS(59, 1), PLL_PARAMS(60, 1), PLL_PARAMS(61, 1), PLL_PARAMS(62, 1), PLL_PARAMS(64, 1), PLL_PARAMS(66, 1), PLL_PARAMS(68, 1), PLL_PARAMS(71, 1), PLL_PARAMS(82, 1), { /* sentinel */ } }; static struct clk_regmap meson8b_hdmi_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_VID_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_VID_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_VID_PLL_CNTL, .shift = 10, .width = 5, }, .frac = { .reg_off = HHI_VID_PLL_CNTL2, .shift = 0, .width = 12, }, .l = { .reg_off = HHI_VID_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_VID_PLL_CNTL, .shift = 29, .width = 1, }, .table = hdmi_pll_params_table, .init_regs = meson8b_hdmi_pll_init_regs, .init_count = ARRAY_SIZE(meson8b_hdmi_pll_init_regs), }, .hw.init = &(struct clk_init_data){ /* sometimes also called "HPLL" or "HPLL PLL" */ .name = "hdmi_pll_dco", .ops = &meson_clk_pll_ops, .parent_hws = (const struct clk_hw *[]) { &hdmi_pll_dco_in.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_hdmi_pll_lvds_out = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VID_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_lvds_out", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_hdmi_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_hdmi_pll_hdmi_out = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VID_PLL_CNTL, .shift = 18, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_hdmi_out", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_hdmi_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_sys_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 9, .width = 5, }, .l = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 29, .width = 1, }, .table = sys_pll_params_table, }, .hw.init = &(struct clk_init_data){ .name = "sys_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", .name = "xtal", .index = -1, }, .num_parents = 1, }, }; static struct clk_regmap meson8b_sys_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "sys_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_sys_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_fclk_div2_div = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "fclk_div2_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_fclk_div2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 27, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fclk_div2_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_fclk_div3_div = { .mult = 1, .div = 3, .hw.init = &(struct clk_init_data){ .name = "fclk_div3_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_fclk_div3 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 28, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div3", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fclk_div3_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_fclk_div4_div = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "fclk_div4_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_fclk_div4 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 29, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div4", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fclk_div4_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_fclk_div5_div = { .mult = 1, .div = 5, .hw.init = &(struct clk_init_data){ .name = "fclk_div5_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_fclk_div5 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div5", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fclk_div5_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_fclk_div7_div = { .mult = 1, .div = 7, .hw.init = &(struct clk_init_data){ .name = "fclk_div7_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_fclk_div7 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div7", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fclk_div7_div.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_mpll_prediv = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPLL_CNTL5, .shift = 12, .width = 1, }, .hw.init = &(struct clk_init_data){ .name = "mpll_prediv", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_mpll0_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL7, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL7, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL7, .shift = 16, .width = 9, }, .ssen = { .reg_off = HHI_MPLL_CNTL, .shift = 25, .width = 1, }, .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data){ .name = "mpll0_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_mpll0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL7, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mpll0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_mpll1_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL8, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL8, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL8, .shift = 16, .width = 9, }, .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data){ .name = "mpll1_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_mpll1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL8, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mpll1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_mpll2_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL9, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL9, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL9, .shift = 16, .width = 9, }, .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data){ .name = "mpll2_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_mpll2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL9, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mpll2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_clk81[] = { 6, 5, 7 }; static struct clk_regmap meson8b_mpeg_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MPEG_CLK_CNTL, .mask = 0x7, .shift = 12, .table = mux_table_clk81, }, .hw.init = &(struct clk_init_data){ .name = "mpeg_clk_sel", .ops = &clk_regmap_mux_ro_ops, /* * FIXME bits 14:12 selects from 8 possible parents: * xtal, 1'b0 (wtf), fclk_div7, mpll_clkout1, mpll_clkout2, * fclk_div4, fclk_div3, fclk_div5 */ .parent_hws = (const struct clk_hw *[]) { &meson8b_fclk_div3.hw, &meson8b_fclk_div4.hw, &meson8b_fclk_div5.hw, }, .num_parents = 3, }, }; static struct clk_regmap meson8b_mpeg_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPEG_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mpeg_clk_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mpeg_clk_sel.hw }, .num_parents = 1, }, }; static struct clk_regmap meson8b_clk81 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPEG_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "clk81", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mpeg_clk_div.hw }, .num_parents = 1, .flags = CLK_IS_CRITICAL, }, }; static struct clk_regmap meson8b_cpu_in_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x1, .shift = 0, }, .hw.init = &(struct clk_init_data){ .name = "cpu_in_sel", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data[]) { { .fw_name = "xtal", .name = "xtal", .index = -1, }, { .hw = &meson8b_sys_pll.hw, }, }, .num_parents = 2, .flags = (CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT), }, }; static struct clk_fixed_factor meson8b_cpu_in_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "cpu_in_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_in_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_cpu_in_div3 = { .mult = 1, .div = 3, .hw.init = &(struct clk_init_data){ .name = "cpu_in_div3", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_in_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_div_table cpu_scale_table[] = { { .val = 1, .div = 4 }, { .val = 2, .div = 6 }, { .val = 3, .div = 8 }, { .val = 4, .div = 10 }, { .val = 5, .div = 12 }, { .val = 6, .div = 14 }, { .val = 7, .div = 16 }, { .val = 8, .div = 18 }, { /* sentinel */ }, }; static struct clk_regmap meson8b_cpu_scale_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .shift = 20, .width = 10, .table = cpu_scale_table, .flags = CLK_DIVIDER_ALLOW_ZERO, }, .hw.init = &(struct clk_init_data){ .name = "cpu_scale_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_in_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_cpu_scale_out_sel[] = { 0, 1, 3 }; static struct clk_regmap meson8b_cpu_scale_out_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x3, .shift = 2, .table = mux_table_cpu_scale_out_sel, }, .hw.init = &(struct clk_init_data){ .name = "cpu_scale_out_sel", .ops = &clk_regmap_mux_ops, /* * NOTE: We are skipping the parent with value 0x2 (which is * meson8b_cpu_in_div3) because it results in a duty cycle of * 33% which makes the system unstable and can result in a * lockup of the whole system. */ .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_in_sel.hw, &meson8b_cpu_in_div2.hw, &meson8b_cpu_scale_div.hw, }, .num_parents = 3, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cpu_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x1, .shift = 7, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data[]) { { .fw_name = "xtal", .name = "xtal", .index = -1, }, { .hw = &meson8b_cpu_scale_out_sel.hw, }, }, .num_parents = 2, .flags = (CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT | CLK_IS_CRITICAL), }, }; static struct clk_regmap meson8b_nand_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_NAND_CLK_CNTL, .mask = 0x7, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "nand_clk_sel", .ops = &clk_regmap_mux_ops, /* FIXME all other parents are unknown: */ .parent_data = (const struct clk_parent_data[]) { { .hw = &meson8b_fclk_div4.hw, }, { .hw = &meson8b_fclk_div3.hw, }, { .hw = &meson8b_fclk_div5.hw, }, { .hw = &meson8b_fclk_div7.hw, }, { .fw_name = "xtal", .name = "xtal", .index = -1, }, }, .num_parents = 5, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_nand_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_NAND_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "nand_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_nand_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_nand_clk_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_NAND_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "nand_clk_gate", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_nand_clk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_cpu_clk_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_cpu_clk_div3 = { .mult = 1, .div = 3, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_div3", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_cpu_clk_div4 = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_cpu_clk_div5 = { .mult = 1, .div = 5, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_div5", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_cpu_clk_div6 = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_cpu_clk_div7 = { .mult = 1, .div = 7, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_div7", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor meson8b_cpu_clk_div8 = { .mult = 1, .div = 8, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_div8", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk.hw }, .num_parents = 1, }, }; static u32 mux_table_apb[] = { 1, 2, 3, 4, 5, 6, 7 }; static struct clk_regmap meson8b_apb_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .mask = 0x7, .shift = 3, .table = mux_table_apb, }, .hw.init = &(struct clk_init_data){ .name = "apb_clk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk_div2.hw, &meson8b_cpu_clk_div3.hw, &meson8b_cpu_clk_div4.hw, &meson8b_cpu_clk_div5.hw, &meson8b_cpu_clk_div6.hw, &meson8b_cpu_clk_div7.hw, &meson8b_cpu_clk_div8.hw, }, .num_parents = 7, }, }; static struct clk_regmap meson8b_apb_clk_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 16, .flags = CLK_GATE_SET_TO_DISABLE, }, .hw.init = &(struct clk_init_data){ .name = "apb_clk_dis", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_apb_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_periph_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .mask = 0x7, .shift = 6, }, .hw.init = &(struct clk_init_data){ .name = "periph_clk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk_div2.hw, &meson8b_cpu_clk_div3.hw, &meson8b_cpu_clk_div4.hw, &meson8b_cpu_clk_div5.hw, &meson8b_cpu_clk_div6.hw, &meson8b_cpu_clk_div7.hw, &meson8b_cpu_clk_div8.hw, }, .num_parents = 7, }, }; static struct clk_regmap meson8b_periph_clk_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 17, .flags = CLK_GATE_SET_TO_DISABLE, }, .hw.init = &(struct clk_init_data){ .name = "periph_clk_dis", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_periph_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_axi[] = { 1, 2, 3, 4, 5, 6, 7 }; static struct clk_regmap meson8b_axi_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .mask = 0x7, .shift = 9, .table = mux_table_axi, }, .hw.init = &(struct clk_init_data){ .name = "axi_clk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk_div2.hw, &meson8b_cpu_clk_div3.hw, &meson8b_cpu_clk_div4.hw, &meson8b_cpu_clk_div5.hw, &meson8b_cpu_clk_div6.hw, &meson8b_cpu_clk_div7.hw, &meson8b_cpu_clk_div8.hw, }, .num_parents = 7, }, }; static struct clk_regmap meson8b_axi_clk_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 18, .flags = CLK_GATE_SET_TO_DISABLE, }, .hw.init = &(struct clk_init_data){ .name = "axi_clk_dis", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_axi_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_l2_dram_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .mask = 0x7, .shift = 12, }, .hw.init = &(struct clk_init_data){ .name = "l2_dram_clk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cpu_clk_div2.hw, &meson8b_cpu_clk_div3.hw, &meson8b_cpu_clk_div4.hw, &meson8b_cpu_clk_div5.hw, &meson8b_cpu_clk_div6.hw, &meson8b_cpu_clk_div7.hw, &meson8b_cpu_clk_div8.hw, }, .num_parents = 7, }, }; static struct clk_regmap meson8b_l2_dram_clk_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 19, .flags = CLK_GATE_SET_TO_DISABLE, }, .hw.init = &(struct clk_init_data){ .name = "l2_dram_clk_dis", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_l2_dram_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* also called LVDS_CLK_EN */ static struct clk_regmap meson8b_vid_pll_lvds_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_DIVIDER_CNTL, .bit_idx = 11, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll_lvds_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_hdmi_pll_lvds_out.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vid_pll_in_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_DIVIDER_CNTL, .mask = 0x1, .shift = 15, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll_in_sel", .ops = &clk_regmap_mux_ops, /* * TODO: depending on the SoC there is also a second parent: * Meson8: unknown * Meson8b: hdmi_pll_dco * Meson8m2: vid2_pll */ .parent_hws = (const struct clk_hw *[]) { &meson8b_vid_pll_lvds_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vid_pll_in_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_DIVIDER_CNTL, .bit_idx = 16, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll_in_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vid_pll_in_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vid_pll_pre_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VID_DIVIDER_CNTL, .shift = 4, .width = 3, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll_pre_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vid_pll_in_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vid_pll_post_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VID_DIVIDER_CNTL, .shift = 12, .width = 3, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll_post_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vid_pll_pre_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vid_pll = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_DIVIDER_CNTL, .mask = 0x3, .shift = 8, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll", .ops = &clk_regmap_mux_ops, /* TODO: parent 0x2 is vid_pll_pre_div_mult7_div2 */ .parent_hws = (const struct clk_hw *[]) { &meson8b_vid_pll_pre_div.hw, &meson8b_vid_pll_post_div.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vid_pll_final_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VID_CLK_DIV, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll_final_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vid_pll.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_hw *meson8b_vclk_mux_parent_hws[] = { &meson8b_vid_pll_final_div.hw, &meson8b_fclk_div4.hw, &meson8b_fclk_div3.hw, &meson8b_fclk_div5.hw, &meson8b_vid_pll_final_div.hw, &meson8b_fclk_div7.hw, &meson8b_mpll1.hw, }; static struct clk_regmap meson8b_vclk_in_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_CNTL, .mask = 0x7, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk_in_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vclk_mux_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vclk_mux_parent_hws), .flags = CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap meson8b_vclk_in_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_DIV, .bit_idx = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk_in_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_in_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vclk_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 19, }, .hw.init = &(struct clk_init_data){ .name = "vclk_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_in_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vclk_div1_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 0, }, .hw.init = &(struct clk_init_data){ .name = "vclk_div1_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_vclk_div2_div = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "vclk_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, } }; static struct clk_regmap meson8b_vclk_div2_div_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 1, }, .hw.init = &(struct clk_init_data){ .name = "vclk_div2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_div2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_vclk_div4_div = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "vclk_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, } }; static struct clk_regmap meson8b_vclk_div4_div_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 2, }, .hw.init = &(struct clk_init_data){ .name = "vclk_div4_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_div4_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_vclk_div6_div = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "vclk_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, } }; static struct clk_regmap meson8b_vclk_div6_div_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 3, }, .hw.init = &(struct clk_init_data){ .name = "vclk_div6_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_div6_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_vclk_div12_div = { .mult = 1, .div = 12, .hw.init = &(struct clk_init_data){ .name = "vclk_div12", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, } }; static struct clk_regmap meson8b_vclk_div12_div_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 4, }, .hw.init = &(struct clk_init_data){ .name = "vclk_div12_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk_div12_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vclk2_in_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_CNTL, .mask = 0x7, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_in_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vclk_mux_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vclk_mux_parent_hws), .flags = CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap meson8b_vclk2_clk_in_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_in_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_in_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vclk2_clk_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 19, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_clk_in_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vclk2_div1_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 0, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_div1_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_clk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_vclk2_div2_div = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "vclk2_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_clk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, } }; static struct clk_regmap meson8b_vclk2_div2_div_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 1, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_div2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_div2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_vclk2_div4_div = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "vclk2_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_clk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, } }; static struct clk_regmap meson8b_vclk2_div4_div_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 2, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_div4_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_div4_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_vclk2_div6_div = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "vclk2_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_clk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, } }; static struct clk_regmap meson8b_vclk2_div6_div_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 3, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_div6_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_div6_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor meson8b_vclk2_div12_div = { .mult = 1, .div = 12, .hw.init = &(struct clk_init_data){ .name = "vclk2_div12", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_clk_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, } }; static struct clk_regmap meson8b_vclk2_div12_div_gate = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 4, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_div12_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vclk2_div12_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_hw *meson8b_vclk_enc_mux_parent_hws[] = { &meson8b_vclk_div1_gate.hw, &meson8b_vclk_div2_div_gate.hw, &meson8b_vclk_div4_div_gate.hw, &meson8b_vclk_div6_div_gate.hw, &meson8b_vclk_div12_div_gate.hw, }; static struct clk_regmap meson8b_cts_enct_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_DIV, .mask = 0xf, .shift = 20, }, .hw.init = &(struct clk_init_data){ .name = "cts_enct_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vclk_enc_mux_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vclk_enc_mux_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_enct = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 1, }, .hw.init = &(struct clk_init_data){ .name = "cts_enct", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_enct_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_encp_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_DIV, .mask = 0xf, .shift = 24, }, .hw.init = &(struct clk_init_data){ .name = "cts_encp_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vclk_enc_mux_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vclk_enc_mux_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_encp = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 2, }, .hw.init = &(struct clk_init_data){ .name = "cts_encp", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_encp_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_enci_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_DIV, .mask = 0xf, .shift = 28, }, .hw.init = &(struct clk_init_data){ .name = "cts_enci_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vclk_enc_mux_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vclk_enc_mux_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_enci = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 0, }, .hw.init = &(struct clk_init_data){ .name = "cts_enci", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_enci_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_hdmi_tx_pixel_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_HDMI_CLK_CNTL, .mask = 0xf, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_tx_pixel_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vclk_enc_mux_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vclk_enc_mux_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_hdmi_tx_pixel = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 5, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_tx_pixel", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_hdmi_tx_pixel_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_hw *meson8b_vclk2_enc_mux_parent_hws[] = { &meson8b_vclk2_div1_gate.hw, &meson8b_vclk2_div2_div_gate.hw, &meson8b_vclk2_div4_div_gate.hw, &meson8b_vclk2_div6_div_gate.hw, &meson8b_vclk2_div12_div_gate.hw, }; static struct clk_regmap meson8b_cts_encl_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_DIV, .mask = 0xf, .shift = 12, }, .hw.init = &(struct clk_init_data){ .name = "cts_encl_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vclk2_enc_mux_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vclk2_enc_mux_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_encl = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 3, }, .hw.init = &(struct clk_init_data){ .name = "cts_encl", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_encl_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_vdac0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_DIV, .mask = 0xf, .shift = 28, }, .hw.init = &(struct clk_init_data){ .name = "cts_vdac0_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vclk2_enc_mux_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vclk2_enc_mux_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_vdac0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 4, }, .hw.init = &(struct clk_init_data){ .name = "cts_vdac0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_vdac0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_hdmi_sys_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_HDMI_CLK_CNTL, .mask = 0x3, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_sys_sel", .ops = &clk_regmap_mux_ops, /* FIXME: all other parents are unknown */ .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", .name = "xtal", .index = -1, }, .num_parents = 1, .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap meson8b_hdmi_sys_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_sys_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_hdmi_sys_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_hdmi_sys = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_HDMI_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "hdmi_sys", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_hdmi_sys_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* * The MALI IP is clocked by two identical clocks (mali_0 and mali_1) * muxed by a glitch-free switch on Meson8b and Meson8m2. The CCF can * actually manage this glitch-free mux because it does top-to-bottom * updates the each clock tree and switches to the "inactive" one when * CLK_SET_RATE_GATE is set. * Meson8 only has mali_0 and no glitch-free mux. */ static const struct clk_parent_data meson8b_mali_0_1_parent_data[] = { { .fw_name = "xtal", .name = "xtal", .index = -1, }, { .hw = &meson8b_mpll2.hw, }, { .hw = &meson8b_mpll1.hw, }, { .hw = &meson8b_fclk_div7.hw, }, { .hw = &meson8b_fclk_div4.hw, }, { .hw = &meson8b_fclk_div3.hw, }, { .hw = &meson8b_fclk_div5.hw, }, }; static u32 meson8b_mali_0_1_mux_table[] = { 0, 2, 3, 4, 5, 6, 7 }; static struct clk_regmap meson8b_mali_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 0x7, .shift = 9, .table = meson8b_mali_0_1_mux_table, }, .hw.init = &(struct clk_init_data){ .name = "mali_0_sel", .ops = &clk_regmap_mux_ops, .parent_data = meson8b_mali_0_1_parent_data, .num_parents = ARRAY_SIZE(meson8b_mali_0_1_parent_data), /* * Don't propagate rate changes up because the only changeable * parents are mpll1 and mpll2 but we need those for audio and * RGMII (Ethernet). We don't want to change the audio or * Ethernet clocks when setting the GPU frequency. */ .flags = 0, }, }; static struct clk_regmap meson8b_mali_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MALI_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mali_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mali_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_mali_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MALI_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "mali_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mali_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_mali_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 0x7, .shift = 25, .table = meson8b_mali_0_1_mux_table, }, .hw.init = &(struct clk_init_data){ .name = "mali_1_sel", .ops = &clk_regmap_mux_ops, .parent_data = meson8b_mali_0_1_parent_data, .num_parents = ARRAY_SIZE(meson8b_mali_0_1_parent_data), /* * Don't propagate rate changes up because the only changeable * parents are mpll1 and mpll2 but we need those for audio and * RGMII (Ethernet). We don't want to change the audio or * Ethernet clocks when setting the GPU frequency. */ .flags = 0, }, }; static struct clk_regmap meson8b_mali_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MALI_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mali_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mali_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_mali_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MALI_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data){ .name = "mali_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mali_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_mali = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "mali", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_mali_0.hw, &meson8b_mali_1.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static const struct reg_sequence meson8m2_gp_pll_init_regs[] = { { .reg = HHI_GP_PLL_CNTL2, .def = 0x59c88000 }, { .reg = HHI_GP_PLL_CNTL3, .def = 0xca463823 }, { .reg = HHI_GP_PLL_CNTL4, .def = 0x0286a027 }, { .reg = HHI_GP_PLL_CNTL5, .def = 0x00003000 }, }; static const struct pll_params_table meson8m2_gp_pll_params_table[] = { PLL_PARAMS(182, 3), { /* sentinel */ }, }; static struct clk_regmap meson8m2_gp_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_GP_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_GP_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_GP_PLL_CNTL, .shift = 9, .width = 5, }, .l = { .reg_off = HHI_GP_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_GP_PLL_CNTL, .shift = 29, .width = 1, }, .table = meson8m2_gp_pll_params_table, .init_regs = meson8m2_gp_pll_init_regs, .init_count = ARRAY_SIZE(meson8m2_gp_pll_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "gp_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", .name = "xtal", .index = -1, }, .num_parents = 1, }, }; static struct clk_regmap meson8m2_gp_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_GP_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "gp_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8m2_gp_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_hw *meson8b_vpu_0_1_parent_hws[] = { &meson8b_fclk_div4.hw, &meson8b_fclk_div3.hw, &meson8b_fclk_div5.hw, &meson8b_fclk_div7.hw, }; static const struct clk_hw *mmeson8m2_vpu_0_1_parent_hws[] = { &meson8b_fclk_div4.hw, &meson8b_fclk_div3.hw, &meson8b_fclk_div5.hw, &meson8m2_gp_pll.hw, }; static struct clk_regmap meson8b_vpu_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vpu_0_1_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vpu_0_1_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8m2_vpu_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_sel", .ops = &clk_regmap_mux_ops, .parent_hws = mmeson8m2_vpu_0_1_parent_hws, .num_parents = ARRAY_SIZE(mmeson8m2_vpu_0_1_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vpu_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VPU_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_div", .ops = &clk_regmap_divider_ops, .parent_data = &(const struct clk_parent_data) { /* * Note: * meson8b and meson8m2 have different vpu_0_sels (with * different struct clk_hw). We fallback to the global * naming string mechanism so vpu_0_div picks up the * appropriate one. */ .name = "vpu_0_sel", .index = -1, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vpu_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VPU_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vpu_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vpu_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vpu_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x3, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vpu_0_1_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vpu_0_1_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8m2_vpu_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x3, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = mmeson8m2_vpu_0_1_parent_hws, .num_parents = ARRAY_SIZE(mmeson8m2_vpu_0_1_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vpu_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VPU_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_div", .ops = &clk_regmap_divider_ops, .parent_data = &(const struct clk_parent_data) { /* * Note: * meson8b and meson8m2 have different vpu_1_sels (with * different struct clk_hw). We fallback to the global * naming string mechanism so vpu_1_div picks up the * appropriate one. */ .name = "vpu_1_sel", .index = -1, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vpu_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VPU_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vpu_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vpu_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT, }, }; /* * The VPU clock has two identical clock trees (vpu_0 and vpu_1) * muxed by a glitch-free switch on Meson8b and Meson8m2. The CCF can * actually manage this glitch-free mux because it does top-to-bottom * updates the each clock tree and switches to the "inactive" one when * CLK_SET_RATE_GATE is set. * Meson8 only has vpu_0 and no glitch-free mux. */ static struct clk_regmap meson8b_vpu = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "vpu", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vpu_0.hw, &meson8b_vpu_1.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_hw *meson8b_vdec_parent_hws[] = { &meson8b_fclk_div4.hw, &meson8b_fclk_div3.hw, &meson8b_fclk_div5.hw, &meson8b_fclk_div7.hw, &meson8b_mpll2.hw, &meson8b_mpll1.hw, }; static struct clk_regmap meson8b_vdec_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC_CLK_CNTL, .mask = 0x3, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vdec_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_1_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_1_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_1_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vdec_1_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_1_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_1_2_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC3_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_1_2_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_1_2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC3_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vdec_1_2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_1_2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_1 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC3_CLK_CNTL, .mask = 0x1, .shift = 15, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_1", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_1_1.hw, &meson8b_vdec_1_2.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_hcodec_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC_CLK_CNTL, .mask = 0x3, .shift = 25, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hcodec_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vdec_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_hcodec_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC_CLK_CNTL, .shift = 16, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hcodec_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_hcodec_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_hcodec = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vdec_hcodec", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_hcodec_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_2_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC2_CLK_CNTL, .mask = 0x3, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_2_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vdec_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_2_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC2_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_2_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_2_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC2_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vdec_2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_hevc_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC2_CLK_CNTL, .mask = 0x3, .shift = 25, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevc_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_vdec_parent_hws, .num_parents = ARRAY_SIZE(meson8b_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_hevc_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC2_CLK_CNTL, .shift = 16, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_hevc_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_hevc_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC2_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vdec_hevc_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_hevc_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_vdec_hevc = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC2_CLK_CNTL, .mask = 0x1, .shift = 31, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevc", .ops = &clk_regmap_mux_ops, /* TODO: The second parent is currently unknown */ .parent_hws = (const struct clk_hw *[]) { &meson8b_vdec_hevc_en.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* TODO: the clock at index 0 is "DDR_PLL" which we don't support yet */ static const struct clk_hw *meson8b_cts_amclk_parent_hws[] = { &meson8b_mpll0.hw, &meson8b_mpll1.hw, &meson8b_mpll2.hw }; static u32 meson8b_cts_amclk_mux_table[] = { 1, 2, 3 }; static struct clk_regmap meson8b_cts_amclk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_AUD_CLK_CNTL, .mask = 0x3, .shift = 9, .table = meson8b_cts_amclk_mux_table, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cts_amclk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_cts_amclk_parent_hws, .num_parents = ARRAY_SIZE(meson8b_cts_amclk_parent_hws), }, }; static struct clk_regmap meson8b_cts_amclk_div = { .data = &(struct clk_regmap_div_data) { .offset = HHI_AUD_CLK_CNTL, .shift = 0, .width = 8, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cts_amclk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_amclk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_amclk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_AUD_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "cts_amclk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_amclk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* TODO: the clock at index 0 is "DDR_PLL" which we don't support yet */ static const struct clk_hw *meson8b_cts_mclk_i958_parent_hws[] = { &meson8b_mpll0.hw, &meson8b_mpll1.hw, &meson8b_mpll2.hw }; static u32 meson8b_cts_mclk_i958_mux_table[] = { 1, 2, 3 }; static struct clk_regmap meson8b_cts_mclk_i958_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_AUD_CLK_CNTL2, .mask = 0x3, .shift = 25, .table = meson8b_cts_mclk_i958_mux_table, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "cts_mclk_i958_sel", .ops = &clk_regmap_mux_ops, .parent_hws = meson8b_cts_mclk_i958_parent_hws, .num_parents = ARRAY_SIZE(meson8b_cts_mclk_i958_parent_hws), }, }; static struct clk_regmap meson8b_cts_mclk_i958_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_AUD_CLK_CNTL2, .shift = 16, .width = 8, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "cts_mclk_i958_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_mclk_i958_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_mclk_i958 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_AUD_CLK_CNTL2, .bit_idx = 24, }, .hw.init = &(struct clk_init_data){ .name = "cts_mclk_i958", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_mclk_i958_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap meson8b_cts_i958 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_AUD_CLK_CNTL2, .mask = 0x1, .shift = 27, }, .hw.init = &(struct clk_init_data){ .name = "cts_i958", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &meson8b_cts_amclk.hw, &meson8b_cts_mclk_i958.hw }, .num_parents = 2, /* * The parent is specific to origin of the audio data. Let the * consumer choose the appropriate parent. */ .flags = CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, }, }; #define MESON_GATE(_name, _reg, _bit) \ MESON_PCLK(_name, _reg, _bit, &meson8b_clk81.hw) /* Everything Else (EE) domain gates */ static MESON_GATE(meson8b_ddr, HHI_GCLK_MPEG0, 0); static MESON_GATE(meson8b_dos, HHI_GCLK_MPEG0, 1); static MESON_GATE(meson8b_isa, HHI_GCLK_MPEG0, 5); static MESON_GATE(meson8b_pl301, HHI_GCLK_MPEG0, 6); static MESON_GATE(meson8b_periphs, HHI_GCLK_MPEG0, 7); static MESON_GATE(meson8b_spicc, HHI_GCLK_MPEG0, 8); static MESON_GATE(meson8b_i2c, HHI_GCLK_MPEG0, 9); static MESON_GATE(meson8b_sar_adc, HHI_GCLK_MPEG0, 10); static MESON_GATE(meson8b_smart_card, HHI_GCLK_MPEG0, 11); static MESON_GATE(meson8b_rng0, HHI_GCLK_MPEG0, 12); static MESON_GATE(meson8b_uart0, HHI_GCLK_MPEG0, 13); static MESON_GATE(meson8b_sdhc, HHI_GCLK_MPEG0, 14); static MESON_GATE(meson8b_stream, HHI_GCLK_MPEG0, 15); static MESON_GATE(meson8b_async_fifo, HHI_GCLK_MPEG0, 16); static MESON_GATE(meson8b_sdio, HHI_GCLK_MPEG0, 17); static MESON_GATE(meson8b_abuf, HHI_GCLK_MPEG0, 18); static MESON_GATE(meson8b_hiu_iface, HHI_GCLK_MPEG0, 19); static MESON_GATE(meson8b_assist_misc, HHI_GCLK_MPEG0, 23); static MESON_GATE(meson8b_spi, HHI_GCLK_MPEG0, 30); static MESON_GATE(meson8b_i2s_spdif, HHI_GCLK_MPEG1, 2); static MESON_GATE(meson8b_eth, HHI_GCLK_MPEG1, 3); static MESON_GATE(meson8b_demux, HHI_GCLK_MPEG1, 4); static MESON_GATE(meson8b_blkmv, HHI_GCLK_MPEG1, 14); static MESON_GATE(meson8b_aiu, HHI_GCLK_MPEG1, 15); static MESON_GATE(meson8b_uart1, HHI_GCLK_MPEG1, 16); static MESON_GATE(meson8b_g2d, HHI_GCLK_MPEG1, 20); static MESON_GATE(meson8b_usb0, HHI_GCLK_MPEG1, 21); static MESON_GATE(meson8b_usb1, HHI_GCLK_MPEG1, 22); static MESON_GATE(meson8b_reset, HHI_GCLK_MPEG1, 23); static MESON_GATE(meson8b_nand, HHI_GCLK_MPEG1, 24); static MESON_GATE(meson8b_dos_parser, HHI_GCLK_MPEG1, 25); static MESON_GATE(meson8b_usb, HHI_GCLK_MPEG1, 26); static MESON_GATE(meson8b_vdin1, HHI_GCLK_MPEG1, 28); static MESON_GATE(meson8b_ahb_arb0, HHI_GCLK_MPEG1, 29); static MESON_GATE(meson8b_efuse, HHI_GCLK_MPEG1, 30); static MESON_GATE(meson8b_boot_rom, HHI_GCLK_MPEG1, 31); static MESON_GATE(meson8b_ahb_data_bus, HHI_GCLK_MPEG2, 1); static MESON_GATE(meson8b_ahb_ctrl_bus, HHI_GCLK_MPEG2, 2); static MESON_GATE(meson8b_hdmi_intr_sync, HHI_GCLK_MPEG2, 3); static MESON_GATE(meson8b_hdmi_pclk, HHI_GCLK_MPEG2, 4); static MESON_GATE(meson8b_usb1_ddr_bridge, HHI_GCLK_MPEG2, 8); static MESON_GATE(meson8b_usb0_ddr_bridge, HHI_GCLK_MPEG2, 9); static MESON_GATE(meson8b_mmc_pclk, HHI_GCLK_MPEG2, 11); static MESON_GATE(meson8b_dvin, HHI_GCLK_MPEG2, 12); static MESON_GATE(meson8b_uart2, HHI_GCLK_MPEG2, 15); static MESON_GATE(meson8b_sana, HHI_GCLK_MPEG2, 22); static MESON_GATE(meson8b_vpu_intr, HHI_GCLK_MPEG2, 25); static MESON_GATE(meson8b_sec_ahb_ahb3_bridge, HHI_GCLK_MPEG2, 26); static MESON_GATE(meson8b_clk81_a9, HHI_GCLK_MPEG2, 29); static MESON_GATE(meson8b_vclk2_venci0, HHI_GCLK_OTHER, 1); static MESON_GATE(meson8b_vclk2_venci1, HHI_GCLK_OTHER, 2); static MESON_GATE(meson8b_vclk2_vencp0, HHI_GCLK_OTHER, 3); static MESON_GATE(meson8b_vclk2_vencp1, HHI_GCLK_OTHER, 4); static MESON_GATE(meson8b_gclk_venci_int, HHI_GCLK_OTHER, 8); static MESON_GATE(meson8b_gclk_vencp_int, HHI_GCLK_OTHER, 9); static MESON_GATE(meson8b_dac_clk, HHI_GCLK_OTHER, 10); static MESON_GATE(meson8b_aoclk_gate, HHI_GCLK_OTHER, 14); static MESON_GATE(meson8b_iec958_gate, HHI_GCLK_OTHER, 16); static MESON_GATE(meson8b_enc480p, HHI_GCLK_OTHER, 20); static MESON_GATE(meson8b_rng1, HHI_GCLK_OTHER, 21); static MESON_GATE(meson8b_gclk_vencl_int, HHI_GCLK_OTHER, 22); static MESON_GATE(meson8b_vclk2_venclmcc, HHI_GCLK_OTHER, 24); static MESON_GATE(meson8b_vclk2_vencl, HHI_GCLK_OTHER, 25); static MESON_GATE(meson8b_vclk2_other, HHI_GCLK_OTHER, 26); static MESON_GATE(meson8b_edp, HHI_GCLK_OTHER, 31); /* AIU gates */ #define MESON_AIU_GLUE_GATE(_name, _reg, _bit) \ MESON_PCLK(_name, _reg, _bit, &meson8b_aiu_glue.hw) static MESON_PCLK(meson8b_aiu_glue, HHI_GCLK_MPEG1, 6, &meson8b_aiu.hw); static MESON_AIU_GLUE_GATE(meson8b_iec958, HHI_GCLK_MPEG1, 7); static MESON_AIU_GLUE_GATE(meson8b_i2s_out, HHI_GCLK_MPEG1, 8); static MESON_AIU_GLUE_GATE(meson8b_amclk, HHI_GCLK_MPEG1, 9); static MESON_AIU_GLUE_GATE(meson8b_aififo2, HHI_GCLK_MPEG1, 10); static MESON_AIU_GLUE_GATE(meson8b_mixer, HHI_GCLK_MPEG1, 11); static MESON_AIU_GLUE_GATE(meson8b_mixer_iface, HHI_GCLK_MPEG1, 12); static MESON_AIU_GLUE_GATE(meson8b_adc, HHI_GCLK_MPEG1, 13); /* Always On (AO) domain gates */ static MESON_GATE(meson8b_ao_media_cpu, HHI_GCLK_AO, 0); static MESON_GATE(meson8b_ao_ahb_sram, HHI_GCLK_AO, 1); static MESON_GATE(meson8b_ao_ahb_bus, HHI_GCLK_AO, 2); static MESON_GATE(meson8b_ao_iface, HHI_GCLK_AO, 3); static struct clk_hw *meson8_hw_clks[] = { [CLKID_PLL_FIXED] = &meson8b_fixed_pll.hw, [CLKID_PLL_VID] = &meson8b_vid_pll.hw, [CLKID_PLL_SYS] = &meson8b_sys_pll.hw, [CLKID_FCLK_DIV2] = &meson8b_fclk_div2.hw, [CLKID_FCLK_DIV3] = &meson8b_fclk_div3.hw, [CLKID_FCLK_DIV4] = &meson8b_fclk_div4.hw, [CLKID_FCLK_DIV5] = &meson8b_fclk_div5.hw, [CLKID_FCLK_DIV7] = &meson8b_fclk_div7.hw, [CLKID_CPUCLK] = &meson8b_cpu_clk.hw, [CLKID_MPEG_SEL] = &meson8b_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &meson8b_mpeg_clk_div.hw, [CLKID_CLK81] = &meson8b_clk81.hw, [CLKID_DDR] = &meson8b_ddr.hw, [CLKID_DOS] = &meson8b_dos.hw, [CLKID_ISA] = &meson8b_isa.hw, [CLKID_PL301] = &meson8b_pl301.hw, [CLKID_PERIPHS] = &meson8b_periphs.hw, [CLKID_SPICC] = &meson8b_spicc.hw, [CLKID_I2C] = &meson8b_i2c.hw, [CLKID_SAR_ADC] = &meson8b_sar_adc.hw, [CLKID_SMART_CARD] = &meson8b_smart_card.hw, [CLKID_RNG0] = &meson8b_rng0.hw, [CLKID_UART0] = &meson8b_uart0.hw, [CLKID_SDHC] = &meson8b_sdhc.hw, [CLKID_STREAM] = &meson8b_stream.hw, [CLKID_ASYNC_FIFO] = &meson8b_async_fifo.hw, [CLKID_SDIO] = &meson8b_sdio.hw, [CLKID_ABUF] = &meson8b_abuf.hw, [CLKID_HIU_IFACE] = &meson8b_hiu_iface.hw, [CLKID_ASSIST_MISC] = &meson8b_assist_misc.hw, [CLKID_SPI] = &meson8b_spi.hw, [CLKID_I2S_SPDIF] = &meson8b_i2s_spdif.hw, [CLKID_ETH] = &meson8b_eth.hw, [CLKID_DEMUX] = &meson8b_demux.hw, [CLKID_AIU_GLUE] = &meson8b_aiu_glue.hw, [CLKID_IEC958] = &meson8b_iec958.hw, [CLKID_I2S_OUT] = &meson8b_i2s_out.hw, [CLKID_AMCLK] = &meson8b_amclk.hw, [CLKID_AIFIFO2] = &meson8b_aififo2.hw, [CLKID_MIXER] = &meson8b_mixer.hw, [CLKID_MIXER_IFACE] = &meson8b_mixer_iface.hw, [CLKID_ADC] = &meson8b_adc.hw, [CLKID_BLKMV] = &meson8b_blkmv.hw, [CLKID_AIU] = &meson8b_aiu.hw, [CLKID_UART1] = &meson8b_uart1.hw, [CLKID_G2D] = &meson8b_g2d.hw, [CLKID_USB0] = &meson8b_usb0.hw, [CLKID_USB1] = &meson8b_usb1.hw, [CLKID_RESET] = &meson8b_reset.hw, [CLKID_NAND] = &meson8b_nand.hw, [CLKID_DOS_PARSER] = &meson8b_dos_parser.hw, [CLKID_USB] = &meson8b_usb.hw, [CLKID_VDIN1] = &meson8b_vdin1.hw, [CLKID_AHB_ARB0] = &meson8b_ahb_arb0.hw, [CLKID_EFUSE] = &meson8b_efuse.hw, [CLKID_BOOT_ROM] = &meson8b_boot_rom.hw, [CLKID_AHB_DATA_BUS] = &meson8b_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &meson8b_ahb_ctrl_bus.hw, [CLKID_HDMI_INTR_SYNC] = &meson8b_hdmi_intr_sync.hw, [CLKID_HDMI_PCLK] = &meson8b_hdmi_pclk.hw, [CLKID_USB1_DDR_BRIDGE] = &meson8b_usb1_ddr_bridge.hw, [CLKID_USB0_DDR_BRIDGE] = &meson8b_usb0_ddr_bridge.hw, [CLKID_MMC_PCLK] = &meson8b_mmc_pclk.hw, [CLKID_DVIN] = &meson8b_dvin.hw, [CLKID_UART2] = &meson8b_uart2.hw, [CLKID_SANA] = &meson8b_sana.hw, [CLKID_VPU_INTR] = &meson8b_vpu_intr.hw, [CLKID_SEC_AHB_AHB3_BRIDGE] = &meson8b_sec_ahb_ahb3_bridge.hw, [CLKID_CLK81_A9] = &meson8b_clk81_a9.hw, [CLKID_VCLK2_VENCI0] = &meson8b_vclk2_venci0.hw, [CLKID_VCLK2_VENCI1] = &meson8b_vclk2_venci1.hw, [CLKID_VCLK2_VENCP0] = &meson8b_vclk2_vencp0.hw, [CLKID_VCLK2_VENCP1] = &meson8b_vclk2_vencp1.hw, [CLKID_GCLK_VENCI_INT] = &meson8b_gclk_venci_int.hw, [CLKID_GCLK_VENCP_INT] = &meson8b_gclk_vencp_int.hw, [CLKID_DAC_CLK] = &meson8b_dac_clk.hw, [CLKID_AOCLK_GATE] = &meson8b_aoclk_gate.hw, [CLKID_IEC958_GATE] = &meson8b_iec958_gate.hw, [CLKID_ENC480P] = &meson8b_enc480p.hw, [CLKID_RNG1] = &meson8b_rng1.hw, [CLKID_GCLK_VENCL_INT] = &meson8b_gclk_vencl_int.hw, [CLKID_VCLK2_VENCLMCC] = &meson8b_vclk2_venclmcc.hw, [CLKID_VCLK2_VENCL] = &meson8b_vclk2_vencl.hw, [CLKID_VCLK2_OTHER] = &meson8b_vclk2_other.hw, [CLKID_EDP] = &meson8b_edp.hw, [CLKID_AO_MEDIA_CPU] = &meson8b_ao_media_cpu.hw, [CLKID_AO_AHB_SRAM] = &meson8b_ao_ahb_sram.hw, [CLKID_AO_AHB_BUS] = &meson8b_ao_ahb_bus.hw, [CLKID_AO_IFACE] = &meson8b_ao_iface.hw, [CLKID_MPLL0] = &meson8b_mpll0.hw, [CLKID_MPLL1] = &meson8b_mpll1.hw, [CLKID_MPLL2] = &meson8b_mpll2.hw, [CLKID_MPLL0_DIV] = &meson8b_mpll0_div.hw, [CLKID_MPLL1_DIV] = &meson8b_mpll1_div.hw, [CLKID_MPLL2_DIV] = &meson8b_mpll2_div.hw, [CLKID_CPU_IN_SEL] = &meson8b_cpu_in_sel.hw, [CLKID_CPU_IN_DIV2] = &meson8b_cpu_in_div2.hw, [CLKID_CPU_IN_DIV3] = &meson8b_cpu_in_div3.hw, [CLKID_CPU_SCALE_DIV] = &meson8b_cpu_scale_div.hw, [CLKID_CPU_SCALE_OUT_SEL] = &meson8b_cpu_scale_out_sel.hw, [CLKID_MPLL_PREDIV] = &meson8b_mpll_prediv.hw, [CLKID_FCLK_DIV2_DIV] = &meson8b_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &meson8b_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &meson8b_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &meson8b_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &meson8b_fclk_div7_div.hw, [CLKID_NAND_SEL] = &meson8b_nand_clk_sel.hw, [CLKID_NAND_DIV] = &meson8b_nand_clk_div.hw, [CLKID_NAND_CLK] = &meson8b_nand_clk_gate.hw, [CLKID_PLL_FIXED_DCO] = &meson8b_fixed_pll_dco.hw, [CLKID_HDMI_PLL_DCO] = &meson8b_hdmi_pll_dco.hw, [CLKID_PLL_SYS_DCO] = &meson8b_sys_pll_dco.hw, [CLKID_CPU_CLK_DIV2] = &meson8b_cpu_clk_div2.hw, [CLKID_CPU_CLK_DIV3] = &meson8b_cpu_clk_div3.hw, [CLKID_CPU_CLK_DIV4] = &meson8b_cpu_clk_div4.hw, [CLKID_CPU_CLK_DIV5] = &meson8b_cpu_clk_div5.hw, [CLKID_CPU_CLK_DIV6] = &meson8b_cpu_clk_div6.hw, [CLKID_CPU_CLK_DIV7] = &meson8b_cpu_clk_div7.hw, [CLKID_CPU_CLK_DIV8] = &meson8b_cpu_clk_div8.hw, [CLKID_APB_SEL] = &meson8b_apb_clk_sel.hw, [CLKID_APB] = &meson8b_apb_clk_gate.hw, [CLKID_PERIPH_SEL] = &meson8b_periph_clk_sel.hw, [CLKID_PERIPH] = &meson8b_periph_clk_gate.hw, [CLKID_AXI_SEL] = &meson8b_axi_clk_sel.hw, [CLKID_AXI] = &meson8b_axi_clk_gate.hw, [CLKID_L2_DRAM_SEL] = &meson8b_l2_dram_clk_sel.hw, [CLKID_L2_DRAM] = &meson8b_l2_dram_clk_gate.hw, [CLKID_HDMI_PLL_LVDS_OUT] = &meson8b_hdmi_pll_lvds_out.hw, [CLKID_HDMI_PLL_HDMI_OUT] = &meson8b_hdmi_pll_hdmi_out.hw, [CLKID_VID_PLL_IN_SEL] = &meson8b_vid_pll_in_sel.hw, [CLKID_VID_PLL_IN_EN] = &meson8b_vid_pll_in_en.hw, [CLKID_VID_PLL_PRE_DIV] = &meson8b_vid_pll_pre_div.hw, [CLKID_VID_PLL_POST_DIV] = &meson8b_vid_pll_post_div.hw, [CLKID_VID_PLL_FINAL_DIV] = &meson8b_vid_pll_final_div.hw, [CLKID_VCLK_IN_SEL] = &meson8b_vclk_in_sel.hw, [CLKID_VCLK_IN_EN] = &meson8b_vclk_in_en.hw, [CLKID_VCLK_EN] = &meson8b_vclk_en.hw, [CLKID_VCLK_DIV1] = &meson8b_vclk_div1_gate.hw, [CLKID_VCLK_DIV2_DIV] = &meson8b_vclk_div2_div.hw, [CLKID_VCLK_DIV2] = &meson8b_vclk_div2_div_gate.hw, [CLKID_VCLK_DIV4_DIV] = &meson8b_vclk_div4_div.hw, [CLKID_VCLK_DIV4] = &meson8b_vclk_div4_div_gate.hw, [CLKID_VCLK_DIV6_DIV] = &meson8b_vclk_div6_div.hw, [CLKID_VCLK_DIV6] = &meson8b_vclk_div6_div_gate.hw, [CLKID_VCLK_DIV12_DIV] = &meson8b_vclk_div12_div.hw, [CLKID_VCLK_DIV12] = &meson8b_vclk_div12_div_gate.hw, [CLKID_VCLK2_IN_SEL] = &meson8b_vclk2_in_sel.hw, [CLKID_VCLK2_IN_EN] = &meson8b_vclk2_clk_in_en.hw, [CLKID_VCLK2_EN] = &meson8b_vclk2_clk_en.hw, [CLKID_VCLK2_DIV1] = &meson8b_vclk2_div1_gate.hw, [CLKID_VCLK2_DIV2_DIV] = &meson8b_vclk2_div2_div.hw, [CLKID_VCLK2_DIV2] = &meson8b_vclk2_div2_div_gate.hw, [CLKID_VCLK2_DIV4_DIV] = &meson8b_vclk2_div4_div.hw, [CLKID_VCLK2_DIV4] = &meson8b_vclk2_div4_div_gate.hw, [CLKID_VCLK2_DIV6_DIV] = &meson8b_vclk2_div6_div.hw, [CLKID_VCLK2_DIV6] = &meson8b_vclk2_div6_div_gate.hw, [CLKID_VCLK2_DIV12_DIV] = &meson8b_vclk2_div12_div.hw, [CLKID_VCLK2_DIV12] = &meson8b_vclk2_div12_div_gate.hw, [CLKID_CTS_ENCT_SEL] = &meson8b_cts_enct_sel.hw, [CLKID_CTS_ENCT] = &meson8b_cts_enct.hw, [CLKID_CTS_ENCP_SEL] = &meson8b_cts_encp_sel.hw, [CLKID_CTS_ENCP] = &meson8b_cts_encp.hw, [CLKID_CTS_ENCI_SEL] = &meson8b_cts_enci_sel.hw, [CLKID_CTS_ENCI] = &meson8b_cts_enci.hw, [CLKID_HDMI_TX_PIXEL_SEL] = &meson8b_hdmi_tx_pixel_sel.hw, [CLKID_HDMI_TX_PIXEL] = &meson8b_hdmi_tx_pixel.hw, [CLKID_CTS_ENCL_SEL] = &meson8b_cts_encl_sel.hw, [CLKID_CTS_ENCL] = &meson8b_cts_encl.hw, [CLKID_CTS_VDAC0_SEL] = &meson8b_cts_vdac0_sel.hw, [CLKID_CTS_VDAC0] = &meson8b_cts_vdac0.hw, [CLKID_HDMI_SYS_SEL] = &meson8b_hdmi_sys_sel.hw, [CLKID_HDMI_SYS_DIV] = &meson8b_hdmi_sys_div.hw, [CLKID_HDMI_SYS] = &meson8b_hdmi_sys.hw, [CLKID_MALI_0_SEL] = &meson8b_mali_0_sel.hw, [CLKID_MALI_0_DIV] = &meson8b_mali_0_div.hw, [CLKID_MALI] = &meson8b_mali_0.hw, [CLKID_VPU_0_SEL] = &meson8b_vpu_0_sel.hw, [CLKID_VPU_0_DIV] = &meson8b_vpu_0_div.hw, [CLKID_VPU] = &meson8b_vpu_0.hw, [CLKID_VDEC_1_SEL] = &meson8b_vdec_1_sel.hw, [CLKID_VDEC_1_1_DIV] = &meson8b_vdec_1_1_div.hw, [CLKID_VDEC_1] = &meson8b_vdec_1_1.hw, [CLKID_VDEC_HCODEC_SEL] = &meson8b_vdec_hcodec_sel.hw, [CLKID_VDEC_HCODEC_DIV] = &meson8b_vdec_hcodec_div.hw, [CLKID_VDEC_HCODEC] = &meson8b_vdec_hcodec.hw, [CLKID_VDEC_2_SEL] = &meson8b_vdec_2_sel.hw, [CLKID_VDEC_2_DIV] = &meson8b_vdec_2_div.hw, [CLKID_VDEC_2] = &meson8b_vdec_2.hw, [CLKID_VDEC_HEVC_SEL] = &meson8b_vdec_hevc_sel.hw, [CLKID_VDEC_HEVC_DIV] = &meson8b_vdec_hevc_div.hw, [CLKID_VDEC_HEVC_EN] = &meson8b_vdec_hevc_en.hw, [CLKID_VDEC_HEVC] = &meson8b_vdec_hevc.hw, [CLKID_CTS_AMCLK_SEL] = &meson8b_cts_amclk_sel.hw, [CLKID_CTS_AMCLK_DIV] = &meson8b_cts_amclk_div.hw, [CLKID_CTS_AMCLK] = &meson8b_cts_amclk.hw, [CLKID_CTS_MCLK_I958_SEL] = &meson8b_cts_mclk_i958_sel.hw, [CLKID_CTS_MCLK_I958_DIV] = &meson8b_cts_mclk_i958_div.hw, [CLKID_CTS_MCLK_I958] = &meson8b_cts_mclk_i958.hw, [CLKID_CTS_I958] = &meson8b_cts_i958.hw, [CLKID_VID_PLL_LVDS_EN] = &meson8b_vid_pll_lvds_en.hw, [CLKID_HDMI_PLL_DCO_IN] = &hdmi_pll_dco_in.hw, }; static struct clk_hw *meson8b_hw_clks[] = { [CLKID_PLL_FIXED] = &meson8b_fixed_pll.hw, [CLKID_PLL_VID] = &meson8b_vid_pll.hw, [CLKID_PLL_SYS] = &meson8b_sys_pll.hw, [CLKID_FCLK_DIV2] = &meson8b_fclk_div2.hw, [CLKID_FCLK_DIV3] = &meson8b_fclk_div3.hw, [CLKID_FCLK_DIV4] = &meson8b_fclk_div4.hw, [CLKID_FCLK_DIV5] = &meson8b_fclk_div5.hw, [CLKID_FCLK_DIV7] = &meson8b_fclk_div7.hw, [CLKID_CPUCLK] = &meson8b_cpu_clk.hw, [CLKID_MPEG_SEL] = &meson8b_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &meson8b_mpeg_clk_div.hw, [CLKID_CLK81] = &meson8b_clk81.hw, [CLKID_DDR] = &meson8b_ddr.hw, [CLKID_DOS] = &meson8b_dos.hw, [CLKID_ISA] = &meson8b_isa.hw, [CLKID_PL301] = &meson8b_pl301.hw, [CLKID_PERIPHS] = &meson8b_periphs.hw, [CLKID_SPICC] = &meson8b_spicc.hw, [CLKID_I2C] = &meson8b_i2c.hw, [CLKID_SAR_ADC] = &meson8b_sar_adc.hw, [CLKID_SMART_CARD] = &meson8b_smart_card.hw, [CLKID_RNG0] = &meson8b_rng0.hw, [CLKID_UART0] = &meson8b_uart0.hw, [CLKID_SDHC] = &meson8b_sdhc.hw, [CLKID_STREAM] = &meson8b_stream.hw, [CLKID_ASYNC_FIFO] = &meson8b_async_fifo.hw, [CLKID_SDIO] = &meson8b_sdio.hw, [CLKID_ABUF] = &meson8b_abuf.hw, [CLKID_HIU_IFACE] = &meson8b_hiu_iface.hw, [CLKID_ASSIST_MISC] = &meson8b_assist_misc.hw, [CLKID_SPI] = &meson8b_spi.hw, [CLKID_I2S_SPDIF] = &meson8b_i2s_spdif.hw, [CLKID_ETH] = &meson8b_eth.hw, [CLKID_DEMUX] = &meson8b_demux.hw, [CLKID_AIU_GLUE] = &meson8b_aiu_glue.hw, [CLKID_IEC958] = &meson8b_iec958.hw, [CLKID_I2S_OUT] = &meson8b_i2s_out.hw, [CLKID_AMCLK] = &meson8b_amclk.hw, [CLKID_AIFIFO2] = &meson8b_aififo2.hw, [CLKID_MIXER] = &meson8b_mixer.hw, [CLKID_MIXER_IFACE] = &meson8b_mixer_iface.hw, [CLKID_ADC] = &meson8b_adc.hw, [CLKID_BLKMV] = &meson8b_blkmv.hw, [CLKID_AIU] = &meson8b_aiu.hw, [CLKID_UART1] = &meson8b_uart1.hw, [CLKID_G2D] = &meson8b_g2d.hw, [CLKID_USB0] = &meson8b_usb0.hw, [CLKID_USB1] = &meson8b_usb1.hw, [CLKID_RESET] = &meson8b_reset.hw, [CLKID_NAND] = &meson8b_nand.hw, [CLKID_DOS_PARSER] = &meson8b_dos_parser.hw, [CLKID_USB] = &meson8b_usb.hw, [CLKID_VDIN1] = &meson8b_vdin1.hw, [CLKID_AHB_ARB0] = &meson8b_ahb_arb0.hw, [CLKID_EFUSE] = &meson8b_efuse.hw, [CLKID_BOOT_ROM] = &meson8b_boot_rom.hw, [CLKID_AHB_DATA_BUS] = &meson8b_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &meson8b_ahb_ctrl_bus.hw, [CLKID_HDMI_INTR_SYNC] = &meson8b_hdmi_intr_sync.hw, [CLKID_HDMI_PCLK] = &meson8b_hdmi_pclk.hw, [CLKID_USB1_DDR_BRIDGE] = &meson8b_usb1_ddr_bridge.hw, [CLKID_USB0_DDR_BRIDGE] = &meson8b_usb0_ddr_bridge.hw, [CLKID_MMC_PCLK] = &meson8b_mmc_pclk.hw, [CLKID_DVIN] = &meson8b_dvin.hw, [CLKID_UART2] = &meson8b_uart2.hw, [CLKID_SANA] = &meson8b_sana.hw, [CLKID_VPU_INTR] = &meson8b_vpu_intr.hw, [CLKID_SEC_AHB_AHB3_BRIDGE] = &meson8b_sec_ahb_ahb3_bridge.hw, [CLKID_CLK81_A9] = &meson8b_clk81_a9.hw, [CLKID_VCLK2_VENCI0] = &meson8b_vclk2_venci0.hw, [CLKID_VCLK2_VENCI1] = &meson8b_vclk2_venci1.hw, [CLKID_VCLK2_VENCP0] = &meson8b_vclk2_vencp0.hw, [CLKID_VCLK2_VENCP1] = &meson8b_vclk2_vencp1.hw, [CLKID_GCLK_VENCI_INT] = &meson8b_gclk_venci_int.hw, [CLKID_GCLK_VENCP_INT] = &meson8b_gclk_vencp_int.hw, [CLKID_DAC_CLK] = &meson8b_dac_clk.hw, [CLKID_AOCLK_GATE] = &meson8b_aoclk_gate.hw, [CLKID_IEC958_GATE] = &meson8b_iec958_gate.hw, [CLKID_ENC480P] = &meson8b_enc480p.hw, [CLKID_RNG1] = &meson8b_rng1.hw, [CLKID_GCLK_VENCL_INT] = &meson8b_gclk_vencl_int.hw, [CLKID_VCLK2_VENCLMCC] = &meson8b_vclk2_venclmcc.hw, [CLKID_VCLK2_VENCL] = &meson8b_vclk2_vencl.hw, [CLKID_VCLK2_OTHER] = &meson8b_vclk2_other.hw, [CLKID_EDP] = &meson8b_edp.hw, [CLKID_AO_MEDIA_CPU] = &meson8b_ao_media_cpu.hw, [CLKID_AO_AHB_SRAM] = &meson8b_ao_ahb_sram.hw, [CLKID_AO_AHB_BUS] = &meson8b_ao_ahb_bus.hw, [CLKID_AO_IFACE] = &meson8b_ao_iface.hw, [CLKID_MPLL0] = &meson8b_mpll0.hw, [CLKID_MPLL1] = &meson8b_mpll1.hw, [CLKID_MPLL2] = &meson8b_mpll2.hw, [CLKID_MPLL0_DIV] = &meson8b_mpll0_div.hw, [CLKID_MPLL1_DIV] = &meson8b_mpll1_div.hw, [CLKID_MPLL2_DIV] = &meson8b_mpll2_div.hw, [CLKID_CPU_IN_SEL] = &meson8b_cpu_in_sel.hw, [CLKID_CPU_IN_DIV2] = &meson8b_cpu_in_div2.hw, [CLKID_CPU_IN_DIV3] = &meson8b_cpu_in_div3.hw, [CLKID_CPU_SCALE_DIV] = &meson8b_cpu_scale_div.hw, [CLKID_CPU_SCALE_OUT_SEL] = &meson8b_cpu_scale_out_sel.hw, [CLKID_MPLL_PREDIV] = &meson8b_mpll_prediv.hw, [CLKID_FCLK_DIV2_DIV] = &meson8b_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &meson8b_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &meson8b_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &meson8b_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &meson8b_fclk_div7_div.hw, [CLKID_NAND_SEL] = &meson8b_nand_clk_sel.hw, [CLKID_NAND_DIV] = &meson8b_nand_clk_div.hw, [CLKID_NAND_CLK] = &meson8b_nand_clk_gate.hw, [CLKID_PLL_FIXED_DCO] = &meson8b_fixed_pll_dco.hw, [CLKID_HDMI_PLL_DCO] = &meson8b_hdmi_pll_dco.hw, [CLKID_PLL_SYS_DCO] = &meson8b_sys_pll_dco.hw, [CLKID_CPU_CLK_DIV2] = &meson8b_cpu_clk_div2.hw, [CLKID_CPU_CLK_DIV3] = &meson8b_cpu_clk_div3.hw, [CLKID_CPU_CLK_DIV4] = &meson8b_cpu_clk_div4.hw, [CLKID_CPU_CLK_DIV5] = &meson8b_cpu_clk_div5.hw, [CLKID_CPU_CLK_DIV6] = &meson8b_cpu_clk_div6.hw, [CLKID_CPU_CLK_DIV7] = &meson8b_cpu_clk_div7.hw, [CLKID_CPU_CLK_DIV8] = &meson8b_cpu_clk_div8.hw, [CLKID_APB_SEL] = &meson8b_apb_clk_sel.hw, [CLKID_APB] = &meson8b_apb_clk_gate.hw, [CLKID_PERIPH_SEL] = &meson8b_periph_clk_sel.hw, [CLKID_PERIPH] = &meson8b_periph_clk_gate.hw, [CLKID_AXI_SEL] = &meson8b_axi_clk_sel.hw, [CLKID_AXI] = &meson8b_axi_clk_gate.hw, [CLKID_L2_DRAM_SEL] = &meson8b_l2_dram_clk_sel.hw, [CLKID_L2_DRAM] = &meson8b_l2_dram_clk_gate.hw, [CLKID_HDMI_PLL_LVDS_OUT] = &meson8b_hdmi_pll_lvds_out.hw, [CLKID_HDMI_PLL_HDMI_OUT] = &meson8b_hdmi_pll_hdmi_out.hw, [CLKID_VID_PLL_IN_SEL] = &meson8b_vid_pll_in_sel.hw, [CLKID_VID_PLL_IN_EN] = &meson8b_vid_pll_in_en.hw, [CLKID_VID_PLL_PRE_DIV] = &meson8b_vid_pll_pre_div.hw, [CLKID_VID_PLL_POST_DIV] = &meson8b_vid_pll_post_div.hw, [CLKID_VID_PLL_FINAL_DIV] = &meson8b_vid_pll_final_div.hw, [CLKID_VCLK_IN_SEL] = &meson8b_vclk_in_sel.hw, [CLKID_VCLK_IN_EN] = &meson8b_vclk_in_en.hw, [CLKID_VCLK_EN] = &meson8b_vclk_en.hw, [CLKID_VCLK_DIV1] = &meson8b_vclk_div1_gate.hw, [CLKID_VCLK_DIV2_DIV] = &meson8b_vclk_div2_div.hw, [CLKID_VCLK_DIV2] = &meson8b_vclk_div2_div_gate.hw, [CLKID_VCLK_DIV4_DIV] = &meson8b_vclk_div4_div.hw, [CLKID_VCLK_DIV4] = &meson8b_vclk_div4_div_gate.hw, [CLKID_VCLK_DIV6_DIV] = &meson8b_vclk_div6_div.hw, [CLKID_VCLK_DIV6] = &meson8b_vclk_div6_div_gate.hw, [CLKID_VCLK_DIV12_DIV] = &meson8b_vclk_div12_div.hw, [CLKID_VCLK_DIV12] = &meson8b_vclk_div12_div_gate.hw, [CLKID_VCLK2_IN_SEL] = &meson8b_vclk2_in_sel.hw, [CLKID_VCLK2_IN_EN] = &meson8b_vclk2_clk_in_en.hw, [CLKID_VCLK2_EN] = &meson8b_vclk2_clk_en.hw, [CLKID_VCLK2_DIV1] = &meson8b_vclk2_div1_gate.hw, [CLKID_VCLK2_DIV2_DIV] = &meson8b_vclk2_div2_div.hw, [CLKID_VCLK2_DIV2] = &meson8b_vclk2_div2_div_gate.hw, [CLKID_VCLK2_DIV4_DIV] = &meson8b_vclk2_div4_div.hw, [CLKID_VCLK2_DIV4] = &meson8b_vclk2_div4_div_gate.hw, [CLKID_VCLK2_DIV6_DIV] = &meson8b_vclk2_div6_div.hw, [CLKID_VCLK2_DIV6] = &meson8b_vclk2_div6_div_gate.hw, [CLKID_VCLK2_DIV12_DIV] = &meson8b_vclk2_div12_div.hw, [CLKID_VCLK2_DIV12] = &meson8b_vclk2_div12_div_gate.hw, [CLKID_CTS_ENCT_SEL] = &meson8b_cts_enct_sel.hw, [CLKID_CTS_ENCT] = &meson8b_cts_enct.hw, [CLKID_CTS_ENCP_SEL] = &meson8b_cts_encp_sel.hw, [CLKID_CTS_ENCP] = &meson8b_cts_encp.hw, [CLKID_CTS_ENCI_SEL] = &meson8b_cts_enci_sel.hw, [CLKID_CTS_ENCI] = &meson8b_cts_enci.hw, [CLKID_HDMI_TX_PIXEL_SEL] = &meson8b_hdmi_tx_pixel_sel.hw, [CLKID_HDMI_TX_PIXEL] = &meson8b_hdmi_tx_pixel.hw, [CLKID_CTS_ENCL_SEL] = &meson8b_cts_encl_sel.hw, [CLKID_CTS_ENCL] = &meson8b_cts_encl.hw, [CLKID_CTS_VDAC0_SEL] = &meson8b_cts_vdac0_sel.hw, [CLKID_CTS_VDAC0] = &meson8b_cts_vdac0.hw, [CLKID_HDMI_SYS_SEL] = &meson8b_hdmi_sys_sel.hw, [CLKID_HDMI_SYS_DIV] = &meson8b_hdmi_sys_div.hw, [CLKID_HDMI_SYS] = &meson8b_hdmi_sys.hw, [CLKID_MALI_0_SEL] = &meson8b_mali_0_sel.hw, [CLKID_MALI_0_DIV] = &meson8b_mali_0_div.hw, [CLKID_MALI_0] = &meson8b_mali_0.hw, [CLKID_MALI_1_SEL] = &meson8b_mali_1_sel.hw, [CLKID_MALI_1_DIV] = &meson8b_mali_1_div.hw, [CLKID_MALI_1] = &meson8b_mali_1.hw, [CLKID_MALI] = &meson8b_mali.hw, [CLKID_VPU_0_SEL] = &meson8b_vpu_0_sel.hw, [CLKID_VPU_0_DIV] = &meson8b_vpu_0_div.hw, [CLKID_VPU_0] = &meson8b_vpu_0.hw, [CLKID_VPU_1_SEL] = &meson8b_vpu_1_sel.hw, [CLKID_VPU_1_DIV] = &meson8b_vpu_1_div.hw, [CLKID_VPU_1] = &meson8b_vpu_1.hw, [CLKID_VPU] = &meson8b_vpu.hw, [CLKID_VDEC_1_SEL] = &meson8b_vdec_1_sel.hw, [CLKID_VDEC_1_1_DIV] = &meson8b_vdec_1_1_div.hw, [CLKID_VDEC_1_1] = &meson8b_vdec_1_1.hw, [CLKID_VDEC_1_2_DIV] = &meson8b_vdec_1_2_div.hw, [CLKID_VDEC_1_2] = &meson8b_vdec_1_2.hw, [CLKID_VDEC_1] = &meson8b_vdec_1.hw, [CLKID_VDEC_HCODEC_SEL] = &meson8b_vdec_hcodec_sel.hw, [CLKID_VDEC_HCODEC_DIV] = &meson8b_vdec_hcodec_div.hw, [CLKID_VDEC_HCODEC] = &meson8b_vdec_hcodec.hw, [CLKID_VDEC_2_SEL] = &meson8b_vdec_2_sel.hw, [CLKID_VDEC_2_DIV] = &meson8b_vdec_2_div.hw, [CLKID_VDEC_2] = &meson8b_vdec_2.hw, [CLKID_VDEC_HEVC_SEL] = &meson8b_vdec_hevc_sel.hw, [CLKID_VDEC_HEVC_DIV] = &meson8b_vdec_hevc_div.hw, [CLKID_VDEC_HEVC_EN] = &meson8b_vdec_hevc_en.hw, [CLKID_VDEC_HEVC] = &meson8b_vdec_hevc.hw, [CLKID_CTS_AMCLK_SEL] = &meson8b_cts_amclk_sel.hw, [CLKID_CTS_AMCLK_DIV] = &meson8b_cts_amclk_div.hw, [CLKID_CTS_AMCLK] = &meson8b_cts_amclk.hw, [CLKID_CTS_MCLK_I958_SEL] = &meson8b_cts_mclk_i958_sel.hw, [CLKID_CTS_MCLK_I958_DIV] = &meson8b_cts_mclk_i958_div.hw, [CLKID_CTS_MCLK_I958] = &meson8b_cts_mclk_i958.hw, [CLKID_CTS_I958] = &meson8b_cts_i958.hw, [CLKID_VID_PLL_LVDS_EN] = &meson8b_vid_pll_lvds_en.hw, [CLKID_HDMI_PLL_DCO_IN] = &hdmi_pll_dco_in.hw, }; static struct clk_hw *meson8m2_hw_clks[] = { [CLKID_PLL_FIXED] = &meson8b_fixed_pll.hw, [CLKID_PLL_VID] = &meson8b_vid_pll.hw, [CLKID_PLL_SYS] = &meson8b_sys_pll.hw, [CLKID_FCLK_DIV2] = &meson8b_fclk_div2.hw, [CLKID_FCLK_DIV3] = &meson8b_fclk_div3.hw, [CLKID_FCLK_DIV4] = &meson8b_fclk_div4.hw, [CLKID_FCLK_DIV5] = &meson8b_fclk_div5.hw, [CLKID_FCLK_DIV7] = &meson8b_fclk_div7.hw, [CLKID_CPUCLK] = &meson8b_cpu_clk.hw, [CLKID_MPEG_SEL] = &meson8b_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &meson8b_mpeg_clk_div.hw, [CLKID_CLK81] = &meson8b_clk81.hw, [CLKID_DDR] = &meson8b_ddr.hw, [CLKID_DOS] = &meson8b_dos.hw, [CLKID_ISA] = &meson8b_isa.hw, [CLKID_PL301] = &meson8b_pl301.hw, [CLKID_PERIPHS] = &meson8b_periphs.hw, [CLKID_SPICC] = &meson8b_spicc.hw, [CLKID_I2C] = &meson8b_i2c.hw, [CLKID_SAR_ADC] = &meson8b_sar_adc.hw, [CLKID_SMART_CARD] = &meson8b_smart_card.hw, [CLKID_RNG0] = &meson8b_rng0.hw, [CLKID_UART0] = &meson8b_uart0.hw, [CLKID_SDHC] = &meson8b_sdhc.hw, [CLKID_STREAM] = &meson8b_stream.hw, [CLKID_ASYNC_FIFO] = &meson8b_async_fifo.hw, [CLKID_SDIO] = &meson8b_sdio.hw, [CLKID_ABUF] = &meson8b_abuf.hw, [CLKID_HIU_IFACE] = &meson8b_hiu_iface.hw, [CLKID_ASSIST_MISC] = &meson8b_assist_misc.hw, [CLKID_SPI] = &meson8b_spi.hw, [CLKID_I2S_SPDIF] = &meson8b_i2s_spdif.hw, [CLKID_ETH] = &meson8b_eth.hw, [CLKID_DEMUX] = &meson8b_demux.hw, [CLKID_AIU_GLUE] = &meson8b_aiu_glue.hw, [CLKID_IEC958] = &meson8b_iec958.hw, [CLKID_I2S_OUT] = &meson8b_i2s_out.hw, [CLKID_AMCLK] = &meson8b_amclk.hw, [CLKID_AIFIFO2] = &meson8b_aififo2.hw, [CLKID_MIXER] = &meson8b_mixer.hw, [CLKID_MIXER_IFACE] = &meson8b_mixer_iface.hw, [CLKID_ADC] = &meson8b_adc.hw, [CLKID_BLKMV] = &meson8b_blkmv.hw, [CLKID_AIU] = &meson8b_aiu.hw, [CLKID_UART1] = &meson8b_uart1.hw, [CLKID_G2D] = &meson8b_g2d.hw, [CLKID_USB0] = &meson8b_usb0.hw, [CLKID_USB1] = &meson8b_usb1.hw, [CLKID_RESET] = &meson8b_reset.hw, [CLKID_NAND] = &meson8b_nand.hw, [CLKID_DOS_PARSER] = &meson8b_dos_parser.hw, [CLKID_USB] = &meson8b_usb.hw, [CLKID_VDIN1] = &meson8b_vdin1.hw, [CLKID_AHB_ARB0] = &meson8b_ahb_arb0.hw, [CLKID_EFUSE] = &meson8b_efuse.hw, [CLKID_BOOT_ROM] = &meson8b_boot_rom.hw, [CLKID_AHB_DATA_BUS] = &meson8b_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &meson8b_ahb_ctrl_bus.hw, [CLKID_HDMI_INTR_SYNC] = &meson8b_hdmi_intr_sync.hw, [CLKID_HDMI_PCLK] = &meson8b_hdmi_pclk.hw, [CLKID_USB1_DDR_BRIDGE] = &meson8b_usb1_ddr_bridge.hw, [CLKID_USB0_DDR_BRIDGE] = &meson8b_usb0_ddr_bridge.hw, [CLKID_MMC_PCLK] = &meson8b_mmc_pclk.hw, [CLKID_DVIN] = &meson8b_dvin.hw, [CLKID_UART2] = &meson8b_uart2.hw, [CLKID_SANA] = &meson8b_sana.hw, [CLKID_VPU_INTR] = &meson8b_vpu_intr.hw, [CLKID_SEC_AHB_AHB3_BRIDGE] = &meson8b_sec_ahb_ahb3_bridge.hw, [CLKID_CLK81_A9] = &meson8b_clk81_a9.hw, [CLKID_VCLK2_VENCI0] = &meson8b_vclk2_venci0.hw, [CLKID_VCLK2_VENCI1] = &meson8b_vclk2_venci1.hw, [CLKID_VCLK2_VENCP0] = &meson8b_vclk2_vencp0.hw, [CLKID_VCLK2_VENCP1] = &meson8b_vclk2_vencp1.hw, [CLKID_GCLK_VENCI_INT] = &meson8b_gclk_venci_int.hw, [CLKID_GCLK_VENCP_INT] = &meson8b_gclk_vencp_int.hw, [CLKID_DAC_CLK] = &meson8b_dac_clk.hw, [CLKID_AOCLK_GATE] = &meson8b_aoclk_gate.hw, [CLKID_IEC958_GATE] = &meson8b_iec958_gate.hw, [CLKID_ENC480P] = &meson8b_enc480p.hw, [CLKID_RNG1] = &meson8b_rng1.hw, [CLKID_GCLK_VENCL_INT] = &meson8b_gclk_vencl_int.hw, [CLKID_VCLK2_VENCLMCC] = &meson8b_vclk2_venclmcc.hw, [CLKID_VCLK2_VENCL] = &meson8b_vclk2_vencl.hw, [CLKID_VCLK2_OTHER] = &meson8b_vclk2_other.hw, [CLKID_EDP] = &meson8b_edp.hw, [CLKID_AO_MEDIA_CPU] = &meson8b_ao_media_cpu.hw, [CLKID_AO_AHB_SRAM] = &meson8b_ao_ahb_sram.hw, [CLKID_AO_AHB_BUS] = &meson8b_ao_ahb_bus.hw, [CLKID_AO_IFACE] = &meson8b_ao_iface.hw, [CLKID_MPLL0] = &meson8b_mpll0.hw, [CLKID_MPLL1] = &meson8b_mpll1.hw, [CLKID_MPLL2] = &meson8b_mpll2.hw, [CLKID_MPLL0_DIV] = &meson8b_mpll0_div.hw, [CLKID_MPLL1_DIV] = &meson8b_mpll1_div.hw, [CLKID_MPLL2_DIV] = &meson8b_mpll2_div.hw, [CLKID_CPU_IN_SEL] = &meson8b_cpu_in_sel.hw, [CLKID_CPU_IN_DIV2] = &meson8b_cpu_in_div2.hw, [CLKID_CPU_IN_DIV3] = &meson8b_cpu_in_div3.hw, [CLKID_CPU_SCALE_DIV] = &meson8b_cpu_scale_div.hw, [CLKID_CPU_SCALE_OUT_SEL] = &meson8b_cpu_scale_out_sel.hw, [CLKID_MPLL_PREDIV] = &meson8b_mpll_prediv.hw, [CLKID_FCLK_DIV2_DIV] = &meson8b_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &meson8b_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &meson8b_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &meson8b_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &meson8b_fclk_div7_div.hw, [CLKID_NAND_SEL] = &meson8b_nand_clk_sel.hw, [CLKID_NAND_DIV] = &meson8b_nand_clk_div.hw, [CLKID_NAND_CLK] = &meson8b_nand_clk_gate.hw, [CLKID_PLL_FIXED_DCO] = &meson8b_fixed_pll_dco.hw, [CLKID_HDMI_PLL_DCO] = &meson8b_hdmi_pll_dco.hw, [CLKID_PLL_SYS_DCO] = &meson8b_sys_pll_dco.hw, [CLKID_CPU_CLK_DIV2] = &meson8b_cpu_clk_div2.hw, [CLKID_CPU_CLK_DIV3] = &meson8b_cpu_clk_div3.hw, [CLKID_CPU_CLK_DIV4] = &meson8b_cpu_clk_div4.hw, [CLKID_CPU_CLK_DIV5] = &meson8b_cpu_clk_div5.hw, [CLKID_CPU_CLK_DIV6] = &meson8b_cpu_clk_div6.hw, [CLKID_CPU_CLK_DIV7] = &meson8b_cpu_clk_div7.hw, [CLKID_CPU_CLK_DIV8] = &meson8b_cpu_clk_div8.hw, [CLKID_APB_SEL] = &meson8b_apb_clk_sel.hw, [CLKID_APB] = &meson8b_apb_clk_gate.hw, [CLKID_PERIPH_SEL] = &meson8b_periph_clk_sel.hw, [CLKID_PERIPH] = &meson8b_periph_clk_gate.hw, [CLKID_AXI_SEL] = &meson8b_axi_clk_sel.hw, [CLKID_AXI] = &meson8b_axi_clk_gate.hw, [CLKID_L2_DRAM_SEL] = &meson8b_l2_dram_clk_sel.hw, [CLKID_L2_DRAM] = &meson8b_l2_dram_clk_gate.hw, [CLKID_HDMI_PLL_LVDS_OUT] = &meson8b_hdmi_pll_lvds_out.hw, [CLKID_HDMI_PLL_HDMI_OUT] = &meson8b_hdmi_pll_hdmi_out.hw, [CLKID_VID_PLL_IN_SEL] = &meson8b_vid_pll_in_sel.hw, [CLKID_VID_PLL_IN_EN] = &meson8b_vid_pll_in_en.hw, [CLKID_VID_PLL_PRE_DIV] = &meson8b_vid_pll_pre_div.hw, [CLKID_VID_PLL_POST_DIV] = &meson8b_vid_pll_post_div.hw, [CLKID_VID_PLL_FINAL_DIV] = &meson8b_vid_pll_final_div.hw, [CLKID_VCLK_IN_SEL] = &meson8b_vclk_in_sel.hw, [CLKID_VCLK_IN_EN] = &meson8b_vclk_in_en.hw, [CLKID_VCLK_EN] = &meson8b_vclk_en.hw, [CLKID_VCLK_DIV1] = &meson8b_vclk_div1_gate.hw, [CLKID_VCLK_DIV2_DIV] = &meson8b_vclk_div2_div.hw, [CLKID_VCLK_DIV2] = &meson8b_vclk_div2_div_gate.hw, [CLKID_VCLK_DIV4_DIV] = &meson8b_vclk_div4_div.hw, [CLKID_VCLK_DIV4] = &meson8b_vclk_div4_div_gate.hw, [CLKID_VCLK_DIV6_DIV] = &meson8b_vclk_div6_div.hw, [CLKID_VCLK_DIV6] = &meson8b_vclk_div6_div_gate.hw, [CLKID_VCLK_DIV12_DIV] = &meson8b_vclk_div12_div.hw, [CLKID_VCLK_DIV12] = &meson8b_vclk_div12_div_gate.hw, [CLKID_VCLK2_IN_SEL] = &meson8b_vclk2_in_sel.hw, [CLKID_VCLK2_IN_EN] = &meson8b_vclk2_clk_in_en.hw, [CLKID_VCLK2_EN] = &meson8b_vclk2_clk_en.hw, [CLKID_VCLK2_DIV1] = &meson8b_vclk2_div1_gate.hw, [CLKID_VCLK2_DIV2_DIV] = &meson8b_vclk2_div2_div.hw, [CLKID_VCLK2_DIV2] = &meson8b_vclk2_div2_div_gate.hw, [CLKID_VCLK2_DIV4_DIV] = &meson8b_vclk2_div4_div.hw, [CLKID_VCLK2_DIV4] = &meson8b_vclk2_div4_div_gate.hw, [CLKID_VCLK2_DIV6_DIV] = &meson8b_vclk2_div6_div.hw, [CLKID_VCLK2_DIV6] = &meson8b_vclk2_div6_div_gate.hw, [CLKID_VCLK2_DIV12_DIV] = &meson8b_vclk2_div12_div.hw, [CLKID_VCLK2_DIV12] = &meson8b_vclk2_div12_div_gate.hw, [CLKID_CTS_ENCT_SEL] = &meson8b_cts_enct_sel.hw, [CLKID_CTS_ENCT] = &meson8b_cts_enct.hw, [CLKID_CTS_ENCP_SEL] = &meson8b_cts_encp_sel.hw, [CLKID_CTS_ENCP] = &meson8b_cts_encp.hw, [CLKID_CTS_ENCI_SEL] = &meson8b_cts_enci_sel.hw, [CLKID_CTS_ENCI] = &meson8b_cts_enci.hw, [CLKID_HDMI_TX_PIXEL_SEL] = &meson8b_hdmi_tx_pixel_sel.hw, [CLKID_HDMI_TX_PIXEL] = &meson8b_hdmi_tx_pixel.hw, [CLKID_CTS_ENCL_SEL] = &meson8b_cts_encl_sel.hw, [CLKID_CTS_ENCL] = &meson8b_cts_encl.hw, [CLKID_CTS_VDAC0_SEL] = &meson8b_cts_vdac0_sel.hw, [CLKID_CTS_VDAC0] = &meson8b_cts_vdac0.hw, [CLKID_HDMI_SYS_SEL] = &meson8b_hdmi_sys_sel.hw, [CLKID_HDMI_SYS_DIV] = &meson8b_hdmi_sys_div.hw, [CLKID_HDMI_SYS] = &meson8b_hdmi_sys.hw, [CLKID_MALI_0_SEL] = &meson8b_mali_0_sel.hw, [CLKID_MALI_0_DIV] = &meson8b_mali_0_div.hw, [CLKID_MALI_0] = &meson8b_mali_0.hw, [CLKID_MALI_1_SEL] = &meson8b_mali_1_sel.hw, [CLKID_MALI_1_DIV] = &meson8b_mali_1_div.hw, [CLKID_MALI_1] = &meson8b_mali_1.hw, [CLKID_MALI] = &meson8b_mali.hw, [CLKID_GP_PLL_DCO] = &meson8m2_gp_pll_dco.hw, [CLKID_GP_PLL] = &meson8m2_gp_pll.hw, [CLKID_VPU_0_SEL] = &meson8m2_vpu_0_sel.hw, [CLKID_VPU_0_DIV] = &meson8b_vpu_0_div.hw, [CLKID_VPU_0] = &meson8b_vpu_0.hw, [CLKID_VPU_1_SEL] = &meson8m2_vpu_1_sel.hw, [CLKID_VPU_1_DIV] = &meson8b_vpu_1_div.hw, [CLKID_VPU_1] = &meson8b_vpu_1.hw, [CLKID_VPU] = &meson8b_vpu.hw, [CLKID_VDEC_1_SEL] = &meson8b_vdec_1_sel.hw, [CLKID_VDEC_1_1_DIV] = &meson8b_vdec_1_1_div.hw, [CLKID_VDEC_1_1] = &meson8b_vdec_1_1.hw, [CLKID_VDEC_1_2_DIV] = &meson8b_vdec_1_2_div.hw, [CLKID_VDEC_1_2] = &meson8b_vdec_1_2.hw, [CLKID_VDEC_1] = &meson8b_vdec_1.hw, [CLKID_VDEC_HCODEC_SEL] = &meson8b_vdec_hcodec_sel.hw, [CLKID_VDEC_HCODEC_DIV] = &meson8b_vdec_hcodec_div.hw, [CLKID_VDEC_HCODEC] = &meson8b_vdec_hcodec.hw, [CLKID_VDEC_2_SEL] = &meson8b_vdec_2_sel.hw, [CLKID_VDEC_2_DIV] = &meson8b_vdec_2_div.hw, [CLKID_VDEC_2] = &meson8b_vdec_2.hw, [CLKID_VDEC_HEVC_SEL] = &meson8b_vdec_hevc_sel.hw, [CLKID_VDEC_HEVC_DIV] = &meson8b_vdec_hevc_div.hw, [CLKID_VDEC_HEVC_EN] = &meson8b_vdec_hevc_en.hw, [CLKID_VDEC_HEVC] = &meson8b_vdec_hevc.hw, [CLKID_CTS_AMCLK_SEL] = &meson8b_cts_amclk_sel.hw, [CLKID_CTS_AMCLK_DIV] = &meson8b_cts_amclk_div.hw, [CLKID_CTS_AMCLK] = &meson8b_cts_amclk.hw, [CLKID_CTS_MCLK_I958_SEL] = &meson8b_cts_mclk_i958_sel.hw, [CLKID_CTS_MCLK_I958_DIV] = &meson8b_cts_mclk_i958_div.hw, [CLKID_CTS_MCLK_I958] = &meson8b_cts_mclk_i958.hw, [CLKID_CTS_I958] = &meson8b_cts_i958.hw, [CLKID_VID_PLL_LVDS_EN] = &meson8b_vid_pll_lvds_en.hw, [CLKID_HDMI_PLL_DCO_IN] = &hdmi_pll_dco_in.hw, }; static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_clk81, &meson8b_ddr, &meson8b_dos, &meson8b_isa, &meson8b_pl301, &meson8b_periphs, &meson8b_spicc, &meson8b_i2c, &meson8b_sar_adc, &meson8b_smart_card, &meson8b_rng0, &meson8b_uart0, &meson8b_sdhc, &meson8b_stream, &meson8b_async_fifo, &meson8b_sdio, &meson8b_abuf, &meson8b_hiu_iface, &meson8b_assist_misc, &meson8b_spi, &meson8b_i2s_spdif, &meson8b_eth, &meson8b_demux, &meson8b_aiu_glue, &meson8b_iec958, &meson8b_i2s_out, &meson8b_amclk, &meson8b_aififo2, &meson8b_mixer, &meson8b_mixer_iface, &meson8b_adc, &meson8b_blkmv, &meson8b_aiu, &meson8b_uart1, &meson8b_g2d, &meson8b_usb0, &meson8b_usb1, &meson8b_reset, &meson8b_nand, &meson8b_dos_parser, &meson8b_usb, &meson8b_vdin1, &meson8b_ahb_arb0, &meson8b_efuse, &meson8b_boot_rom, &meson8b_ahb_data_bus, &meson8b_ahb_ctrl_bus, &meson8b_hdmi_intr_sync, &meson8b_hdmi_pclk, &meson8b_usb1_ddr_bridge, &meson8b_usb0_ddr_bridge, &meson8b_mmc_pclk, &meson8b_dvin, &meson8b_uart2, &meson8b_sana, &meson8b_vpu_intr, &meson8b_sec_ahb_ahb3_bridge, &meson8b_clk81_a9, &meson8b_vclk2_venci0, &meson8b_vclk2_venci1, &meson8b_vclk2_vencp0, &meson8b_vclk2_vencp1, &meson8b_gclk_venci_int, &meson8b_gclk_vencp_int, &meson8b_dac_clk, &meson8b_aoclk_gate, &meson8b_iec958_gate, &meson8b_enc480p, &meson8b_rng1, &meson8b_gclk_vencl_int, &meson8b_vclk2_venclmcc, &meson8b_vclk2_vencl, &meson8b_vclk2_other, &meson8b_edp, &meson8b_ao_media_cpu, &meson8b_ao_ahb_sram, &meson8b_ao_ahb_bus, &meson8b_ao_iface, &meson8b_mpeg_clk_div, &meson8b_mpeg_clk_sel, &meson8b_mpll0, &meson8b_mpll1, &meson8b_mpll2, &meson8b_mpll0_div, &meson8b_mpll1_div, &meson8b_mpll2_div, &meson8b_fixed_pll, &meson8b_sys_pll, &meson8b_cpu_in_sel, &meson8b_cpu_scale_div, &meson8b_cpu_scale_out_sel, &meson8b_cpu_clk, &meson8b_mpll_prediv, &meson8b_fclk_div2, &meson8b_fclk_div3, &meson8b_fclk_div4, &meson8b_fclk_div5, &meson8b_fclk_div7, &meson8b_nand_clk_sel, &meson8b_nand_clk_div, &meson8b_nand_clk_gate, &meson8b_fixed_pll_dco, &meson8b_hdmi_pll_dco, &meson8b_sys_pll_dco, &meson8b_apb_clk_sel, &meson8b_apb_clk_gate, &meson8b_periph_clk_sel, &meson8b_periph_clk_gate, &meson8b_axi_clk_sel, &meson8b_axi_clk_gate, &meson8b_l2_dram_clk_sel, &meson8b_l2_dram_clk_gate, &meson8b_hdmi_pll_lvds_out, &meson8b_hdmi_pll_hdmi_out, &meson8b_vid_pll_in_sel, &meson8b_vid_pll_in_en, &meson8b_vid_pll_pre_div, &meson8b_vid_pll_post_div, &meson8b_vid_pll, &meson8b_vid_pll_final_div, &meson8b_vclk_in_sel, &meson8b_vclk_in_en, &meson8b_vclk_en, &meson8b_vclk_div1_gate, &meson8b_vclk_div2_div_gate, &meson8b_vclk_div4_div_gate, &meson8b_vclk_div6_div_gate, &meson8b_vclk_div12_div_gate, &meson8b_vclk2_in_sel, &meson8b_vclk2_clk_in_en, &meson8b_vclk2_clk_en, &meson8b_vclk2_div1_gate, &meson8b_vclk2_div2_div_gate, &meson8b_vclk2_div4_div_gate, &meson8b_vclk2_div6_div_gate, &meson8b_vclk2_div12_div_gate, &meson8b_cts_enct_sel, &meson8b_cts_enct, &meson8b_cts_encp_sel, &meson8b_cts_encp, &meson8b_cts_enci_sel, &meson8b_cts_enci, &meson8b_hdmi_tx_pixel_sel, &meson8b_hdmi_tx_pixel, &meson8b_cts_encl_sel, &meson8b_cts_encl, &meson8b_cts_vdac0_sel, &meson8b_cts_vdac0, &meson8b_hdmi_sys_sel, &meson8b_hdmi_sys_div, &meson8b_hdmi_sys, &meson8b_mali_0_sel, &meson8b_mali_0_div, &meson8b_mali_0, &meson8b_mali_1_sel, &meson8b_mali_1_div, &meson8b_mali_1, &meson8b_mali, &meson8m2_gp_pll_dco, &meson8m2_gp_pll, &meson8b_vpu_0_sel, &meson8m2_vpu_0_sel, &meson8b_vpu_0_div, &meson8b_vpu_0, &meson8b_vpu_1_sel, &meson8m2_vpu_1_sel, &meson8b_vpu_1_div, &meson8b_vpu_1, &meson8b_vpu, &meson8b_vdec_1_sel, &meson8b_vdec_1_1_div, &meson8b_vdec_1_1, &meson8b_vdec_1_2_div, &meson8b_vdec_1_2, &meson8b_vdec_1, &meson8b_vdec_hcodec_sel, &meson8b_vdec_hcodec_div, &meson8b_vdec_hcodec, &meson8b_vdec_2_sel, &meson8b_vdec_2_div, &meson8b_vdec_2, &meson8b_vdec_hevc_sel, &meson8b_vdec_hevc_div, &meson8b_vdec_hevc_en, &meson8b_vdec_hevc, &meson8b_cts_amclk, &meson8b_cts_amclk_sel, &meson8b_cts_amclk_div, &meson8b_cts_mclk_i958_sel, &meson8b_cts_mclk_i958_div, &meson8b_cts_mclk_i958, &meson8b_cts_i958, &meson8b_vid_pll_lvds_en, }; static const struct meson8b_clk_reset_line { u32 reg; u8 bit_idx; bool active_low; } meson8b_clk_reset_bits[] = { [CLKC_RESET_L2_CACHE_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 30, .active_low = false, }, [CLKC_RESET_AXI_64_TO_128_BRIDGE_A5_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 29, .active_low = false, }, [CLKC_RESET_SCU_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 28, .active_low = false, }, [CLKC_RESET_CPU3_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 27, .active_low = false, }, [CLKC_RESET_CPU2_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 26, .active_low = false, }, [CLKC_RESET_CPU1_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 25, .active_low = false, }, [CLKC_RESET_CPU0_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 24, .active_low = false, }, [CLKC_RESET_A5_GLOBAL_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 18, .active_low = false, }, [CLKC_RESET_A5_AXI_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 17, .active_low = false, }, [CLKC_RESET_A5_ABP_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL0, .bit_idx = 16, .active_low = false, }, [CLKC_RESET_AXI_64_TO_128_BRIDGE_MMC_SOFT_RESET] = { .reg = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 30, .active_low = false, }, [CLKC_RESET_VID_CLK_CNTL_SOFT_RESET] = { .reg = HHI_VID_CLK_CNTL, .bit_idx = 15, .active_low = false, }, [CLKC_RESET_VID_DIVIDER_CNTL_SOFT_RESET_POST] = { .reg = HHI_VID_DIVIDER_CNTL, .bit_idx = 7, .active_low = false, }, [CLKC_RESET_VID_DIVIDER_CNTL_SOFT_RESET_PRE] = { .reg = HHI_VID_DIVIDER_CNTL, .bit_idx = 3, .active_low = false, }, [CLKC_RESET_VID_DIVIDER_CNTL_RESET_N_POST] = { .reg = HHI_VID_DIVIDER_CNTL, .bit_idx = 1, .active_low = true, }, [CLKC_RESET_VID_DIVIDER_CNTL_RESET_N_PRE] = { .reg = HHI_VID_DIVIDER_CNTL, .bit_idx = 0, .active_low = true, }, }; static int meson8b_clk_reset_update(struct reset_controller_dev *rcdev, unsigned long id, bool assert) { struct meson8b_clk_reset *meson8b_clk_reset = container_of(rcdev, struct meson8b_clk_reset, reset); const struct meson8b_clk_reset_line *reset; unsigned int value = 0; unsigned long flags; if (id >= ARRAY_SIZE(meson8b_clk_reset_bits)) return -EINVAL; reset = &meson8b_clk_reset_bits[id]; if (assert != reset->active_low) value = BIT(reset->bit_idx); spin_lock_irqsave(&meson_clk_lock, flags); regmap_update_bits(meson8b_clk_reset->regmap, reset->reg, BIT(reset->bit_idx), value); spin_unlock_irqrestore(&meson_clk_lock, flags); return 0; } static int meson8b_clk_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) { return meson8b_clk_reset_update(rcdev, id, true); } static int meson8b_clk_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) { return meson8b_clk_reset_update(rcdev, id, false); } static const struct reset_control_ops meson8b_clk_reset_ops = { .assert = meson8b_clk_reset_assert, .deassert = meson8b_clk_reset_deassert, }; struct meson8b_nb_data { struct notifier_block nb; struct clk_hw *cpu_clk; }; static int meson8b_cpu_clk_notifier_cb(struct notifier_block *nb, unsigned long event, void *data) { struct meson8b_nb_data *nb_data = container_of(nb, struct meson8b_nb_data, nb); struct clk_hw *parent_clk; int ret; switch (event) { case PRE_RATE_CHANGE: /* xtal */ parent_clk = clk_hw_get_parent_by_index(nb_data->cpu_clk, 0); break; case POST_RATE_CHANGE: /* cpu_scale_out_sel */ parent_clk = clk_hw_get_parent_by_index(nb_data->cpu_clk, 1); break; default: return NOTIFY_DONE; } ret = clk_hw_set_parent(nb_data->cpu_clk, parent_clk); if (ret) return notifier_from_errno(ret); udelay(100); return NOTIFY_OK; } static struct meson8b_nb_data meson8b_cpu_nb_data = { .nb.notifier_call = meson8b_cpu_clk_notifier_cb, }; static struct meson_clk_hw_data meson8_clks = { .hws = meson8_hw_clks, .num = ARRAY_SIZE(meson8_hw_clks), }; static struct meson_clk_hw_data meson8b_clks = { .hws = meson8b_hw_clks, .num = ARRAY_SIZE(meson8b_hw_clks), }; static struct meson_clk_hw_data meson8m2_clks = { .hws = meson8m2_hw_clks, .num = ARRAY_SIZE(meson8m2_hw_clks), }; static void __init meson8b_clkc_init_common(struct device_node *np, struct meson_clk_hw_data *hw_clks) { struct meson8b_clk_reset *rstc; struct device_node *parent_np; const char *notifier_clk_name; struct clk *notifier_clk; struct regmap *map; int i, ret; parent_np = of_get_parent(np); map = syscon_node_to_regmap(parent_np); of_node_put(parent_np); if (IS_ERR(map)) { pr_err("failed to get HHI regmap - Trying obsolete regs\n"); return; } rstc = kzalloc(sizeof(*rstc), GFP_KERNEL); if (!rstc) return; /* Reset Controller */ rstc->regmap = map; rstc->reset.ops = &meson8b_clk_reset_ops; rstc->reset.nr_resets = ARRAY_SIZE(meson8b_clk_reset_bits); rstc->reset.of_node = np; ret = reset_controller_register(&rstc->reset); if (ret) { pr_err("%s: Failed to register clkc reset controller: %d\n", __func__, ret); return; } /* Populate regmap for the regmap backed clocks */ for (i = 0; i < ARRAY_SIZE(meson8b_clk_regmaps); i++) meson8b_clk_regmaps[i]->map = map; /* * register all clks and start with the first used ID (which is * CLKID_PLL_FIXED) */ for (i = CLKID_PLL_FIXED; i < hw_clks->num; i++) { /* array might be sparse */ if (!hw_clks->hws[i]) continue; ret = of_clk_hw_register(np, hw_clks->hws[i]); if (ret) return; } meson8b_cpu_nb_data.cpu_clk = hw_clks->hws[CLKID_CPUCLK]; /* * FIXME we shouldn't program the muxes in notifier handlers. The * tricky programming sequence will be handled by the forthcoming * coordinated clock rates mechanism once that feature is released. */ notifier_clk_name = clk_hw_get_name(&meson8b_cpu_scale_out_sel.hw); notifier_clk = __clk_lookup(notifier_clk_name); ret = clk_notifier_register(notifier_clk, &meson8b_cpu_nb_data.nb); if (ret) { pr_err("%s: failed to register the CPU clock notifier\n", __func__); return; } ret = of_clk_add_hw_provider(np, meson_clk_hw_get, hw_clks); if (ret) pr_err("%s: failed to register clock provider\n", __func__); } static void __init meson8_clkc_init(struct device_node *np) { return meson8b_clkc_init_common(np, &meson8_clks); } static void __init meson8b_clkc_init(struct device_node *np) { return meson8b_clkc_init_common(np, &meson8b_clks); } static void __init meson8m2_clkc_init(struct device_node *np) { return meson8b_clkc_init_common(np, &meson8m2_clks); } CLK_OF_DECLARE_DRIVER(meson8_clkc, "amlogic,meson8-clkc", meson8_clkc_init); CLK_OF_DECLARE_DRIVER(meson8b_clkc, "amlogic,meson8b-clkc", meson8b_clkc_init); CLK_OF_DECLARE_DRIVER(meson8m2_clkc, "amlogic,meson8m2-clkc", meson8m2_clkc_init);
linux-master
drivers/clk/meson/meson8b.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2015 Endless Mobile, Inc. * Author: Carlo Caione <[email protected]> * * Copyright (c) 2018 Baylibre, SAS. * Author: Jerome Brunet <[email protected]> */ /* * In the most basic form, a Meson PLL is composed as follows: * * PLL * +--------------------------------+ * | | * | +--+ | * in >>-----[ /N ]--->| | +-----+ | * | | |------| DCO |---->> out * | +--------->| | +--v--+ | * | | +--+ | | * | | | | * | +--[ *(M + (F/Fmax) ]<--+ | * | | * +--------------------------------+ * * out = in * (m + frac / frac_max) / n */ #include <linux/clk-provider.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/io.h> #include <linux/math64.h> #include <linux/module.h> #include "clk-regmap.h" #include "clk-pll.h" static inline struct meson_clk_pll_data * meson_clk_pll_data(struct clk_regmap *clk) { return (struct meson_clk_pll_data *)clk->data; } static int __pll_round_closest_mult(struct meson_clk_pll_data *pll) { if ((pll->flags & CLK_MESON_PLL_ROUND_CLOSEST) && !MESON_PARM_APPLICABLE(&pll->frac)) return 1; return 0; } static unsigned long __pll_params_to_rate(unsigned long parent_rate, unsigned int m, unsigned int n, unsigned int frac, struct meson_clk_pll_data *pll) { u64 rate = (u64)parent_rate * m; if (frac && MESON_PARM_APPLICABLE(&pll->frac)) { u64 frac_rate = (u64)parent_rate * frac; rate += DIV_ROUND_UP_ULL(frac_rate, (1 << pll->frac.width)); } return DIV_ROUND_UP_ULL(rate, n); } static unsigned long meson_clk_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); unsigned int m, n, frac; n = meson_parm_read(clk->map, &pll->n); /* * On some HW, N is set to zero on init. This value is invalid as * it would result in a division by zero. The rate can't be * calculated in this case */ if (n == 0) return 0; m = meson_parm_read(clk->map, &pll->m); frac = MESON_PARM_APPLICABLE(&pll->frac) ? meson_parm_read(clk->map, &pll->frac) : 0; return __pll_params_to_rate(parent_rate, m, n, frac, pll); } static unsigned int __pll_params_with_frac(unsigned long rate, unsigned long parent_rate, unsigned int m, unsigned int n, struct meson_clk_pll_data *pll) { unsigned int frac_max = (1 << pll->frac.width); u64 val = (u64)rate * n; /* Bail out if we are already over the requested rate */ if (rate < parent_rate * m / n) return 0; if (pll->flags & CLK_MESON_PLL_ROUND_CLOSEST) val = DIV_ROUND_CLOSEST_ULL(val * frac_max, parent_rate); else val = div_u64(val * frac_max, parent_rate); val -= m * frac_max; return min((unsigned int)val, (frac_max - 1)); } static bool meson_clk_pll_is_better(unsigned long rate, unsigned long best, unsigned long now, struct meson_clk_pll_data *pll) { if (__pll_round_closest_mult(pll)) { /* Round Closest */ if (abs(now - rate) < abs(best - rate)) return true; } else { /* Round down */ if (now <= rate && best < now) return true; } return false; } static int meson_clk_get_pll_table_index(unsigned int index, unsigned int *m, unsigned int *n, struct meson_clk_pll_data *pll) { if (!pll->table[index].n) return -EINVAL; *m = pll->table[index].m; *n = pll->table[index].n; return 0; } static unsigned int meson_clk_get_pll_range_m(unsigned long rate, unsigned long parent_rate, unsigned int n, struct meson_clk_pll_data *pll) { u64 val = (u64)rate * n; if (__pll_round_closest_mult(pll)) return DIV_ROUND_CLOSEST_ULL(val, parent_rate); return div_u64(val, parent_rate); } static int meson_clk_get_pll_range_index(unsigned long rate, unsigned long parent_rate, unsigned int index, unsigned int *m, unsigned int *n, struct meson_clk_pll_data *pll) { *n = index + 1; /* Check the predivider range */ if (*n >= (1 << pll->n.width)) return -EINVAL; if (*n == 1) { /* Get the boundaries out the way */ if (rate <= pll->range->min * parent_rate) { *m = pll->range->min; return -ENODATA; } else if (rate >= pll->range->max * parent_rate) { *m = pll->range->max; return -ENODATA; } } *m = meson_clk_get_pll_range_m(rate, parent_rate, *n, pll); /* the pre-divider gives a multiplier too big - stop */ if (*m >= (1 << pll->m.width)) return -EINVAL; return 0; } static int meson_clk_get_pll_get_index(unsigned long rate, unsigned long parent_rate, unsigned int index, unsigned int *m, unsigned int *n, struct meson_clk_pll_data *pll) { if (pll->range) return meson_clk_get_pll_range_index(rate, parent_rate, index, m, n, pll); else if (pll->table) return meson_clk_get_pll_table_index(index, m, n, pll); return -EINVAL; } static int meson_clk_get_pll_settings(unsigned long rate, unsigned long parent_rate, unsigned int *best_m, unsigned int *best_n, struct meson_clk_pll_data *pll) { unsigned long best = 0, now = 0; unsigned int i, m, n; int ret; for (i = 0, ret = 0; !ret; i++) { ret = meson_clk_get_pll_get_index(rate, parent_rate, i, &m, &n, pll); if (ret == -EINVAL) break; now = __pll_params_to_rate(parent_rate, m, n, 0, pll); if (meson_clk_pll_is_better(rate, best, now, pll)) { best = now; *best_m = m; *best_n = n; if (now == rate) break; } } return best ? 0 : -EINVAL; } static int meson_clk_pll_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); unsigned int m, n, frac; unsigned long round; int ret; ret = meson_clk_get_pll_settings(req->rate, req->best_parent_rate, &m, &n, pll); if (ret) return ret; round = __pll_params_to_rate(req->best_parent_rate, m, n, 0, pll); if (!MESON_PARM_APPLICABLE(&pll->frac) || req->rate == round) { req->rate = round; return 0; } /* * The rate provided by the setting is not an exact match, let's * try to improve the result using the fractional parameter */ frac = __pll_params_with_frac(req->rate, req->best_parent_rate, m, n, pll); req->rate = __pll_params_to_rate(req->best_parent_rate, m, n, frac, pll); return 0; } static int meson_clk_pll_wait_lock(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); int delay = 5000; do { /* Is the clock locked now ? Time out after 100ms. */ if (meson_parm_read(clk->map, &pll->l)) return 0; udelay(20); } while (--delay); return -ETIMEDOUT; } static int meson_clk_pll_init(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); if (pll->init_count) { if (MESON_PARM_APPLICABLE(&pll->rst)) meson_parm_write(clk->map, &pll->rst, 1); regmap_multi_reg_write(clk->map, pll->init_regs, pll->init_count); if (MESON_PARM_APPLICABLE(&pll->rst)) meson_parm_write(clk->map, &pll->rst, 0); } return 0; } static int meson_clk_pll_is_enabled(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); if (MESON_PARM_APPLICABLE(&pll->rst) && meson_parm_read(clk->map, &pll->rst)) return 0; if (!meson_parm_read(clk->map, &pll->en) || !meson_parm_read(clk->map, &pll->l)) return 0; return 1; } static int meson_clk_pcie_pll_enable(struct clk_hw *hw) { int retries = 10; do { meson_clk_pll_init(hw); if (!meson_clk_pll_wait_lock(hw)) return 0; pr_info("Retry enabling PCIe PLL clock\n"); } while (--retries); return -EIO; } static int meson_clk_pll_enable(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); /* do nothing if the PLL is already enabled */ if (clk_hw_is_enabled(hw)) return 0; /* Make sure the pll is in reset */ if (MESON_PARM_APPLICABLE(&pll->rst)) meson_parm_write(clk->map, &pll->rst, 1); /* Enable the pll */ meson_parm_write(clk->map, &pll->en, 1); /* Take the pll out reset */ if (MESON_PARM_APPLICABLE(&pll->rst)) meson_parm_write(clk->map, &pll->rst, 0); /* * Compared with the previous SoCs, self-adaption current module * is newly added for A1, keep the new power-on sequence to enable the * PLL. The sequence is: * 1. enable the pll, delay for 10us * 2. enable the pll self-adaption current module, delay for 40us * 3. enable the lock detect module */ if (MESON_PARM_APPLICABLE(&pll->current_en)) { udelay(10); meson_parm_write(clk->map, &pll->current_en, 1); udelay(40); } if (MESON_PARM_APPLICABLE(&pll->l_detect)) { meson_parm_write(clk->map, &pll->l_detect, 1); meson_parm_write(clk->map, &pll->l_detect, 0); } if (meson_clk_pll_wait_lock(hw)) return -EIO; return 0; } static void meson_clk_pll_disable(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); /* Put the pll is in reset */ if (MESON_PARM_APPLICABLE(&pll->rst)) meson_parm_write(clk->map, &pll->rst, 1); /* Disable the pll */ meson_parm_write(clk->map, &pll->en, 0); /* Disable PLL internal self-adaption current module */ if (MESON_PARM_APPLICABLE(&pll->current_en)) meson_parm_write(clk->map, &pll->current_en, 0); } static int meson_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); unsigned int enabled, m, n, frac = 0; unsigned long old_rate; int ret; if (parent_rate == 0 || rate == 0) return -EINVAL; old_rate = clk_hw_get_rate(hw); ret = meson_clk_get_pll_settings(rate, parent_rate, &m, &n, pll); if (ret) return ret; enabled = meson_parm_read(clk->map, &pll->en); if (enabled) meson_clk_pll_disable(hw); meson_parm_write(clk->map, &pll->n, n); meson_parm_write(clk->map, &pll->m, m); if (MESON_PARM_APPLICABLE(&pll->frac)) { frac = __pll_params_with_frac(rate, parent_rate, m, n, pll); meson_parm_write(clk->map, &pll->frac, frac); } /* If the pll is stopped, bail out now */ if (!enabled) return 0; ret = meson_clk_pll_enable(hw); if (ret) { pr_warn("%s: pll did not lock, trying to restore old rate %lu\n", __func__, old_rate); /* * FIXME: Do we really need/want this HACK ? * It looks unsafe. what happens if the clock gets into a * broken state and we can't lock back on the old_rate ? Looks * like an infinite recursion is possible */ meson_clk_pll_set_rate(hw, old_rate, parent_rate); } return ret; } /* * The Meson G12A PCIE PLL is fined tuned to deliver a very precise * 100MHz reference clock for the PCIe Analog PHY, and thus requires * a strict register sequence to enable the PLL. * To simplify, re-use the _init() op to enable the PLL and keep * the other ops except set_rate since the rate is fixed. */ const struct clk_ops meson_clk_pcie_pll_ops = { .recalc_rate = meson_clk_pll_recalc_rate, .determine_rate = meson_clk_pll_determine_rate, .is_enabled = meson_clk_pll_is_enabled, .enable = meson_clk_pcie_pll_enable, .disable = meson_clk_pll_disable }; EXPORT_SYMBOL_GPL(meson_clk_pcie_pll_ops); const struct clk_ops meson_clk_pll_ops = { .init = meson_clk_pll_init, .recalc_rate = meson_clk_pll_recalc_rate, .determine_rate = meson_clk_pll_determine_rate, .set_rate = meson_clk_pll_set_rate, .is_enabled = meson_clk_pll_is_enabled, .enable = meson_clk_pll_enable, .disable = meson_clk_pll_disable }; EXPORT_SYMBOL_GPL(meson_clk_pll_ops); const struct clk_ops meson_clk_pll_ro_ops = { .recalc_rate = meson_clk_pll_recalc_rate, .is_enabled = meson_clk_pll_is_enabled, }; EXPORT_SYMBOL_GPL(meson_clk_pll_ro_ops); MODULE_DESCRIPTION("Amlogic PLL driver"); MODULE_AUTHOR("Carlo Caione <[email protected]>"); MODULE_AUTHOR("Jerome Brunet <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/clk-pll.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2017 BayLibre, SAS * Author: Neil Armstrong <[email protected]> * Author: Jerome Brunet <[email protected]> */ /* * The AO Domain embeds a dual/divider to generate a more precise * 32,768KHz clock for low-power suspend mode and CEC. * ______ ______ * | | | | * | Div1 |-| Cnt1 | * /|______| |______|\ * -| ______ ______ X--> Out * \| | | |/ * | Div2 |-| Cnt2 | * |______| |______| * * The dividing can be switched to single or dual, with a counter * for each divider to set when the switching is done. */ #include <linux/clk-provider.h> #include <linux/module.h> #include "clk-regmap.h" #include "clk-dualdiv.h" static inline struct meson_clk_dualdiv_data * meson_clk_dualdiv_data(struct clk_regmap *clk) { return (struct meson_clk_dualdiv_data *)clk->data; } static unsigned long __dualdiv_param_to_rate(unsigned long parent_rate, const struct meson_clk_dualdiv_param *p) { if (!p->dual) return DIV_ROUND_CLOSEST(parent_rate, p->n1); return DIV_ROUND_CLOSEST(parent_rate * (p->m1 + p->m2), p->n1 * p->m1 + p->n2 * p->m2); } static unsigned long meson_clk_dualdiv_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_dualdiv_data *dualdiv = meson_clk_dualdiv_data(clk); struct meson_clk_dualdiv_param setting; setting.dual = meson_parm_read(clk->map, &dualdiv->dual); setting.n1 = meson_parm_read(clk->map, &dualdiv->n1) + 1; setting.m1 = meson_parm_read(clk->map, &dualdiv->m1) + 1; setting.n2 = meson_parm_read(clk->map, &dualdiv->n2) + 1; setting.m2 = meson_parm_read(clk->map, &dualdiv->m2) + 1; return __dualdiv_param_to_rate(parent_rate, &setting); } static const struct meson_clk_dualdiv_param * __dualdiv_get_setting(unsigned long rate, unsigned long parent_rate, struct meson_clk_dualdiv_data *dualdiv) { const struct meson_clk_dualdiv_param *table = dualdiv->table; unsigned long best = 0, now = 0; unsigned int i, best_i = 0; if (!table) return NULL; for (i = 0; table[i].n1; i++) { now = __dualdiv_param_to_rate(parent_rate, &table[i]); /* If we get an exact match, don't bother any further */ if (now == rate) { return &table[i]; } else if (abs(now - rate) < abs(best - rate)) { best = now; best_i = i; } } return (struct meson_clk_dualdiv_param *)&table[best_i]; } static int meson_clk_dualdiv_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_dualdiv_data *dualdiv = meson_clk_dualdiv_data(clk); const struct meson_clk_dualdiv_param *setting; setting = __dualdiv_get_setting(req->rate, req->best_parent_rate, dualdiv); if (setting) req->rate = __dualdiv_param_to_rate(req->best_parent_rate, setting); else req->rate = meson_clk_dualdiv_recalc_rate(hw, req->best_parent_rate); return 0; } static int meson_clk_dualdiv_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_dualdiv_data *dualdiv = meson_clk_dualdiv_data(clk); const struct meson_clk_dualdiv_param *setting = __dualdiv_get_setting(rate, parent_rate, dualdiv); if (!setting) return -EINVAL; meson_parm_write(clk->map, &dualdiv->dual, setting->dual); meson_parm_write(clk->map, &dualdiv->n1, setting->n1 - 1); meson_parm_write(clk->map, &dualdiv->m1, setting->m1 - 1); meson_parm_write(clk->map, &dualdiv->n2, setting->n2 - 1); meson_parm_write(clk->map, &dualdiv->m2, setting->m2 - 1); return 0; } const struct clk_ops meson_clk_dualdiv_ops = { .recalc_rate = meson_clk_dualdiv_recalc_rate, .determine_rate = meson_clk_dualdiv_determine_rate, .set_rate = meson_clk_dualdiv_set_rate, }; EXPORT_SYMBOL_GPL(meson_clk_dualdiv_ops); const struct clk_ops meson_clk_dualdiv_ro_ops = { .recalc_rate = meson_clk_dualdiv_recalc_rate, }; EXPORT_SYMBOL_GPL(meson_clk_dualdiv_ro_ops); MODULE_DESCRIPTION("Amlogic dual divider driver"); MODULE_AUTHOR("Neil Armstrong <[email protected]>"); MODULE_AUTHOR("Jerome Brunet <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/clk-dualdiv.c
// SPDX-License-Identifier: GPL-2.0+ /* * AmLogic Meson-AXG Clock Controller Driver * * Copyright (c) 2016 Baylibre SAS. * Author: Michael Turquette <[email protected]> * * Copyright (c) 2017 Amlogic, inc. * Author: Qiufang Dai <[email protected]> */ #include <linux/clk-provider.h> #include <linux/init.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include <linux/module.h> #include "clk-regmap.h" #include "clk-pll.h" #include "clk-mpll.h" #include "axg.h" #include "meson-eeclk.h" #include <dt-bindings/clock/axg-clkc.h> static DEFINE_SPINLOCK(meson_clk_lock); static struct clk_regmap axg_fixed_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_MPLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_MPLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_MPLL_CNTL, .shift = 9, .width = 5, }, .frac = { .reg_off = HHI_MPLL_CNTL2, .shift = 0, .width = 12, }, .l = { .reg_off = HHI_MPLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_MPLL_CNTL, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap axg_fixed_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fixed_pll_dco.hw }, .num_parents = 1, /* * This clock won't ever change at runtime so * CLK_SET_RATE_PARENT is not required */ }, }; static struct clk_regmap axg_sys_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 9, .width = 5, }, .l = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "sys_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap axg_sys_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "sys_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &axg_sys_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct pll_params_table axg_gp0_pll_params_table[] = { PLL_PARAMS(40, 1), PLL_PARAMS(41, 1), PLL_PARAMS(42, 1), PLL_PARAMS(43, 1), PLL_PARAMS(44, 1), PLL_PARAMS(45, 1), PLL_PARAMS(46, 1), PLL_PARAMS(47, 1), PLL_PARAMS(48, 1), PLL_PARAMS(49, 1), PLL_PARAMS(50, 1), PLL_PARAMS(51, 1), PLL_PARAMS(52, 1), PLL_PARAMS(53, 1), PLL_PARAMS(54, 1), PLL_PARAMS(55, 1), PLL_PARAMS(56, 1), PLL_PARAMS(57, 1), PLL_PARAMS(58, 1), PLL_PARAMS(59, 1), PLL_PARAMS(60, 1), PLL_PARAMS(61, 1), PLL_PARAMS(62, 1), PLL_PARAMS(63, 1), PLL_PARAMS(64, 1), PLL_PARAMS(65, 1), PLL_PARAMS(66, 1), PLL_PARAMS(67, 1), PLL_PARAMS(68, 1), { /* sentinel */ }, }; static const struct reg_sequence axg_gp0_init_regs[] = { { .reg = HHI_GP0_PLL_CNTL1, .def = 0xc084b000 }, { .reg = HHI_GP0_PLL_CNTL2, .def = 0xb75020be }, { .reg = HHI_GP0_PLL_CNTL3, .def = 0x0a59a288 }, { .reg = HHI_GP0_PLL_CNTL4, .def = 0xc000004d }, { .reg = HHI_GP0_PLL_CNTL5, .def = 0x00078000 }, }; static struct clk_regmap axg_gp0_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 9, .width = 5, }, .frac = { .reg_off = HHI_GP0_PLL_CNTL1, .shift = 0, .width = 10, }, .l = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 29, .width = 1, }, .table = axg_gp0_pll_params_table, .init_regs = axg_gp0_init_regs, .init_count = ARRAY_SIZE(axg_gp0_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "gp0_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap axg_gp0_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_GP0_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "gp0_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_gp0_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct reg_sequence axg_hifi_init_regs[] = { { .reg = HHI_HIFI_PLL_CNTL1, .def = 0xc084b000 }, { .reg = HHI_HIFI_PLL_CNTL2, .def = 0xb75020be }, { .reg = HHI_HIFI_PLL_CNTL3, .def = 0x0a6a3a88 }, { .reg = HHI_HIFI_PLL_CNTL4, .def = 0xc000004d }, { .reg = HHI_HIFI_PLL_CNTL5, .def = 0x00058000 }, }; static struct clk_regmap axg_hifi_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_HIFI_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_HIFI_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_HIFI_PLL_CNTL, .shift = 9, .width = 5, }, .frac = { .reg_off = HHI_HIFI_PLL_CNTL5, .shift = 0, .width = 13, }, .l = { .reg_off = HHI_HIFI_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_HIFI_PLL_CNTL, .shift = 29, .width = 1, }, .table = axg_gp0_pll_params_table, .init_regs = axg_hifi_init_regs, .init_count = ARRAY_SIZE(axg_hifi_init_regs), .flags = CLK_MESON_PLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "hifi_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap axg_hifi_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HIFI_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hifi_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_hifi_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor axg_fclk_div2_div = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "fclk_div2_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_fclk_div2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 27, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fclk_div2_div.hw }, .num_parents = 1, .flags = CLK_IS_CRITICAL, }, }; static struct clk_fixed_factor axg_fclk_div3_div = { .mult = 1, .div = 3, .hw.init = &(struct clk_init_data){ .name = "fclk_div3_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_fclk_div3 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 28, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div3", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fclk_div3_div.hw }, .num_parents = 1, /* * FIXME: * This clock, as fdiv2, is used by the SCPI FW and is required * by the platform to operate correctly. * Until the following condition are met, we need this clock to * be marked as critical: * a) The SCPI generic driver claims and enable all the clocks * it needs * b) CCF has a clock hand-off mechanism to make the sure the * clock stays on until the proper driver comes along */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_fixed_factor axg_fclk_div4_div = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "fclk_div4_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_fclk_div4 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 29, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div4", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fclk_div4_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_fclk_div5_div = { .mult = 1, .div = 5, .hw.init = &(struct clk_init_data){ .name = "fclk_div5_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_fclk_div5 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div5", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fclk_div5_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_fclk_div7_div = { .mult = 1, .div = 7, .hw.init = &(struct clk_init_data){ .name = "fclk_div7_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_fclk_div7 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div7", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fclk_div7_div.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_mpll_prediv = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPLL_CNTL5, .shift = 12, .width = 1, }, .hw.init = &(struct clk_init_data){ .name = "mpll_prediv", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &axg_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_mpll0_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL7, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL7, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL7, .shift = 16, .width = 9, }, .misc = { .reg_off = HHI_PLL_TOP_MISC, .shift = 0, .width = 1, }, .lock = &meson_clk_lock, .flags = CLK_MESON_MPLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mpll0_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_mpll0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL7, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpll0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_mpll1_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL8, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL8, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL8, .shift = 16, .width = 9, }, .misc = { .reg_off = HHI_PLL_TOP_MISC, .shift = 1, .width = 1, }, .lock = &meson_clk_lock, .flags = CLK_MESON_MPLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mpll1_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_mpll1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL8, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpll1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_mpll2_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL9, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL9, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL9, .shift = 16, .width = 9, }, .ssen = { .reg_off = HHI_MPLL_CNTL, .shift = 25, .width = 1, }, .misc = { .reg_off = HHI_PLL_TOP_MISC, .shift = 2, .width = 1, }, .lock = &meson_clk_lock, .flags = CLK_MESON_MPLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mpll2_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_mpll2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL9, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpll2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_mpll3_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL3_CNTL0, .shift = 12, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL3_CNTL0, .shift = 11, .width = 1, }, .n2 = { .reg_off = HHI_MPLL3_CNTL0, .shift = 2, .width = 9, }, .misc = { .reg_off = HHI_PLL_TOP_MISC, .shift = 3, .width = 1, }, .lock = &meson_clk_lock, .flags = CLK_MESON_MPLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mpll3_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_mpll3 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL3_CNTL0, .bit_idx = 0, }, .hw.init = &(struct clk_init_data){ .name = "mpll3", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpll3_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct pll_params_table axg_pcie_pll_params_table[] = { { .m = 200, .n = 3, }, { /* sentinel */ }, }; static const struct reg_sequence axg_pcie_init_regs[] = { { .reg = HHI_PCIE_PLL_CNTL1, .def = 0x0084a2aa }, { .reg = HHI_PCIE_PLL_CNTL2, .def = 0xb75020be }, { .reg = HHI_PCIE_PLL_CNTL3, .def = 0x0a47488e }, { .reg = HHI_PCIE_PLL_CNTL4, .def = 0xc000004d }, { .reg = HHI_PCIE_PLL_CNTL5, .def = 0x00078000 }, { .reg = HHI_PCIE_PLL_CNTL6, .def = 0x002323c6 }, { .reg = HHI_PCIE_PLL_CNTL, .def = 0x400106c8 }, }; static struct clk_regmap axg_pcie_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_PCIE_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_PCIE_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_PCIE_PLL_CNTL, .shift = 9, .width = 5, }, .frac = { .reg_off = HHI_PCIE_PLL_CNTL1, .shift = 0, .width = 12, }, .l = { .reg_off = HHI_PCIE_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_PCIE_PLL_CNTL, .shift = 29, .width = 1, }, .table = axg_pcie_pll_params_table, .init_regs = axg_pcie_init_regs, .init_count = ARRAY_SIZE(axg_pcie_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "pcie_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap axg_pcie_pll_od = { .data = &(struct clk_regmap_div_data){ .offset = HHI_PCIE_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "pcie_pll_od", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_pcie_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_pcie_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_PCIE_PLL_CNTL6, .shift = 6, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "pcie_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_pcie_pll_od.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_pcie_mux = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_PCIE_PLL_CNTL6, .mask = 0x1, .shift = 2, /* skip the parent mpll3, reserved for debug */ .table = (u32[]){ 1 }, }, .hw.init = &(struct clk_init_data){ .name = "pcie_mux", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &axg_pcie_pll.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_pcie_ref = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_PCIE_PLL_CNTL6, .mask = 0x1, .shift = 1, /* skip the parent 0, reserved for debug */ .table = (u32[]){ 1 }, }, .hw.init = &(struct clk_init_data){ .name = "pcie_ref", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &axg_pcie_mux.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_pcie_cml_en0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_PCIE_PLL_CNTL6, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "pcie_cml_en0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_pcie_ref.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_pcie_cml_en1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_PCIE_PLL_CNTL6, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "pcie_cml_en1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_pcie_ref.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_clk81[] = { 0, 2, 3, 4, 5, 6, 7 }; static const struct clk_parent_data clk81_parent_data[] = { { .fw_name = "xtal", }, { .hw = &axg_fclk_div7.hw }, { .hw = &axg_mpll1.hw }, { .hw = &axg_mpll2.hw }, { .hw = &axg_fclk_div4.hw }, { .hw = &axg_fclk_div3.hw }, { .hw = &axg_fclk_div5.hw }, }; static struct clk_regmap axg_mpeg_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MPEG_CLK_CNTL, .mask = 0x7, .shift = 12, .table = mux_table_clk81, }, .hw.init = &(struct clk_init_data){ .name = "mpeg_clk_sel", .ops = &clk_regmap_mux_ro_ops, .parent_data = clk81_parent_data, .num_parents = ARRAY_SIZE(clk81_parent_data), }, }; static struct clk_regmap axg_mpeg_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPEG_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mpeg_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpeg_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_clk81 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPEG_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "clk81", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_mpeg_clk_div.hw }, .num_parents = 1, .flags = (CLK_SET_RATE_PARENT | CLK_IS_CRITICAL), }, }; static const struct clk_parent_data axg_sd_emmc_clk0_parent_data[] = { { .fw_name = "xtal", }, { .hw = &axg_fclk_div2.hw }, { .hw = &axg_fclk_div3.hw }, { .hw = &axg_fclk_div5.hw }, { .hw = &axg_fclk_div7.hw }, /* * Following these parent clocks, we should also have had mpll2, mpll3 * and gp0_pll but these clocks are too precious to be used here. All * the necessary rates for MMC and NAND operation can be acheived using * xtal or fclk_div clocks */ }; /* SDcard clock */ static struct clk_regmap axg_sd_emmc_b_clk0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .mask = 0x7, .shift = 25, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_b_clk0_sel", .ops = &clk_regmap_mux_ops, .parent_data = axg_sd_emmc_clk0_parent_data, .num_parents = ARRAY_SIZE(axg_sd_emmc_clk0_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_sd_emmc_b_clk0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .shift = 16, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_b_clk0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_sd_emmc_b_clk0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_sd_emmc_b_clk0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .bit_idx = 23, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_b_clk0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_sd_emmc_b_clk0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* EMMC/NAND clock */ static struct clk_regmap axg_sd_emmc_c_clk0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_NAND_CLK_CNTL, .mask = 0x7, .shift = 9, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_c_clk0_sel", .ops = &clk_regmap_mux_ops, .parent_data = axg_sd_emmc_clk0_parent_data, .num_parents = ARRAY_SIZE(axg_sd_emmc_clk0_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_sd_emmc_c_clk0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_NAND_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_c_clk0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_sd_emmc_c_clk0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_sd_emmc_c_clk0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_NAND_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_c_clk0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_sd_emmc_c_clk0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* VPU Clock */ static const struct clk_hw *axg_vpu_parent_hws[] = { &axg_fclk_div4.hw, &axg_fclk_div3.hw, &axg_fclk_div5.hw, &axg_fclk_div7.hw, }; static struct clk_regmap axg_vpu_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_sel", .ops = &clk_regmap_mux_ops, .parent_hws = axg_vpu_parent_hws, .num_parents = ARRAY_SIZE(axg_vpu_parent_hws), /* We need a specific parent for VPU clock source, let it be set in DT */ .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap axg_vpu_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VPU_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vpu_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_vpu_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VPU_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vpu_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vpu_0_div.hw }, .num_parents = 1, /* * We want to avoid CCF to disable the VPU clock if * display has been set by Bootloader */ .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vpu_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x3, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = axg_vpu_parent_hws, .num_parents = ARRAY_SIZE(axg_vpu_parent_hws), /* We need a specific parent for VPU clock source, let it be set in DT */ .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap axg_vpu_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VPU_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vpu_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_vpu_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VPU_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vpu_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vpu_1_div.hw }, .num_parents = 1, /* * We want to avoid CCF to disable the VPU clock if * display has been set by Bootloader */ .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vpu = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "vpu", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vpu_0.hw, &axg_vpu_1.hw }, .num_parents = 2, .flags = CLK_SET_RATE_NO_REPARENT, }, }; /* VAPB Clock */ static struct clk_regmap axg_vapb_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "vapb_0_sel", .ops = &clk_regmap_mux_ops, .parent_hws = axg_vpu_parent_hws, .num_parents = ARRAY_SIZE(axg_vpu_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap axg_vapb_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VAPBCLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vapb_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vapb_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_vapb_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vapb_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vapb_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vapb_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 0x3, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "vapb_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = axg_vpu_parent_hws, .num_parents = ARRAY_SIZE(axg_vpu_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap axg_vapb_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VAPBCLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vapb_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vapb_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_vapb_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vapb_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vapb_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vapb_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "vapb_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vapb_0.hw, &axg_vapb_1.hw }, .num_parents = 2, .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap axg_vapb = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 30, }, .hw.init = &(struct clk_init_data) { .name = "vapb", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vapb_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; /* Video Clocks */ static const struct clk_hw *axg_vclk_parent_hws[] = { &axg_gp0_pll.hw, &axg_fclk_div4.hw, &axg_fclk_div3.hw, &axg_fclk_div5.hw, &axg_fclk_div2.hw, &axg_fclk_div7.hw, &axg_mpll1.hw, }; static struct clk_regmap axg_vclk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_CNTL, .mask = 0x7, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = axg_vclk_parent_hws, .num_parents = ARRAY_SIZE(axg_vclk_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap axg_vclk2_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_CNTL, .mask = 0x7, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_sel", .ops = &clk_regmap_mux_ops, .parent_hws = axg_vclk_parent_hws, .num_parents = ARRAY_SIZE(axg_vclk_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap axg_vclk_input = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_DIV, .bit_idx = 16, }, .hw.init = &(struct clk_init_data) { .name = "vclk_input", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk2_input = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 16, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_input", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VID_CLK_DIV, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "vclk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk_input.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap axg_vclk2_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VIID_CLK_DIV, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2_input.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap axg_vclk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 19, }, .hw.init = &(struct clk_init_data) { .name = "vclk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 19, }, .hw.init = &(struct clk_init_data) { .name = "vclk2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk_div1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk_div2_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk_div4_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div4_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk_div6_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div6_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk_div12_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div12_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk2_div1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk2_div2_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk2_div4_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div4_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk2_div6_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div6_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap axg_vclk2_div12_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div12_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_fixed_factor axg_vclk_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "vclk_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk_div2_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_vclk_div4 = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "vclk_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk_div4_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_vclk_div6 = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "vclk_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk_div6_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_vclk_div12 = { .mult = 1, .div = 12, .hw.init = &(struct clk_init_data){ .name = "vclk_div12", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk_div12_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_vclk2_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "vclk2_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2_div2_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_vclk2_div4 = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "vclk2_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2_div4_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_vclk2_div6 = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "vclk2_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2_div6_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor axg_vclk2_div12 = { .mult = 1, .div = 12, .hw.init = &(struct clk_init_data){ .name = "vclk2_div12", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vclk2_div12_en.hw }, .num_parents = 1, }, }; static u32 mux_table_cts_sel[] = { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12 }; static const struct clk_hw *axg_cts_parent_hws[] = { &axg_vclk_div1.hw, &axg_vclk_div2.hw, &axg_vclk_div4.hw, &axg_vclk_div6.hw, &axg_vclk_div12.hw, &axg_vclk2_div1.hw, &axg_vclk2_div2.hw, &axg_vclk2_div4.hw, &axg_vclk2_div6.hw, &axg_vclk2_div12.hw, }; static struct clk_regmap axg_cts_encl_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_DIV, .mask = 0xf, .shift = 12, .table = mux_table_cts_sel, }, .hw.init = &(struct clk_init_data){ .name = "cts_encl_sel", .ops = &clk_regmap_mux_ops, .parent_hws = axg_cts_parent_hws, .num_parents = ARRAY_SIZE(axg_cts_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap axg_cts_encl = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "cts_encl", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_cts_encl_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; /* MIPI DSI Host Clock */ static u32 mux_table_axg_vdin_meas[] = { 0, 1, 2, 3, 6, 7 }; static const struct clk_parent_data axg_vdin_meas_parent_data[] = { { .fw_name = "xtal", }, { .hw = &axg_fclk_div4.hw }, { .hw = &axg_fclk_div3.hw }, { .hw = &axg_fclk_div5.hw }, { .hw = &axg_fclk_div2.hw }, { .hw = &axg_fclk_div7.hw }, }; static struct clk_regmap axg_vdin_meas_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDIN_MEAS_CLK_CNTL, .mask = 0x7, .shift = 21, .flags = CLK_MUX_ROUND_CLOSEST, .table = mux_table_axg_vdin_meas, }, .hw.init = &(struct clk_init_data){ .name = "vdin_meas_sel", .ops = &clk_regmap_mux_ops, .parent_data = axg_vdin_meas_parent_data, .num_parents = ARRAY_SIZE(axg_vdin_meas_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_vdin_meas_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDIN_MEAS_CLK_CNTL, .shift = 12, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vdin_meas_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vdin_meas_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_vdin_meas = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDIN_MEAS_CLK_CNTL, .bit_idx = 20, }, .hw.init = &(struct clk_init_data) { .name = "vdin_meas", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_vdin_meas_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_gen_clk[] = { 0, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, }; static const struct clk_parent_data gen_clk_parent_data[] = { { .fw_name = "xtal", }, { .hw = &axg_hifi_pll.hw }, { .hw = &axg_mpll0.hw }, { .hw = &axg_mpll1.hw }, { .hw = &axg_mpll2.hw }, { .hw = &axg_mpll3.hw }, { .hw = &axg_fclk_div4.hw }, { .hw = &axg_fclk_div3.hw }, { .hw = &axg_fclk_div5.hw }, { .hw = &axg_fclk_div7.hw }, { .hw = &axg_gp0_pll.hw }, }; static struct clk_regmap axg_gen_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_GEN_CLK_CNTL, .mask = 0xf, .shift = 12, .table = mux_table_gen_clk, }, .hw.init = &(struct clk_init_data){ .name = "gen_clk_sel", .ops = &clk_regmap_mux_ops, /* * bits 15:12 selects from 14 possible parents: * xtal, [rtc_oscin_i], [sys_cpu_div16], [ddr_dpll_pt], * hifi_pll, mpll0, mpll1, mpll2, mpll3, fdiv4, * fdiv3, fdiv5, [cts_msr_clk], fdiv7, gp0_pll */ .parent_data = gen_clk_parent_data, .num_parents = ARRAY_SIZE(gen_clk_parent_data), }, }; static struct clk_regmap axg_gen_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_GEN_CLK_CNTL, .shift = 0, .width = 11, }, .hw.init = &(struct clk_init_data){ .name = "gen_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_gen_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_gen_clk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_GEN_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "gen_clk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_gen_clk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; #define MESON_GATE(_name, _reg, _bit) \ MESON_PCLK(_name, _reg, _bit, &axg_clk81.hw) /* Everything Else (EE) domain gates */ static MESON_GATE(axg_ddr, HHI_GCLK_MPEG0, 0); static MESON_GATE(axg_audio_locker, HHI_GCLK_MPEG0, 2); static MESON_GATE(axg_mipi_dsi_host, HHI_GCLK_MPEG0, 3); static MESON_GATE(axg_isa, HHI_GCLK_MPEG0, 5); static MESON_GATE(axg_pl301, HHI_GCLK_MPEG0, 6); static MESON_GATE(axg_periphs, HHI_GCLK_MPEG0, 7); static MESON_GATE(axg_spicc_0, HHI_GCLK_MPEG0, 8); static MESON_GATE(axg_i2c, HHI_GCLK_MPEG0, 9); static MESON_GATE(axg_rng0, HHI_GCLK_MPEG0, 12); static MESON_GATE(axg_uart0, HHI_GCLK_MPEG0, 13); static MESON_GATE(axg_mipi_dsi_phy, HHI_GCLK_MPEG0, 14); static MESON_GATE(axg_spicc_1, HHI_GCLK_MPEG0, 15); static MESON_GATE(axg_pcie_a, HHI_GCLK_MPEG0, 16); static MESON_GATE(axg_pcie_b, HHI_GCLK_MPEG0, 17); static MESON_GATE(axg_hiu_reg, HHI_GCLK_MPEG0, 19); static MESON_GATE(axg_assist_misc, HHI_GCLK_MPEG0, 23); static MESON_GATE(axg_emmc_b, HHI_GCLK_MPEG0, 25); static MESON_GATE(axg_emmc_c, HHI_GCLK_MPEG0, 26); static MESON_GATE(axg_dma, HHI_GCLK_MPEG0, 27); static MESON_GATE(axg_spi, HHI_GCLK_MPEG0, 30); static MESON_GATE(axg_audio, HHI_GCLK_MPEG1, 0); static MESON_GATE(axg_eth_core, HHI_GCLK_MPEG1, 3); static MESON_GATE(axg_uart1, HHI_GCLK_MPEG1, 16); static MESON_GATE(axg_g2d, HHI_GCLK_MPEG1, 20); static MESON_GATE(axg_usb0, HHI_GCLK_MPEG1, 21); static MESON_GATE(axg_usb1, HHI_GCLK_MPEG1, 22); static MESON_GATE(axg_reset, HHI_GCLK_MPEG1, 23); static MESON_GATE(axg_usb_general, HHI_GCLK_MPEG1, 26); static MESON_GATE(axg_ahb_arb0, HHI_GCLK_MPEG1, 29); static MESON_GATE(axg_efuse, HHI_GCLK_MPEG1, 30); static MESON_GATE(axg_boot_rom, HHI_GCLK_MPEG1, 31); static MESON_GATE(axg_ahb_data_bus, HHI_GCLK_MPEG2, 1); static MESON_GATE(axg_ahb_ctrl_bus, HHI_GCLK_MPEG2, 2); static MESON_GATE(axg_usb1_to_ddr, HHI_GCLK_MPEG2, 8); static MESON_GATE(axg_usb0_to_ddr, HHI_GCLK_MPEG2, 9); static MESON_GATE(axg_mmc_pclk, HHI_GCLK_MPEG2, 11); static MESON_GATE(axg_vpu_intr, HHI_GCLK_MPEG2, 25); static MESON_GATE(axg_sec_ahb_ahb3_bridge, HHI_GCLK_MPEG2, 26); static MESON_GATE(axg_gic, HHI_GCLK_MPEG2, 30); /* Always On (AO) domain gates */ static MESON_GATE(axg_ao_media_cpu, HHI_GCLK_AO, 0); static MESON_GATE(axg_ao_ahb_sram, HHI_GCLK_AO, 1); static MESON_GATE(axg_ao_ahb_bus, HHI_GCLK_AO, 2); static MESON_GATE(axg_ao_iface, HHI_GCLK_AO, 3); static MESON_GATE(axg_ao_i2c, HHI_GCLK_AO, 4); /* Array of all clocks provided by this provider */ static struct clk_hw *axg_hw_clks[] = { [CLKID_SYS_PLL] = &axg_sys_pll.hw, [CLKID_FIXED_PLL] = &axg_fixed_pll.hw, [CLKID_FCLK_DIV2] = &axg_fclk_div2.hw, [CLKID_FCLK_DIV3] = &axg_fclk_div3.hw, [CLKID_FCLK_DIV4] = &axg_fclk_div4.hw, [CLKID_FCLK_DIV5] = &axg_fclk_div5.hw, [CLKID_FCLK_DIV7] = &axg_fclk_div7.hw, [CLKID_GP0_PLL] = &axg_gp0_pll.hw, [CLKID_MPEG_SEL] = &axg_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &axg_mpeg_clk_div.hw, [CLKID_CLK81] = &axg_clk81.hw, [CLKID_MPLL0] = &axg_mpll0.hw, [CLKID_MPLL1] = &axg_mpll1.hw, [CLKID_MPLL2] = &axg_mpll2.hw, [CLKID_MPLL3] = &axg_mpll3.hw, [CLKID_DDR] = &axg_ddr.hw, [CLKID_AUDIO_LOCKER] = &axg_audio_locker.hw, [CLKID_MIPI_DSI_HOST] = &axg_mipi_dsi_host.hw, [CLKID_ISA] = &axg_isa.hw, [CLKID_PL301] = &axg_pl301.hw, [CLKID_PERIPHS] = &axg_periphs.hw, [CLKID_SPICC0] = &axg_spicc_0.hw, [CLKID_I2C] = &axg_i2c.hw, [CLKID_RNG0] = &axg_rng0.hw, [CLKID_UART0] = &axg_uart0.hw, [CLKID_MIPI_DSI_PHY] = &axg_mipi_dsi_phy.hw, [CLKID_SPICC1] = &axg_spicc_1.hw, [CLKID_PCIE_A] = &axg_pcie_a.hw, [CLKID_PCIE_B] = &axg_pcie_b.hw, [CLKID_HIU_IFACE] = &axg_hiu_reg.hw, [CLKID_ASSIST_MISC] = &axg_assist_misc.hw, [CLKID_SD_EMMC_B] = &axg_emmc_b.hw, [CLKID_SD_EMMC_C] = &axg_emmc_c.hw, [CLKID_DMA] = &axg_dma.hw, [CLKID_SPI] = &axg_spi.hw, [CLKID_AUDIO] = &axg_audio.hw, [CLKID_ETH] = &axg_eth_core.hw, [CLKID_UART1] = &axg_uart1.hw, [CLKID_G2D] = &axg_g2d.hw, [CLKID_USB0] = &axg_usb0.hw, [CLKID_USB1] = &axg_usb1.hw, [CLKID_RESET] = &axg_reset.hw, [CLKID_USB] = &axg_usb_general.hw, [CLKID_AHB_ARB0] = &axg_ahb_arb0.hw, [CLKID_EFUSE] = &axg_efuse.hw, [CLKID_BOOT_ROM] = &axg_boot_rom.hw, [CLKID_AHB_DATA_BUS] = &axg_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &axg_ahb_ctrl_bus.hw, [CLKID_USB1_DDR_BRIDGE] = &axg_usb1_to_ddr.hw, [CLKID_USB0_DDR_BRIDGE] = &axg_usb0_to_ddr.hw, [CLKID_MMC_PCLK] = &axg_mmc_pclk.hw, [CLKID_VPU_INTR] = &axg_vpu_intr.hw, [CLKID_SEC_AHB_AHB3_BRIDGE] = &axg_sec_ahb_ahb3_bridge.hw, [CLKID_GIC] = &axg_gic.hw, [CLKID_AO_MEDIA_CPU] = &axg_ao_media_cpu.hw, [CLKID_AO_AHB_SRAM] = &axg_ao_ahb_sram.hw, [CLKID_AO_AHB_BUS] = &axg_ao_ahb_bus.hw, [CLKID_AO_IFACE] = &axg_ao_iface.hw, [CLKID_AO_I2C] = &axg_ao_i2c.hw, [CLKID_SD_EMMC_B_CLK0_SEL] = &axg_sd_emmc_b_clk0_sel.hw, [CLKID_SD_EMMC_B_CLK0_DIV] = &axg_sd_emmc_b_clk0_div.hw, [CLKID_SD_EMMC_B_CLK0] = &axg_sd_emmc_b_clk0.hw, [CLKID_SD_EMMC_C_CLK0_SEL] = &axg_sd_emmc_c_clk0_sel.hw, [CLKID_SD_EMMC_C_CLK0_DIV] = &axg_sd_emmc_c_clk0_div.hw, [CLKID_SD_EMMC_C_CLK0] = &axg_sd_emmc_c_clk0.hw, [CLKID_MPLL0_DIV] = &axg_mpll0_div.hw, [CLKID_MPLL1_DIV] = &axg_mpll1_div.hw, [CLKID_MPLL2_DIV] = &axg_mpll2_div.hw, [CLKID_MPLL3_DIV] = &axg_mpll3_div.hw, [CLKID_HIFI_PLL] = &axg_hifi_pll.hw, [CLKID_MPLL_PREDIV] = &axg_mpll_prediv.hw, [CLKID_FCLK_DIV2_DIV] = &axg_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &axg_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &axg_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &axg_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &axg_fclk_div7_div.hw, [CLKID_PCIE_PLL] = &axg_pcie_pll.hw, [CLKID_PCIE_MUX] = &axg_pcie_mux.hw, [CLKID_PCIE_REF] = &axg_pcie_ref.hw, [CLKID_PCIE_CML_EN0] = &axg_pcie_cml_en0.hw, [CLKID_PCIE_CML_EN1] = &axg_pcie_cml_en1.hw, [CLKID_GEN_CLK_SEL] = &axg_gen_clk_sel.hw, [CLKID_GEN_CLK_DIV] = &axg_gen_clk_div.hw, [CLKID_GEN_CLK] = &axg_gen_clk.hw, [CLKID_SYS_PLL_DCO] = &axg_sys_pll_dco.hw, [CLKID_FIXED_PLL_DCO] = &axg_fixed_pll_dco.hw, [CLKID_GP0_PLL_DCO] = &axg_gp0_pll_dco.hw, [CLKID_HIFI_PLL_DCO] = &axg_hifi_pll_dco.hw, [CLKID_PCIE_PLL_DCO] = &axg_pcie_pll_dco.hw, [CLKID_PCIE_PLL_OD] = &axg_pcie_pll_od.hw, [CLKID_VPU_0_DIV] = &axg_vpu_0_div.hw, [CLKID_VPU_0_SEL] = &axg_vpu_0_sel.hw, [CLKID_VPU_0] = &axg_vpu_0.hw, [CLKID_VPU_1_DIV] = &axg_vpu_1_div.hw, [CLKID_VPU_1_SEL] = &axg_vpu_1_sel.hw, [CLKID_VPU_1] = &axg_vpu_1.hw, [CLKID_VPU] = &axg_vpu.hw, [CLKID_VAPB_0_DIV] = &axg_vapb_0_div.hw, [CLKID_VAPB_0_SEL] = &axg_vapb_0_sel.hw, [CLKID_VAPB_0] = &axg_vapb_0.hw, [CLKID_VAPB_1_DIV] = &axg_vapb_1_div.hw, [CLKID_VAPB_1_SEL] = &axg_vapb_1_sel.hw, [CLKID_VAPB_1] = &axg_vapb_1.hw, [CLKID_VAPB_SEL] = &axg_vapb_sel.hw, [CLKID_VAPB] = &axg_vapb.hw, [CLKID_VCLK] = &axg_vclk.hw, [CLKID_VCLK2] = &axg_vclk2.hw, [CLKID_VCLK_SEL] = &axg_vclk_sel.hw, [CLKID_VCLK2_SEL] = &axg_vclk2_sel.hw, [CLKID_VCLK_INPUT] = &axg_vclk_input.hw, [CLKID_VCLK2_INPUT] = &axg_vclk2_input.hw, [CLKID_VCLK_DIV] = &axg_vclk_div.hw, [CLKID_VCLK2_DIV] = &axg_vclk2_div.hw, [CLKID_VCLK_DIV2_EN] = &axg_vclk_div2_en.hw, [CLKID_VCLK_DIV4_EN] = &axg_vclk_div4_en.hw, [CLKID_VCLK_DIV6_EN] = &axg_vclk_div6_en.hw, [CLKID_VCLK_DIV12_EN] = &axg_vclk_div12_en.hw, [CLKID_VCLK2_DIV2_EN] = &axg_vclk2_div2_en.hw, [CLKID_VCLK2_DIV4_EN] = &axg_vclk2_div4_en.hw, [CLKID_VCLK2_DIV6_EN] = &axg_vclk2_div6_en.hw, [CLKID_VCLK2_DIV12_EN] = &axg_vclk2_div12_en.hw, [CLKID_VCLK_DIV1] = &axg_vclk_div1.hw, [CLKID_VCLK_DIV2] = &axg_vclk_div2.hw, [CLKID_VCLK_DIV4] = &axg_vclk_div4.hw, [CLKID_VCLK_DIV6] = &axg_vclk_div6.hw, [CLKID_VCLK_DIV12] = &axg_vclk_div12.hw, [CLKID_VCLK2_DIV1] = &axg_vclk2_div1.hw, [CLKID_VCLK2_DIV2] = &axg_vclk2_div2.hw, [CLKID_VCLK2_DIV4] = &axg_vclk2_div4.hw, [CLKID_VCLK2_DIV6] = &axg_vclk2_div6.hw, [CLKID_VCLK2_DIV12] = &axg_vclk2_div12.hw, [CLKID_CTS_ENCL_SEL] = &axg_cts_encl_sel.hw, [CLKID_CTS_ENCL] = &axg_cts_encl.hw, [CLKID_VDIN_MEAS_SEL] = &axg_vdin_meas_sel.hw, [CLKID_VDIN_MEAS_DIV] = &axg_vdin_meas_div.hw, [CLKID_VDIN_MEAS] = &axg_vdin_meas.hw, }; /* Convenience table to populate regmap in .probe */ static struct clk_regmap *const axg_clk_regmaps[] = { &axg_clk81, &axg_ddr, &axg_audio_locker, &axg_mipi_dsi_host, &axg_isa, &axg_pl301, &axg_periphs, &axg_spicc_0, &axg_i2c, &axg_rng0, &axg_uart0, &axg_mipi_dsi_phy, &axg_spicc_1, &axg_pcie_a, &axg_pcie_b, &axg_hiu_reg, &axg_assist_misc, &axg_emmc_b, &axg_emmc_c, &axg_dma, &axg_spi, &axg_audio, &axg_eth_core, &axg_uart1, &axg_g2d, &axg_usb0, &axg_usb1, &axg_reset, &axg_usb_general, &axg_ahb_arb0, &axg_efuse, &axg_boot_rom, &axg_ahb_data_bus, &axg_ahb_ctrl_bus, &axg_usb1_to_ddr, &axg_usb0_to_ddr, &axg_mmc_pclk, &axg_vpu_intr, &axg_sec_ahb_ahb3_bridge, &axg_gic, &axg_ao_media_cpu, &axg_ao_ahb_sram, &axg_ao_ahb_bus, &axg_ao_iface, &axg_ao_i2c, &axg_sd_emmc_b_clk0, &axg_sd_emmc_c_clk0, &axg_mpeg_clk_div, &axg_sd_emmc_b_clk0_div, &axg_sd_emmc_c_clk0_div, &axg_mpeg_clk_sel, &axg_sd_emmc_b_clk0_sel, &axg_sd_emmc_c_clk0_sel, &axg_mpll0, &axg_mpll1, &axg_mpll2, &axg_mpll3, &axg_mpll0_div, &axg_mpll1_div, &axg_mpll2_div, &axg_mpll3_div, &axg_fixed_pll, &axg_sys_pll, &axg_gp0_pll, &axg_hifi_pll, &axg_mpll_prediv, &axg_fclk_div2, &axg_fclk_div3, &axg_fclk_div4, &axg_fclk_div5, &axg_fclk_div7, &axg_pcie_pll_dco, &axg_pcie_pll_od, &axg_pcie_pll, &axg_pcie_mux, &axg_pcie_ref, &axg_pcie_cml_en0, &axg_pcie_cml_en1, &axg_gen_clk_sel, &axg_gen_clk_div, &axg_gen_clk, &axg_fixed_pll_dco, &axg_sys_pll_dco, &axg_gp0_pll_dco, &axg_hifi_pll_dco, &axg_pcie_pll_dco, &axg_pcie_pll_od, &axg_vpu_0_div, &axg_vpu_0_sel, &axg_vpu_0, &axg_vpu_1_div, &axg_vpu_1_sel, &axg_vpu_1, &axg_vpu, &axg_vapb_0_div, &axg_vapb_0_sel, &axg_vapb_0, &axg_vapb_1_div, &axg_vapb_1_sel, &axg_vapb_1, &axg_vapb_sel, &axg_vapb, &axg_vclk, &axg_vclk2, &axg_vclk_sel, &axg_vclk2_sel, &axg_vclk_input, &axg_vclk2_input, &axg_vclk_div, &axg_vclk2_div, &axg_vclk_div2_en, &axg_vclk_div4_en, &axg_vclk_div6_en, &axg_vclk_div12_en, &axg_vclk2_div2_en, &axg_vclk2_div4_en, &axg_vclk2_div6_en, &axg_vclk2_div12_en, &axg_cts_encl_sel, &axg_cts_encl, &axg_vdin_meas_sel, &axg_vdin_meas_div, &axg_vdin_meas, }; static const struct meson_eeclkc_data axg_clkc_data = { .regmap_clks = axg_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(axg_clk_regmaps), .hw_clks = { .hws = axg_hw_clks, .num = ARRAY_SIZE(axg_hw_clks), }, }; static const struct of_device_id clkc_match_table[] = { { .compatible = "amlogic,axg-clkc", .data = &axg_clkc_data }, {} }; MODULE_DEVICE_TABLE(of, clkc_match_table); static struct platform_driver axg_driver = { .probe = meson_eeclkc_probe, .driver = { .name = "axg-clkc", .of_match_table = clkc_match_table, }, }; module_platform_driver(axg_driver); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/axg.c
// SPDX-License-Identifier: GPL-2.0+ /* * Amlogic Meson-AXG Clock Controller Driver * * Copyright (c) 2016 BayLibre, SAS. * Author: Neil Armstrong <[email protected]> * * Copyright (c) 2018 Amlogic, inc. * Author: Qiufang Dai <[email protected]> * Author: Yixun Lan <[email protected]> */ #include <linux/platform_device.h> #include <linux/reset-controller.h> #include <linux/mfd/syscon.h> #include <linux/of.h> #include <linux/module.h> #include <linux/slab.h> #include "meson-aoclk.h" static int meson_aoclk_do_reset(struct reset_controller_dev *rcdev, unsigned long id) { struct meson_aoclk_reset_controller *rstc = container_of(rcdev, struct meson_aoclk_reset_controller, reset); return regmap_write(rstc->regmap, rstc->data->reset_reg, BIT(rstc->data->reset[id])); } static const struct reset_control_ops meson_aoclk_reset_ops = { .reset = meson_aoclk_do_reset, }; int meson_aoclkc_probe(struct platform_device *pdev) { struct meson_aoclk_reset_controller *rstc; struct meson_aoclk_data *data; struct device *dev = &pdev->dev; struct device_node *np; struct regmap *regmap; int ret, clkid; data = (struct meson_aoclk_data *) of_device_get_match_data(dev); if (!data) return -ENODEV; rstc = devm_kzalloc(dev, sizeof(*rstc), GFP_KERNEL); if (!rstc) return -ENOMEM; np = of_get_parent(dev->of_node); regmap = syscon_node_to_regmap(np); of_node_put(np); if (IS_ERR(regmap)) { dev_err(dev, "failed to get regmap\n"); return PTR_ERR(regmap); } /* Reset Controller */ rstc->data = data; rstc->regmap = regmap; rstc->reset.ops = &meson_aoclk_reset_ops; rstc->reset.nr_resets = data->num_reset; rstc->reset.of_node = dev->of_node; ret = devm_reset_controller_register(dev, &rstc->reset); if (ret) { dev_err(dev, "failed to register reset controller\n"); return ret; } /* Populate regmap */ for (clkid = 0; clkid < data->num_clks; clkid++) data->clks[clkid]->map = regmap; /* Register all clks */ for (clkid = 0; clkid < data->hw_clks.num; clkid++) { if (!data->hw_clks.hws[clkid]) continue; ret = devm_clk_hw_register(dev, data->hw_clks.hws[clkid]); if (ret) { dev_err(dev, "Clock registration failed\n"); return ret; } } return devm_of_clk_add_hw_provider(dev, meson_clk_hw_get, (void *)&data->hw_clks); } EXPORT_SYMBOL_GPL(meson_aoclkc_probe); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/meson-aoclk.c
// SPDX-License-Identifier: GPL-2.0+ /* * Amlogic Meson-AXG Clock Controller Driver * * Copyright (c) 2016 Baylibre SAS. * Author: Michael Turquette <[email protected]> * * Copyright (c) 2019 Baylibre SAS. * Author: Neil Armstrong <[email protected]> */ #include <linux/clk-provider.h> #include <linux/platform_device.h> #include <linux/reset-controller.h> #include <linux/mfd/syscon.h> #include <linux/module.h> #include "meson-aoclk.h" #include "clk-regmap.h" #include "clk-dualdiv.h" #include <dt-bindings/clock/g12a-aoclkc.h> #include <dt-bindings/reset/g12a-aoclkc.h> /* * AO Configuration Clock registers offsets * Register offsets from the data sheet must be multiplied by 4. */ #define AO_RTI_STATUS_REG3 0x0C #define AO_RTI_PWR_CNTL_REG0 0x10 #define AO_RTI_GEN_CNTL_REG0 0x40 #define AO_CLK_GATE0 0x4c #define AO_CLK_GATE0_SP 0x50 #define AO_OSCIN_CNTL 0x58 #define AO_CEC_CLK_CNTL_REG0 0x74 #define AO_CEC_CLK_CNTL_REG1 0x78 #define AO_SAR_CLK 0x90 #define AO_RTC_ALT_CLK_CNTL0 0x94 #define AO_RTC_ALT_CLK_CNTL1 0x98 /* * Like every other peripheral clock gate in Amlogic Clock drivers, * we are using CLK_IGNORE_UNUSED here, so we keep the state of the * bootloader. The goal is to remove this flag at some point. * Actually removing it will require some extensive test to be done safely. */ #define AXG_AO_GATE(_name, _reg, _bit) \ static struct clk_regmap g12a_aoclk_##_name = { \ .data = &(struct clk_regmap_gate_data) { \ .offset = (_reg), \ .bit_idx = (_bit), \ }, \ .hw.init = &(struct clk_init_data) { \ .name = "g12a_ao_" #_name, \ .ops = &clk_regmap_gate_ops, \ .parent_data = &(const struct clk_parent_data) { \ .fw_name = "mpeg-clk", \ }, \ .num_parents = 1, \ .flags = CLK_IGNORE_UNUSED, \ }, \ } AXG_AO_GATE(ahb, AO_CLK_GATE0, 0); AXG_AO_GATE(ir_in, AO_CLK_GATE0, 1); AXG_AO_GATE(i2c_m0, AO_CLK_GATE0, 2); AXG_AO_GATE(i2c_s0, AO_CLK_GATE0, 3); AXG_AO_GATE(uart, AO_CLK_GATE0, 4); AXG_AO_GATE(prod_i2c, AO_CLK_GATE0, 5); AXG_AO_GATE(uart2, AO_CLK_GATE0, 6); AXG_AO_GATE(ir_out, AO_CLK_GATE0, 7); AXG_AO_GATE(saradc, AO_CLK_GATE0, 8); AXG_AO_GATE(mailbox, AO_CLK_GATE0_SP, 0); AXG_AO_GATE(m3, AO_CLK_GATE0_SP, 1); AXG_AO_GATE(ahb_sram, AO_CLK_GATE0_SP, 2); AXG_AO_GATE(rti, AO_CLK_GATE0_SP, 3); AXG_AO_GATE(m4_fclk, AO_CLK_GATE0_SP, 4); AXG_AO_GATE(m4_hclk, AO_CLK_GATE0_SP, 5); static struct clk_regmap g12a_aoclk_cts_oscin = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTI_PWR_CNTL_REG0, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "cts_oscin", .ops = &clk_regmap_gate_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static const struct meson_clk_dualdiv_param g12a_32k_div_table[] = { { .dual = 1, .n1 = 733, .m1 = 8, .n2 = 732, .m2 = 11, }, {} }; /* 32k_by_oscin clock */ static struct clk_regmap g12a_aoclk_32k_by_oscin_pre = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTC_ALT_CLK_CNTL0, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_32k_by_oscin_pre", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_cts_oscin.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_aoclk_32k_by_oscin_div = { .data = &(struct meson_clk_dualdiv_data){ .n1 = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 0, .width = 12, }, .n2 = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 12, .width = 12, }, .m1 = { .reg_off = AO_RTC_ALT_CLK_CNTL1, .shift = 0, .width = 12, }, .m2 = { .reg_off = AO_RTC_ALT_CLK_CNTL1, .shift = 12, .width = 12, }, .dual = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 28, .width = 1, }, .table = g12a_32k_div_table, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_32k_by_oscin_div", .ops = &meson_clk_dualdiv_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_32k_by_oscin_pre.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_aoclk_32k_by_oscin_sel = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTC_ALT_CLK_CNTL1, .mask = 0x1, .shift = 24, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_32k_by_oscin_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_32k_by_oscin_div.hw, &g12a_aoclk_32k_by_oscin_pre.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_aoclk_32k_by_oscin = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTC_ALT_CLK_CNTL0, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_32k_by_oscin", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_32k_by_oscin_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* cec clock */ static struct clk_regmap g12a_aoclk_cec_pre = { .data = &(struct clk_regmap_gate_data){ .offset = AO_CEC_CLK_CNTL_REG0, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_cec_pre", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_cts_oscin.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_aoclk_cec_div = { .data = &(struct meson_clk_dualdiv_data){ .n1 = { .reg_off = AO_CEC_CLK_CNTL_REG0, .shift = 0, .width = 12, }, .n2 = { .reg_off = AO_CEC_CLK_CNTL_REG0, .shift = 12, .width = 12, }, .m1 = { .reg_off = AO_CEC_CLK_CNTL_REG1, .shift = 0, .width = 12, }, .m2 = { .reg_off = AO_CEC_CLK_CNTL_REG1, .shift = 12, .width = 12, }, .dual = { .reg_off = AO_CEC_CLK_CNTL_REG0, .shift = 28, .width = 1, }, .table = g12a_32k_div_table, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_cec_div", .ops = &meson_clk_dualdiv_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_cec_pre.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_aoclk_cec_sel = { .data = &(struct clk_regmap_mux_data) { .offset = AO_CEC_CLK_CNTL_REG1, .mask = 0x1, .shift = 24, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_cec_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_cec_div.hw, &g12a_aoclk_cec_pre.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_aoclk_cec = { .data = &(struct clk_regmap_gate_data){ .offset = AO_CEC_CLK_CNTL_REG0, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_cec", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_cec_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_aoclk_cts_rtc_oscin = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTI_PWR_CNTL_REG0, .mask = 0x1, .shift = 10, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_cts_rtc_oscin", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .hw = &g12a_aoclk_32k_by_oscin.hw }, { .fw_name = "ext-32k-0", }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_aoclk_clk81 = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTI_PWR_CNTL_REG0, .mask = 0x1, .shift = 8, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_clk81", .ops = &clk_regmap_mux_ro_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "mpeg-clk", }, { .hw = &g12a_aoclk_cts_rtc_oscin.hw }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_aoclk_saradc_mux = { .data = &(struct clk_regmap_mux_data) { .offset = AO_SAR_CLK, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_saradc_mux", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &g12a_aoclk_clk81.hw }, }, .num_parents = 2, }, }; static struct clk_regmap g12a_aoclk_saradc_div = { .data = &(struct clk_regmap_div_data) { .offset = AO_SAR_CLK, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_saradc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_saradc_mux.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_aoclk_saradc_gate = { .data = &(struct clk_regmap_gate_data) { .offset = AO_SAR_CLK, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "g12a_ao_saradc_gate", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_aoclk_saradc_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const unsigned int g12a_aoclk_reset[] = { [RESET_AO_IR_IN] = 16, [RESET_AO_UART] = 17, [RESET_AO_I2C_M] = 18, [RESET_AO_I2C_S] = 19, [RESET_AO_SAR_ADC] = 20, [RESET_AO_UART2] = 22, [RESET_AO_IR_OUT] = 23, }; static struct clk_regmap *g12a_aoclk_regmap[] = { &g12a_aoclk_ahb, &g12a_aoclk_ir_in, &g12a_aoclk_i2c_m0, &g12a_aoclk_i2c_s0, &g12a_aoclk_uart, &g12a_aoclk_prod_i2c, &g12a_aoclk_uart2, &g12a_aoclk_ir_out, &g12a_aoclk_saradc, &g12a_aoclk_mailbox, &g12a_aoclk_m3, &g12a_aoclk_ahb_sram, &g12a_aoclk_rti, &g12a_aoclk_m4_fclk, &g12a_aoclk_m4_hclk, &g12a_aoclk_cts_oscin, &g12a_aoclk_32k_by_oscin_pre, &g12a_aoclk_32k_by_oscin_div, &g12a_aoclk_32k_by_oscin_sel, &g12a_aoclk_32k_by_oscin, &g12a_aoclk_cec_pre, &g12a_aoclk_cec_div, &g12a_aoclk_cec_sel, &g12a_aoclk_cec, &g12a_aoclk_cts_rtc_oscin, &g12a_aoclk_clk81, &g12a_aoclk_saradc_mux, &g12a_aoclk_saradc_div, &g12a_aoclk_saradc_gate, }; static struct clk_hw *g12a_aoclk_hw_clks[] = { [CLKID_AO_AHB] = &g12a_aoclk_ahb.hw, [CLKID_AO_IR_IN] = &g12a_aoclk_ir_in.hw, [CLKID_AO_I2C_M0] = &g12a_aoclk_i2c_m0.hw, [CLKID_AO_I2C_S0] = &g12a_aoclk_i2c_s0.hw, [CLKID_AO_UART] = &g12a_aoclk_uart.hw, [CLKID_AO_PROD_I2C] = &g12a_aoclk_prod_i2c.hw, [CLKID_AO_UART2] = &g12a_aoclk_uart2.hw, [CLKID_AO_IR_OUT] = &g12a_aoclk_ir_out.hw, [CLKID_AO_SAR_ADC] = &g12a_aoclk_saradc.hw, [CLKID_AO_MAILBOX] = &g12a_aoclk_mailbox.hw, [CLKID_AO_M3] = &g12a_aoclk_m3.hw, [CLKID_AO_AHB_SRAM] = &g12a_aoclk_ahb_sram.hw, [CLKID_AO_RTI] = &g12a_aoclk_rti.hw, [CLKID_AO_M4_FCLK] = &g12a_aoclk_m4_fclk.hw, [CLKID_AO_M4_HCLK] = &g12a_aoclk_m4_hclk.hw, [CLKID_AO_CLK81] = &g12a_aoclk_clk81.hw, [CLKID_AO_SAR_ADC_SEL] = &g12a_aoclk_saradc_mux.hw, [CLKID_AO_SAR_ADC_DIV] = &g12a_aoclk_saradc_div.hw, [CLKID_AO_SAR_ADC_CLK] = &g12a_aoclk_saradc_gate.hw, [CLKID_AO_CTS_OSCIN] = &g12a_aoclk_cts_oscin.hw, [CLKID_AO_32K_PRE] = &g12a_aoclk_32k_by_oscin_pre.hw, [CLKID_AO_32K_DIV] = &g12a_aoclk_32k_by_oscin_div.hw, [CLKID_AO_32K_SEL] = &g12a_aoclk_32k_by_oscin_sel.hw, [CLKID_AO_32K] = &g12a_aoclk_32k_by_oscin.hw, [CLKID_AO_CEC_PRE] = &g12a_aoclk_cec_pre.hw, [CLKID_AO_CEC_DIV] = &g12a_aoclk_cec_div.hw, [CLKID_AO_CEC_SEL] = &g12a_aoclk_cec_sel.hw, [CLKID_AO_CEC] = &g12a_aoclk_cec.hw, [CLKID_AO_CTS_RTC_OSCIN] = &g12a_aoclk_cts_rtc_oscin.hw, }; static const struct meson_aoclk_data g12a_aoclkc_data = { .reset_reg = AO_RTI_GEN_CNTL_REG0, .num_reset = ARRAY_SIZE(g12a_aoclk_reset), .reset = g12a_aoclk_reset, .num_clks = ARRAY_SIZE(g12a_aoclk_regmap), .clks = g12a_aoclk_regmap, .hw_clks = { .hws = g12a_aoclk_hw_clks, .num = ARRAY_SIZE(g12a_aoclk_hw_clks), }, }; static const struct of_device_id g12a_aoclkc_match_table[] = { { .compatible = "amlogic,meson-g12a-aoclkc", .data = &g12a_aoclkc_data, }, { } }; MODULE_DEVICE_TABLE(of, g12a_aoclkc_match_table); static struct platform_driver g12a_aoclkc_driver = { .probe = meson_aoclkc_probe, .driver = { .name = "g12a-aoclkc", .of_match_table = g12a_aoclkc_match_table, }, }; module_platform_driver(g12a_aoclkc_driver); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/g12a-aoclk.c
// SPDX-License-Identifier: GPL-2.0+ /* * Amlogic Meson-G12A Clock Controller Driver * * Copyright (c) 2016 Baylibre SAS. * Author: Michael Turquette <[email protected]> * * Copyright (c) 2018 Amlogic, inc. * Author: Qiufang Dai <[email protected]> * Author: Jian Hu <[email protected]> */ #include <linux/clk-provider.h> #include <linux/init.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/clk.h> #include <linux/module.h> #include "clk-mpll.h" #include "clk-pll.h" #include "clk-regmap.h" #include "clk-cpu-dyndiv.h" #include "vid-pll-div.h" #include "meson-eeclk.h" #include "g12a.h" #include <dt-bindings/clock/g12a-clkc.h> static DEFINE_SPINLOCK(meson_clk_lock); static struct clk_regmap g12a_fixed_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_FIX_PLL_CNTL0, .shift = 28, .width = 1, }, .m = { .reg_off = HHI_FIX_PLL_CNTL0, .shift = 0, .width = 8, }, .n = { .reg_off = HHI_FIX_PLL_CNTL0, .shift = 10, .width = 5, }, .frac = { .reg_off = HHI_FIX_PLL_CNTL1, .shift = 0, .width = 17, }, .l = { .reg_off = HHI_FIX_PLL_CNTL0, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_FIX_PLL_CNTL0, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap g12a_fixed_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_FIX_PLL_CNTL0, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll_dco.hw }, .num_parents = 1, /* * This clock won't ever change at runtime so * CLK_SET_RATE_PARENT is not required */ }, }; static const struct pll_mult_range g12a_sys_pll_mult_range = { .min = 128, .max = 250, }; static struct clk_regmap g12a_sys_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_SYS_PLL_CNTL0, .shift = 28, .width = 1, }, .m = { .reg_off = HHI_SYS_PLL_CNTL0, .shift = 0, .width = 8, }, .n = { .reg_off = HHI_SYS_PLL_CNTL0, .shift = 10, .width = 5, }, .l = { .reg_off = HHI_SYS_PLL_CNTL0, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_SYS_PLL_CNTL0, .shift = 29, .width = 1, }, .range = &g12a_sys_pll_mult_range, }, .hw.init = &(struct clk_init_data){ .name = "sys_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, /* This clock feeds the CPU, avoid disabling it */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_regmap g12a_sys_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_PLL_CNTL0, .shift = 16, .width = 3, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "sys_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sys_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12b_sys1_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_SYS1_PLL_CNTL0, .shift = 28, .width = 1, }, .m = { .reg_off = HHI_SYS1_PLL_CNTL0, .shift = 0, .width = 8, }, .n = { .reg_off = HHI_SYS1_PLL_CNTL0, .shift = 10, .width = 5, }, .l = { .reg_off = HHI_SYS1_PLL_CNTL0, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_SYS1_PLL_CNTL0, .shift = 29, .width = 1, }, .range = &g12a_sys_pll_mult_range, }, .hw.init = &(struct clk_init_data){ .name = "sys1_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, /* This clock feeds the CPU, avoid disabling it */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_regmap g12b_sys1_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS1_PLL_CNTL0, .shift = 16, .width = 3, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "sys1_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_sys1_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_sys_pll_div16_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "sys_pll_div16_en", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sys_pll.hw }, .num_parents = 1, /* * This clock is used to debug the sys_pll range * Linux should not change it at runtime */ }, }; static struct clk_regmap g12b_sys1_pll_div16_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "sys1_pll_div16_en", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_sys1_pll.hw }, .num_parents = 1, /* * This clock is used to debug the sys_pll range * Linux should not change it at runtime */ }, }; static struct clk_fixed_factor g12a_sys_pll_div16 = { .mult = 1, .div = 16, .hw.init = &(struct clk_init_data){ .name = "sys_pll_div16", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sys_pll_div16_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12b_sys1_pll_div16 = { .mult = 1, .div = 16, .hw.init = &(struct clk_init_data){ .name = "sys1_pll_div16", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_sys1_pll_div16_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_fclk_div2_div = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "fclk_div2_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_fclk_div2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_FIX_PLL_CNTL1, .bit_idx = 24, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fclk_div2_div.hw }, .num_parents = 1, /* * Similar to fclk_div3, it seems that this clock is used by * the resident firmware and is required by the platform to * operate correctly. * Until the following condition are met, we need this clock to * be marked as critical: * a) Mark the clock used by a firmware resource, if possible * b) CCF has a clock hand-off mechanism to make the sure the * clock stays on until the proper driver comes along */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_fixed_factor g12a_fclk_div3_div = { .mult = 1, .div = 3, .hw.init = &(struct clk_init_data){ .name = "fclk_div3_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_fclk_div3 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_FIX_PLL_CNTL1, .bit_idx = 20, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div3", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fclk_div3_div.hw }, .num_parents = 1, /* * This clock is used by the resident firmware and is required * by the platform to operate correctly. * Until the following condition are met, we need this clock to * be marked as critical: * a) Mark the clock used by a firmware resource, if possible * b) CCF has a clock hand-off mechanism to make the sure the * clock stays on until the proper driver comes along */ .flags = CLK_IS_CRITICAL, }, }; /* Datasheet names this field as "premux0" */ static struct clk_regmap g12a_cpu_clk_premux0 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x3, .shift = 0, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_dyn0_sel", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div2.hw }, { .hw = &g12a_fclk_div3.hw }, }, .num_parents = 3, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "premux1" */ static struct clk_regmap g12a_cpu_clk_premux1 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x3, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_dyn1_sel", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div2.hw }, { .hw = &g12a_fclk_div3.hw }, }, .num_parents = 3, /* This sub-tree is used a parking clock */ .flags = CLK_SET_RATE_NO_REPARENT }, }; /* Datasheet names this field as "mux0_divn_tcnt" */ static struct clk_regmap g12a_cpu_clk_mux0_div = { .data = &(struct meson_clk_cpu_dyndiv_data){ .div = { .reg_off = HHI_SYS_CPU_CLK_CNTL0, .shift = 4, .width = 6, }, .dyn = { .reg_off = HHI_SYS_CPU_CLK_CNTL0, .shift = 26, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_dyn0_div", .ops = &meson_clk_cpu_dyndiv_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_premux0.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "postmux0" */ static struct clk_regmap g12a_cpu_clk_postmux0 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x1, .shift = 2, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_dyn0", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_premux0.hw, &g12a_cpu_clk_mux0_div.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "Mux1_divn_tcnt" */ static struct clk_regmap g12a_cpu_clk_mux1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .shift = 20, .width = 6, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_dyn1_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_premux1.hw }, .num_parents = 1, }, }; /* Datasheet names this field as "postmux1" */ static struct clk_regmap g12a_cpu_clk_postmux1 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x1, .shift = 18, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_dyn1", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_premux1.hw, &g12a_cpu_clk_mux1_div.hw, }, .num_parents = 2, /* This sub-tree is used a parking clock */ .flags = CLK_SET_RATE_NO_REPARENT, }, }; /* Datasheet names this field as "Final_dyn_mux_sel" */ static struct clk_regmap g12a_cpu_clk_dyn = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x1, .shift = 10, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_dyn", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_postmux0.hw, &g12a_cpu_clk_postmux1.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "Final_mux_sel" */ static struct clk_regmap g12a_cpu_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x1, .shift = 11, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_dyn.hw, &g12a_sys_pll.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "Final_mux_sel" */ static struct clk_regmap g12b_cpu_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL0, .mask = 0x1, .shift = 11, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_dyn.hw, &g12b_sys1_pll.hw }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "premux0" */ static struct clk_regmap g12b_cpub_clk_premux0 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL, .mask = 0x3, .shift = 0, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_dyn0_sel", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div2.hw }, { .hw = &g12a_fclk_div3.hw }, }, .num_parents = 3, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "mux0_divn_tcnt" */ static struct clk_regmap g12b_cpub_clk_mux0_div = { .data = &(struct meson_clk_cpu_dyndiv_data){ .div = { .reg_off = HHI_SYS_CPUB_CLK_CNTL, .shift = 4, .width = 6, }, .dyn = { .reg_off = HHI_SYS_CPUB_CLK_CNTL, .shift = 26, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_dyn0_div", .ops = &meson_clk_cpu_dyndiv_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_premux0.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "postmux0" */ static struct clk_regmap g12b_cpub_clk_postmux0 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL, .mask = 0x1, .shift = 2, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_dyn0", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_premux0.hw, &g12b_cpub_clk_mux0_div.hw }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "premux1" */ static struct clk_regmap g12b_cpub_clk_premux1 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL, .mask = 0x3, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_dyn1_sel", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div2.hw }, { .hw = &g12a_fclk_div3.hw }, }, .num_parents = 3, /* This sub-tree is used a parking clock */ .flags = CLK_SET_RATE_NO_REPARENT, }, }; /* Datasheet names this field as "Mux1_divn_tcnt" */ static struct clk_regmap g12b_cpub_clk_mux1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPUB_CLK_CNTL, .shift = 20, .width = 6, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_dyn1_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_premux1.hw }, .num_parents = 1, }, }; /* Datasheet names this field as "postmux1" */ static struct clk_regmap g12b_cpub_clk_postmux1 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL, .mask = 0x1, .shift = 18, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_dyn1", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_premux1.hw, &g12b_cpub_clk_mux1_div.hw }, .num_parents = 2, /* This sub-tree is used a parking clock */ .flags = CLK_SET_RATE_NO_REPARENT, }, }; /* Datasheet names this field as "Final_dyn_mux_sel" */ static struct clk_regmap g12b_cpub_clk_dyn = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL, .mask = 0x1, .shift = 10, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_dyn", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_postmux0.hw, &g12b_cpub_clk_postmux1.hw }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; /* Datasheet names this field as "Final_mux_sel" */ static struct clk_regmap g12b_cpub_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL, .mask = 0x1, .shift = 11, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_dyn.hw, &g12a_sys_pll.hw }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sm1_gp1_pll; /* Datasheet names this field as "premux0" */ static struct clk_regmap sm1_dsu_clk_premux0 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL5, .mask = 0x3, .shift = 0, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk_dyn0_sel", .ops = &clk_regmap_mux_ro_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div2.hw }, { .hw = &g12a_fclk_div3.hw }, { .hw = &sm1_gp1_pll.hw }, }, .num_parents = 4, }, }; /* Datasheet names this field as "premux1" */ static struct clk_regmap sm1_dsu_clk_premux1 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL5, .mask = 0x3, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk_dyn1_sel", .ops = &clk_regmap_mux_ro_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div2.hw }, { .hw = &g12a_fclk_div3.hw }, { .hw = &sm1_gp1_pll.hw }, }, .num_parents = 4, }, }; /* Datasheet names this field as "Mux0_divn_tcnt" */ static struct clk_regmap sm1_dsu_clk_mux0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPU_CLK_CNTL5, .shift = 4, .width = 6, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk_dyn0_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_dsu_clk_premux0.hw }, .num_parents = 1, }, }; /* Datasheet names this field as "postmux0" */ static struct clk_regmap sm1_dsu_clk_postmux0 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL5, .mask = 0x1, .shift = 2, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk_dyn0", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_dsu_clk_premux0.hw, &sm1_dsu_clk_mux0_div.hw, }, .num_parents = 2, }, }; /* Datasheet names this field as "Mux1_divn_tcnt" */ static struct clk_regmap sm1_dsu_clk_mux1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPU_CLK_CNTL5, .shift = 20, .width = 6, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk_dyn1_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_dsu_clk_premux1.hw }, .num_parents = 1, }, }; /* Datasheet names this field as "postmux1" */ static struct clk_regmap sm1_dsu_clk_postmux1 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL5, .mask = 0x1, .shift = 18, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk_dyn1", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_dsu_clk_premux1.hw, &sm1_dsu_clk_mux1_div.hw, }, .num_parents = 2, }, }; /* Datasheet names this field as "Final_dyn_mux_sel" */ static struct clk_regmap sm1_dsu_clk_dyn = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL5, .mask = 0x1, .shift = 10, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk_dyn", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_dsu_clk_postmux0.hw, &sm1_dsu_clk_postmux1.hw, }, .num_parents = 2, }, }; /* Datasheet names this field as "Final_mux_sel" */ static struct clk_regmap sm1_dsu_final_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL5, .mask = 0x1, .shift = 11, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk_final", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_dsu_clk_dyn.hw, &g12a_sys_pll.hw, }, .num_parents = 2, }, }; /* Datasheet names this field as "Cpu_clk_sync_mux_sel" bit 0 */ static struct clk_regmap sm1_cpu1_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL6, .mask = 0x1, .shift = 24, }, .hw.init = &(struct clk_init_data){ .name = "cpu1_clk", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk.hw, /* This CPU also have a dedicated clock tree */ }, .num_parents = 1, }, }; /* Datasheet names this field as "Cpu_clk_sync_mux_sel" bit 1 */ static struct clk_regmap sm1_cpu2_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL6, .mask = 0x1, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "cpu2_clk", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk.hw, /* This CPU also have a dedicated clock tree */ }, .num_parents = 1, }, }; /* Datasheet names this field as "Cpu_clk_sync_mux_sel" bit 2 */ static struct clk_regmap sm1_cpu3_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL6, .mask = 0x1, .shift = 26, }, .hw.init = &(struct clk_init_data){ .name = "cpu3_clk", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk.hw, /* This CPU also have a dedicated clock tree */ }, .num_parents = 1, }, }; /* Datasheet names this field as "Cpu_clk_sync_mux_sel" bit 4 */ static struct clk_regmap sm1_dsu_clk = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPU_CLK_CNTL6, .mask = 0x1, .shift = 27, }, .hw.init = &(struct clk_init_data){ .name = "dsu_clk", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk.hw, &sm1_dsu_final_clk.hw, }, .num_parents = 2, }, }; static int g12a_cpu_clk_mux_notifier_cb(struct notifier_block *nb, unsigned long event, void *data) { if (event == POST_RATE_CHANGE || event == PRE_RATE_CHANGE) { /* Wait for clock propagation before/after changing the mux */ udelay(100); return NOTIFY_OK; } return NOTIFY_DONE; } static struct notifier_block g12a_cpu_clk_mux_nb = { .notifier_call = g12a_cpu_clk_mux_notifier_cb, }; struct g12a_cpu_clk_postmux_nb_data { struct notifier_block nb; struct clk_hw *xtal; struct clk_hw *cpu_clk_dyn; struct clk_hw *cpu_clk_postmux0; struct clk_hw *cpu_clk_postmux1; struct clk_hw *cpu_clk_premux1; }; static int g12a_cpu_clk_postmux_notifier_cb(struct notifier_block *nb, unsigned long event, void *data) { struct g12a_cpu_clk_postmux_nb_data *nb_data = container_of(nb, struct g12a_cpu_clk_postmux_nb_data, nb); switch (event) { case PRE_RATE_CHANGE: /* * This notifier means cpu_clk_postmux0 clock will be changed * to feed cpu_clk, this is the current path : * cpu_clk * \- cpu_clk_dyn * \- cpu_clk_postmux0 * \- cpu_clk_muxX_div * \- cpu_clk_premux0 * \- fclk_div3 or fclk_div2 * OR * \- cpu_clk_premux0 * \- fclk_div3 or fclk_div2 */ /* Setup cpu_clk_premux1 to xtal */ clk_hw_set_parent(nb_data->cpu_clk_premux1, nb_data->xtal); /* Setup cpu_clk_postmux1 to bypass divider */ clk_hw_set_parent(nb_data->cpu_clk_postmux1, nb_data->cpu_clk_premux1); /* Switch to parking clk on cpu_clk_postmux1 */ clk_hw_set_parent(nb_data->cpu_clk_dyn, nb_data->cpu_clk_postmux1); /* * Now, cpu_clk is 24MHz in the current path : * cpu_clk * \- cpu_clk_dyn * \- cpu_clk_postmux1 * \- cpu_clk_premux1 * \- xtal */ udelay(100); return NOTIFY_OK; case POST_RATE_CHANGE: /* * The cpu_clk_postmux0 has ben updated, now switch back * cpu_clk_dyn to cpu_clk_postmux0 and take the changes * in account. */ /* Configure cpu_clk_dyn back to cpu_clk_postmux0 */ clk_hw_set_parent(nb_data->cpu_clk_dyn, nb_data->cpu_clk_postmux0); /* * new path : * cpu_clk * \- cpu_clk_dyn * \- cpu_clk_postmux0 * \- cpu_clk_muxX_div * \- cpu_clk_premux0 * \- fclk_div3 or fclk_div2 * OR * \- cpu_clk_premux0 * \- fclk_div3 or fclk_div2 */ udelay(100); return NOTIFY_OK; default: return NOTIFY_DONE; } } static struct g12a_cpu_clk_postmux_nb_data g12a_cpu_clk_postmux0_nb_data = { .cpu_clk_dyn = &g12a_cpu_clk_dyn.hw, .cpu_clk_postmux0 = &g12a_cpu_clk_postmux0.hw, .cpu_clk_postmux1 = &g12a_cpu_clk_postmux1.hw, .cpu_clk_premux1 = &g12a_cpu_clk_premux1.hw, .nb.notifier_call = g12a_cpu_clk_postmux_notifier_cb, }; static struct g12a_cpu_clk_postmux_nb_data g12b_cpub_clk_postmux0_nb_data = { .cpu_clk_dyn = &g12b_cpub_clk_dyn.hw, .cpu_clk_postmux0 = &g12b_cpub_clk_postmux0.hw, .cpu_clk_postmux1 = &g12b_cpub_clk_postmux1.hw, .cpu_clk_premux1 = &g12b_cpub_clk_premux1.hw, .nb.notifier_call = g12a_cpu_clk_postmux_notifier_cb, }; struct g12a_sys_pll_nb_data { struct notifier_block nb; struct clk_hw *sys_pll; struct clk_hw *cpu_clk; struct clk_hw *cpu_clk_dyn; }; static int g12a_sys_pll_notifier_cb(struct notifier_block *nb, unsigned long event, void *data) { struct g12a_sys_pll_nb_data *nb_data = container_of(nb, struct g12a_sys_pll_nb_data, nb); switch (event) { case PRE_RATE_CHANGE: /* * This notifier means sys_pll clock will be changed * to feed cpu_clk, this the current path : * cpu_clk * \- sys_pll * \- sys_pll_dco */ /* Configure cpu_clk to use cpu_clk_dyn */ clk_hw_set_parent(nb_data->cpu_clk, nb_data->cpu_clk_dyn); /* * Now, cpu_clk uses the dyn path * cpu_clk * \- cpu_clk_dyn * \- cpu_clk_dynX * \- cpu_clk_dynX_sel * \- cpu_clk_dynX_div * \- xtal/fclk_div2/fclk_div3 * \- xtal/fclk_div2/fclk_div3 */ udelay(100); return NOTIFY_OK; case POST_RATE_CHANGE: /* * The sys_pll has ben updated, now switch back cpu_clk to * sys_pll */ /* Configure cpu_clk to use sys_pll */ clk_hw_set_parent(nb_data->cpu_clk, nb_data->sys_pll); udelay(100); /* new path : * cpu_clk * \- sys_pll * \- sys_pll_dco */ return NOTIFY_OK; default: return NOTIFY_DONE; } } static struct g12a_sys_pll_nb_data g12a_sys_pll_nb_data = { .sys_pll = &g12a_sys_pll.hw, .cpu_clk = &g12a_cpu_clk.hw, .cpu_clk_dyn = &g12a_cpu_clk_dyn.hw, .nb.notifier_call = g12a_sys_pll_notifier_cb, }; /* G12B first CPU cluster uses sys1_pll */ static struct g12a_sys_pll_nb_data g12b_cpu_clk_sys1_pll_nb_data = { .sys_pll = &g12b_sys1_pll.hw, .cpu_clk = &g12b_cpu_clk.hw, .cpu_clk_dyn = &g12a_cpu_clk_dyn.hw, .nb.notifier_call = g12a_sys_pll_notifier_cb, }; /* G12B second CPU cluster uses sys_pll */ static struct g12a_sys_pll_nb_data g12b_cpub_clk_sys_pll_nb_data = { .sys_pll = &g12a_sys_pll.hw, .cpu_clk = &g12b_cpub_clk.hw, .cpu_clk_dyn = &g12b_cpub_clk_dyn.hw, .nb.notifier_call = g12a_sys_pll_notifier_cb, }; static struct clk_regmap g12a_cpu_clk_div16_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "cpu_clk_div16_en", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk.hw }, .num_parents = 1, /* * This clock is used to debug the cpu_clk range * Linux should not change it at runtime */ }, }; static struct clk_regmap g12b_cpub_clk_div16_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "cpub_clk_div16_en", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk.hw }, .num_parents = 1, /* * This clock is used to debug the cpu_clk range * Linux should not change it at runtime */ }, }; static struct clk_fixed_factor g12a_cpu_clk_div16 = { .mult = 1, .div = 16, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_div16", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_div16_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12b_cpub_clk_div16 = { .mult = 1, .div = 16, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_div16", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_div16_en.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_cpu_clk_apb_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .shift = 3, .width = 3, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_apb_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_cpu_clk_apb = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "cpu_clk_apb", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_apb_div.hw }, .num_parents = 1, /* * This clock is set by the ROM monitor code, * Linux should not change it at runtime */ }, }; static struct clk_regmap g12a_cpu_clk_atb_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .shift = 6, .width = 3, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_atb_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_cpu_clk_atb = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 17, }, .hw.init = &(struct clk_init_data) { .name = "cpu_clk_atb", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_atb_div.hw }, .num_parents = 1, /* * This clock is set by the ROM monitor code, * Linux should not change it at runtime */ }, }; static struct clk_regmap g12a_cpu_clk_axi_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .shift = 9, .width = 3, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_axi_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_cpu_clk_axi = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 18, }, .hw.init = &(struct clk_init_data) { .name = "cpu_clk_axi", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_axi_div.hw }, .num_parents = 1, /* * This clock is set by the ROM monitor code, * Linux should not change it at runtime */ }, }; static struct clk_regmap g12a_cpu_clk_trace_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .shift = 20, .width = 3, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "cpu_clk_trace_div", .ops = &clk_regmap_divider_ro_ops, .parent_data = &(const struct clk_parent_data) { /* * Note: * G12A and G12B have different cpu_clks (with * different struct clk_hw). We fallback to the global * naming string mechanism so cpu_clk_trace_div picks * up the appropriate one. */ .name = "cpu_clk", .index = -1, }, .num_parents = 1, }, }; static struct clk_regmap g12a_cpu_clk_trace = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPU_CLK_CNTL1, .bit_idx = 23, }, .hw.init = &(struct clk_init_data) { .name = "cpu_clk_trace", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cpu_clk_trace_div.hw }, .num_parents = 1, /* * This clock is set by the ROM monitor code, * Linux should not change it at runtime */ }, }; static struct clk_fixed_factor g12b_cpub_clk_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12b_cpub_clk_div3 = { .mult = 1, .div = 3, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_div3", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12b_cpub_clk_div4 = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12b_cpub_clk_div5 = { .mult = 1, .div = 5, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_div5", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12b_cpub_clk_div6 = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12b_cpub_clk_div7 = { .mult = 1, .div = 7, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_div7", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12b_cpub_clk_div8 = { .mult = 1, .div = 8, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_div8", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk.hw }, .num_parents = 1, }, }; static u32 mux_table_cpub[] = { 1, 2, 3, 4, 5, 6, 7 }; static struct clk_regmap g12b_cpub_clk_apb_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .mask = 7, .shift = 3, .table = mux_table_cpub, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_apb_sel", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_div2.hw, &g12b_cpub_clk_div3.hw, &g12b_cpub_clk_div4.hw, &g12b_cpub_clk_div5.hw, &g12b_cpub_clk_div6.hw, &g12b_cpub_clk_div7.hw, &g12b_cpub_clk_div8.hw }, .num_parents = 7, }, }; static struct clk_regmap g12b_cpub_clk_apb = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .bit_idx = 16, .flags = CLK_GATE_SET_TO_DISABLE, }, .hw.init = &(struct clk_init_data) { .name = "cpub_clk_apb", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_apb_sel.hw }, .num_parents = 1, /* * This clock is set by the ROM monitor code, * Linux should not change it at runtime */ }, }; static struct clk_regmap g12b_cpub_clk_atb_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .mask = 7, .shift = 6, .table = mux_table_cpub, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_atb_sel", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_div2.hw, &g12b_cpub_clk_div3.hw, &g12b_cpub_clk_div4.hw, &g12b_cpub_clk_div5.hw, &g12b_cpub_clk_div6.hw, &g12b_cpub_clk_div7.hw, &g12b_cpub_clk_div8.hw }, .num_parents = 7, }, }; static struct clk_regmap g12b_cpub_clk_atb = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .bit_idx = 17, .flags = CLK_GATE_SET_TO_DISABLE, }, .hw.init = &(struct clk_init_data) { .name = "cpub_clk_atb", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_atb_sel.hw }, .num_parents = 1, /* * This clock is set by the ROM monitor code, * Linux should not change it at runtime */ }, }; static struct clk_regmap g12b_cpub_clk_axi_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .mask = 7, .shift = 9, .table = mux_table_cpub, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_axi_sel", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_div2.hw, &g12b_cpub_clk_div3.hw, &g12b_cpub_clk_div4.hw, &g12b_cpub_clk_div5.hw, &g12b_cpub_clk_div6.hw, &g12b_cpub_clk_div7.hw, &g12b_cpub_clk_div8.hw }, .num_parents = 7, }, }; static struct clk_regmap g12b_cpub_clk_axi = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .bit_idx = 18, .flags = CLK_GATE_SET_TO_DISABLE, }, .hw.init = &(struct clk_init_data) { .name = "cpub_clk_axi", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_axi_sel.hw }, .num_parents = 1, /* * This clock is set by the ROM monitor code, * Linux should not change it at runtime */ }, }; static struct clk_regmap g12b_cpub_clk_trace_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .mask = 7, .shift = 20, .table = mux_table_cpub, }, .hw.init = &(struct clk_init_data){ .name = "cpub_clk_trace_sel", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_div2.hw, &g12b_cpub_clk_div3.hw, &g12b_cpub_clk_div4.hw, &g12b_cpub_clk_div5.hw, &g12b_cpub_clk_div6.hw, &g12b_cpub_clk_div7.hw, &g12b_cpub_clk_div8.hw }, .num_parents = 7, }, }; static struct clk_regmap g12b_cpub_clk_trace = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SYS_CPUB_CLK_CNTL1, .bit_idx = 23, .flags = CLK_GATE_SET_TO_DISABLE, }, .hw.init = &(struct clk_init_data) { .name = "cpub_clk_trace", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12b_cpub_clk_trace_sel.hw }, .num_parents = 1, /* * This clock is set by the ROM monitor code, * Linux should not change it at runtime */ }, }; static const struct pll_mult_range g12a_gp0_pll_mult_range = { .min = 125, .max = 255, }; /* * Internal gp0 pll emulation configuration parameters */ static const struct reg_sequence g12a_gp0_init_regs[] = { { .reg = HHI_GP0_PLL_CNTL1, .def = 0x00000000 }, { .reg = HHI_GP0_PLL_CNTL2, .def = 0x00000000 }, { .reg = HHI_GP0_PLL_CNTL3, .def = 0x48681c00 }, { .reg = HHI_GP0_PLL_CNTL4, .def = 0x33771290 }, { .reg = HHI_GP0_PLL_CNTL5, .def = 0x39272000 }, { .reg = HHI_GP0_PLL_CNTL6, .def = 0x56540000 }, }; static struct clk_regmap g12a_gp0_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_GP0_PLL_CNTL0, .shift = 28, .width = 1, }, .m = { .reg_off = HHI_GP0_PLL_CNTL0, .shift = 0, .width = 8, }, .n = { .reg_off = HHI_GP0_PLL_CNTL0, .shift = 10, .width = 5, }, .frac = { .reg_off = HHI_GP0_PLL_CNTL1, .shift = 0, .width = 17, }, .l = { .reg_off = HHI_GP0_PLL_CNTL0, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_GP0_PLL_CNTL0, .shift = 29, .width = 1, }, .range = &g12a_gp0_pll_mult_range, .init_regs = g12a_gp0_init_regs, .init_count = ARRAY_SIZE(g12a_gp0_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "gp0_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap g12a_gp0_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_GP0_PLL_CNTL0, .shift = 16, .width = 3, .flags = (CLK_DIVIDER_POWER_OF_TWO | CLK_DIVIDER_ROUND_CLOSEST), }, .hw.init = &(struct clk_init_data){ .name = "gp0_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_gp0_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sm1_gp1_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_GP1_PLL_CNTL0, .shift = 28, .width = 1, }, .m = { .reg_off = HHI_GP1_PLL_CNTL0, .shift = 0, .width = 8, }, .n = { .reg_off = HHI_GP1_PLL_CNTL0, .shift = 10, .width = 5, }, .frac = { .reg_off = HHI_GP1_PLL_CNTL1, .shift = 0, .width = 17, }, .l = { .reg_off = HHI_GP1_PLL_CNTL0, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_GP1_PLL_CNTL0, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "gp1_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, /* This clock feeds the DSU, avoid disabling it */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_regmap sm1_gp1_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_GP1_PLL_CNTL0, .shift = 16, .width = 3, .flags = (CLK_DIVIDER_POWER_OF_TWO | CLK_DIVIDER_ROUND_CLOSEST), }, .hw.init = &(struct clk_init_data){ .name = "gp1_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_gp1_pll_dco.hw }, .num_parents = 1, }, }; /* * Internal hifi pll emulation configuration parameters */ static const struct reg_sequence g12a_hifi_init_regs[] = { { .reg = HHI_HIFI_PLL_CNTL1, .def = 0x00000000 }, { .reg = HHI_HIFI_PLL_CNTL2, .def = 0x00000000 }, { .reg = HHI_HIFI_PLL_CNTL3, .def = 0x6a285c00 }, { .reg = HHI_HIFI_PLL_CNTL4, .def = 0x65771290 }, { .reg = HHI_HIFI_PLL_CNTL5, .def = 0x39272000 }, { .reg = HHI_HIFI_PLL_CNTL6, .def = 0x56540000 }, }; static struct clk_regmap g12a_hifi_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_HIFI_PLL_CNTL0, .shift = 28, .width = 1, }, .m = { .reg_off = HHI_HIFI_PLL_CNTL0, .shift = 0, .width = 8, }, .n = { .reg_off = HHI_HIFI_PLL_CNTL0, .shift = 10, .width = 5, }, .frac = { .reg_off = HHI_HIFI_PLL_CNTL1, .shift = 0, .width = 17, }, .l = { .reg_off = HHI_HIFI_PLL_CNTL0, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_HIFI_PLL_CNTL0, .shift = 29, .width = 1, }, .range = &g12a_gp0_pll_mult_range, .init_regs = g12a_hifi_init_regs, .init_count = ARRAY_SIZE(g12a_hifi_init_regs), .flags = CLK_MESON_PLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "hifi_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap g12a_hifi_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HIFI_PLL_CNTL0, .shift = 16, .width = 2, .flags = (CLK_DIVIDER_POWER_OF_TWO | CLK_DIVIDER_ROUND_CLOSEST), }, .hw.init = &(struct clk_init_data){ .name = "hifi_pll", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_hifi_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* * The Meson G12A PCIE PLL is fined tuned to deliver a very precise * 100MHz reference clock for the PCIe Analog PHY, and thus requires * a strict register sequence to enable the PLL. */ static const struct reg_sequence g12a_pcie_pll_init_regs[] = { { .reg = HHI_PCIE_PLL_CNTL0, .def = 0x20090496 }, { .reg = HHI_PCIE_PLL_CNTL0, .def = 0x30090496 }, { .reg = HHI_PCIE_PLL_CNTL1, .def = 0x00000000 }, { .reg = HHI_PCIE_PLL_CNTL2, .def = 0x00001100 }, { .reg = HHI_PCIE_PLL_CNTL3, .def = 0x10058e00 }, { .reg = HHI_PCIE_PLL_CNTL4, .def = 0x000100c0 }, { .reg = HHI_PCIE_PLL_CNTL5, .def = 0x68000048 }, { .reg = HHI_PCIE_PLL_CNTL5, .def = 0x68000068, .delay_us = 20 }, { .reg = HHI_PCIE_PLL_CNTL4, .def = 0x008100c0, .delay_us = 10 }, { .reg = HHI_PCIE_PLL_CNTL0, .def = 0x34090496 }, { .reg = HHI_PCIE_PLL_CNTL0, .def = 0x14090496, .delay_us = 10 }, { .reg = HHI_PCIE_PLL_CNTL2, .def = 0x00001000 }, }; /* Keep a single entry table for recalc/round_rate() ops */ static const struct pll_params_table g12a_pcie_pll_table[] = { PLL_PARAMS(150, 1), {0, 0}, }; static struct clk_regmap g12a_pcie_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_PCIE_PLL_CNTL0, .shift = 28, .width = 1, }, .m = { .reg_off = HHI_PCIE_PLL_CNTL0, .shift = 0, .width = 8, }, .n = { .reg_off = HHI_PCIE_PLL_CNTL0, .shift = 10, .width = 5, }, .frac = { .reg_off = HHI_PCIE_PLL_CNTL1, .shift = 0, .width = 12, }, .l = { .reg_off = HHI_PCIE_PLL_CNTL0, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_PCIE_PLL_CNTL0, .shift = 29, .width = 1, }, .table = g12a_pcie_pll_table, .init_regs = g12a_pcie_pll_init_regs, .init_count = ARRAY_SIZE(g12a_pcie_pll_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "pcie_pll_dco", .ops = &meson_clk_pcie_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_pcie_pll_dco_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "pcie_pll_dco_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_pcie_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_pcie_pll_od = { .data = &(struct clk_regmap_div_data){ .offset = HHI_PCIE_PLL_CNTL0, .shift = 16, .width = 5, .flags = CLK_DIVIDER_ROUND_CLOSEST | CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, }, .hw.init = &(struct clk_init_data){ .name = "pcie_pll_od", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_pcie_pll_dco_div2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor g12a_pcie_pll = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "pcie_pll_pll", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_pcie_pll_od.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_hdmi_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_HDMI_PLL_CNTL0, .shift = 28, .width = 1, }, .m = { .reg_off = HHI_HDMI_PLL_CNTL0, .shift = 0, .width = 8, }, .n = { .reg_off = HHI_HDMI_PLL_CNTL0, .shift = 10, .width = 5, }, .frac = { .reg_off = HHI_HDMI_PLL_CNTL1, .shift = 0, .width = 16, }, .l = { .reg_off = HHI_HDMI_PLL_CNTL0, .shift = 30, .width = 1, }, .rst = { .reg_off = HHI_HDMI_PLL_CNTL0, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, /* * Display directly handle hdmi pll registers ATM, we need * NOCACHE to keep our view of the clock as accurate as possible */ .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_hdmi_pll_od = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL0, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_od", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_hdmi_pll_dco.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_hdmi_pll_od2 = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL0, .shift = 18, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_od2", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_hdmi_pll_od.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_hdmi_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL0, .shift = 20, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_hdmi_pll_od2.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor g12a_fclk_div4_div = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "fclk_div4_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_fclk_div4 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_FIX_PLL_CNTL1, .bit_idx = 21, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div4", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fclk_div4_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_fclk_div5_div = { .mult = 1, .div = 5, .hw.init = &(struct clk_init_data){ .name = "fclk_div5_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_fclk_div5 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_FIX_PLL_CNTL1, .bit_idx = 22, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div5", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fclk_div5_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_fclk_div7_div = { .mult = 1, .div = 7, .hw.init = &(struct clk_init_data){ .name = "fclk_div7_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_fclk_div7 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_FIX_PLL_CNTL1, .bit_idx = 23, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div7", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fclk_div7_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_fclk_div2p5_div = { .mult = 1, .div = 5, .hw.init = &(struct clk_init_data){ .name = "fclk_div2p5_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll_dco.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_fclk_div2p5 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_FIX_PLL_CNTL1, .bit_idx = 25, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div2p5", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fclk_div2p5_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_mpll_50m_div = { .mult = 1, .div = 80, .hw.init = &(struct clk_init_data){ .name = "mpll_50m_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll_dco.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_mpll_50m = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_FIX_PLL_CNTL3, .mask = 0x1, .shift = 5, }, .hw.init = &(struct clk_init_data){ .name = "mpll_50m", .ops = &clk_regmap_mux_ro_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &g12a_mpll_50m_div.hw }, }, .num_parents = 2, }, }; static struct clk_fixed_factor g12a_mpll_prediv = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "mpll_prediv", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_fixed_pll_dco.hw }, .num_parents = 1, }, }; static const struct reg_sequence g12a_mpll0_init_regs[] = { { .reg = HHI_MPLL_CNTL2, .def = 0x40000033 }, }; static struct clk_regmap g12a_mpll0_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL1, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL1, .shift = 30, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL1, .shift = 20, .width = 9, }, .ssen = { .reg_off = HHI_MPLL_CNTL1, .shift = 29, .width = 1, }, .lock = &meson_clk_lock, .init_regs = g12a_mpll0_init_regs, .init_count = ARRAY_SIZE(g12a_mpll0_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "mpll0_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_mpll0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL1, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "mpll0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpll0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct reg_sequence g12a_mpll1_init_regs[] = { { .reg = HHI_MPLL_CNTL4, .def = 0x40000033 }, }; static struct clk_regmap g12a_mpll1_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL3, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL3, .shift = 30, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL3, .shift = 20, .width = 9, }, .ssen = { .reg_off = HHI_MPLL_CNTL3, .shift = 29, .width = 1, }, .lock = &meson_clk_lock, .init_regs = g12a_mpll1_init_regs, .init_count = ARRAY_SIZE(g12a_mpll1_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "mpll1_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_mpll1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL3, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "mpll1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpll1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct reg_sequence g12a_mpll2_init_regs[] = { { .reg = HHI_MPLL_CNTL6, .def = 0x40000033 }, }; static struct clk_regmap g12a_mpll2_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL5, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL5, .shift = 30, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL5, .shift = 20, .width = 9, }, .ssen = { .reg_off = HHI_MPLL_CNTL5, .shift = 29, .width = 1, }, .lock = &meson_clk_lock, .init_regs = g12a_mpll2_init_regs, .init_count = ARRAY_SIZE(g12a_mpll2_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "mpll2_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_mpll2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL5, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "mpll2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpll2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct reg_sequence g12a_mpll3_init_regs[] = { { .reg = HHI_MPLL_CNTL8, .def = 0x40000033 }, }; static struct clk_regmap g12a_mpll3_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL7, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL7, .shift = 30, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL7, .shift = 20, .width = 9, }, .ssen = { .reg_off = HHI_MPLL_CNTL7, .shift = 29, .width = 1, }, .lock = &meson_clk_lock, .init_regs = g12a_mpll3_init_regs, .init_count = ARRAY_SIZE(g12a_mpll3_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "mpll3_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap g12a_mpll3 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL7, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "mpll3", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpll3_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_clk81[] = { 0, 2, 3, 4, 5, 6, 7 }; static const struct clk_parent_data clk81_parent_data[] = { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div7.hw }, { .hw = &g12a_mpll1.hw }, { .hw = &g12a_mpll2.hw }, { .hw = &g12a_fclk_div4.hw }, { .hw = &g12a_fclk_div3.hw }, { .hw = &g12a_fclk_div5.hw }, }; static struct clk_regmap g12a_mpeg_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MPEG_CLK_CNTL, .mask = 0x7, .shift = 12, .table = mux_table_clk81, }, .hw.init = &(struct clk_init_data){ .name = "mpeg_clk_sel", .ops = &clk_regmap_mux_ro_ops, .parent_data = clk81_parent_data, .num_parents = ARRAY_SIZE(clk81_parent_data), }, }; static struct clk_regmap g12a_mpeg_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPEG_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mpeg_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpeg_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_clk81 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPEG_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "clk81", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mpeg_clk_div.hw }, .num_parents = 1, .flags = (CLK_SET_RATE_PARENT | CLK_IS_CRITICAL), }, }; static const struct clk_parent_data g12a_sd_emmc_clk0_parent_data[] = { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div2.hw }, { .hw = &g12a_fclk_div3.hw }, { .hw = &g12a_fclk_div5.hw }, { .hw = &g12a_fclk_div7.hw }, /* * Following these parent clocks, we should also have had mpll2, mpll3 * and gp0_pll but these clocks are too precious to be used here. All * the necessary rates for MMC and NAND operation can be acheived using * g12a_ee_core or fclk_div clocks */ }; /* SDIO clock */ static struct clk_regmap g12a_sd_emmc_a_clk0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .mask = 0x7, .shift = 9, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_a_clk0_sel", .ops = &clk_regmap_mux_ops, .parent_data = g12a_sd_emmc_clk0_parent_data, .num_parents = ARRAY_SIZE(g12a_sd_emmc_clk0_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_sd_emmc_a_clk0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_a_clk0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sd_emmc_a_clk0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_sd_emmc_a_clk0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_a_clk0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sd_emmc_a_clk0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* SDcard clock */ static struct clk_regmap g12a_sd_emmc_b_clk0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .mask = 0x7, .shift = 25, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_b_clk0_sel", .ops = &clk_regmap_mux_ops, .parent_data = g12a_sd_emmc_clk0_parent_data, .num_parents = ARRAY_SIZE(g12a_sd_emmc_clk0_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_sd_emmc_b_clk0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_b_clk0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sd_emmc_b_clk0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_sd_emmc_b_clk0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .bit_idx = 23, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_b_clk0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sd_emmc_b_clk0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* EMMC/NAND clock */ static struct clk_regmap g12a_sd_emmc_c_clk0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_NAND_CLK_CNTL, .mask = 0x7, .shift = 9, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_c_clk0_sel", .ops = &clk_regmap_mux_ops, .parent_data = g12a_sd_emmc_clk0_parent_data, .num_parents = ARRAY_SIZE(g12a_sd_emmc_clk0_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_sd_emmc_c_clk0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_NAND_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_c_clk0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sd_emmc_c_clk0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_sd_emmc_c_clk0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_NAND_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_c_clk0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_sd_emmc_c_clk0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* Video Clocks */ static struct clk_regmap g12a_vid_pll_div = { .data = &(struct meson_vid_pll_div_data){ .val = { .reg_off = HHI_VID_PLL_CLK_DIV, .shift = 0, .width = 15, }, .sel = { .reg_off = HHI_VID_PLL_CLK_DIV, .shift = 16, .width = 2, }, }, .hw.init = &(struct clk_init_data) { .name = "vid_pll_div", .ops = &meson_vid_pll_div_ro_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_hdmi_pll.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE, }, }; static const struct clk_hw *g12a_vid_pll_parent_hws[] = { &g12a_vid_pll_div.hw, &g12a_hdmi_pll.hw, }; static struct clk_regmap g12a_vid_pll_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_PLL_CLK_DIV, .mask = 0x1, .shift = 18, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll_sel", .ops = &clk_regmap_mux_ops, /* * bit 18 selects from 2 possible parents: * vid_pll_div or hdmi_pll */ .parent_hws = g12a_vid_pll_parent_hws, .num_parents = ARRAY_SIZE(g12a_vid_pll_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_vid_pll = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_PLL_CLK_DIV, .bit_idx = 19, }, .hw.init = &(struct clk_init_data) { .name = "vid_pll", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vid_pll_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; /* VPU Clock */ static const struct clk_hw *g12a_vpu_parent_hws[] = { &g12a_fclk_div3.hw, &g12a_fclk_div4.hw, &g12a_fclk_div5.hw, &g12a_fclk_div7.hw, &g12a_mpll1.hw, &g12a_vid_pll.hw, &g12a_hifi_pll.hw, &g12a_gp0_pll.hw, }; static struct clk_regmap g12a_vpu_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x7, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vpu_parent_hws, .num_parents = ARRAY_SIZE(g12a_vpu_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap g12a_vpu_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VPU_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vpu_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vpu_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VPU_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vpu_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vpu_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vpu_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x7, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vpu_parent_hws, .num_parents = ARRAY_SIZE(g12a_vpu_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap g12a_vpu_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VPU_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vpu_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vpu_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VPU_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vpu_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vpu_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vpu = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "vpu", .ops = &clk_regmap_mux_ops, /* * bit 31 selects from 2 possible parents: * vpu_0 or vpu_1 */ .parent_hws = (const struct clk_hw *[]) { &g12a_vpu_0.hw, &g12a_vpu_1.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_NO_REPARENT, }, }; /* VDEC clocks */ static const struct clk_hw *g12a_vdec_parent_hws[] = { &g12a_fclk_div2p5.hw, &g12a_fclk_div3.hw, &g12a_fclk_div4.hw, &g12a_fclk_div5.hw, &g12a_fclk_div7.hw, &g12a_hifi_pll.hw, &g12a_gp0_pll.hw, }; static struct clk_regmap g12a_vdec_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC_CLK_CNTL, .mask = 0x7, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vdec_parent_hws, .num_parents = ARRAY_SIZE(g12a_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vdec_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vdec_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vdec_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vdec_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vdec_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vdec_hevcf_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC2_CLK_CNTL, .mask = 0x7, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevcf_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vdec_parent_hws, .num_parents = ARRAY_SIZE(g12a_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vdec_hevcf_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC2_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevcf_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vdec_hevcf_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vdec_hevcf = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC2_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vdec_hevcf", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vdec_hevcf_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vdec_hevc_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC2_CLK_CNTL, .mask = 0x7, .shift = 25, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevc_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vdec_parent_hws, .num_parents = ARRAY_SIZE(g12a_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vdec_hevc_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC2_CLK_CNTL, .shift = 16, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vdec_hevc_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vdec_hevc = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC2_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vdec_hevc", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vdec_hevc_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* VAPB Clock */ static const struct clk_hw *g12a_vapb_parent_hws[] = { &g12a_fclk_div4.hw, &g12a_fclk_div3.hw, &g12a_fclk_div5.hw, &g12a_fclk_div7.hw, &g12a_mpll1.hw, &g12a_vid_pll.hw, &g12a_mpll2.hw, &g12a_fclk_div2p5.hw, }; static struct clk_regmap g12a_vapb_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "vapb_0_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vapb_parent_hws, .num_parents = ARRAY_SIZE(g12a_vapb_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap g12a_vapb_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VAPBCLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vapb_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vapb_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vapb_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vapb_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vapb_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vapb_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 0x3, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "vapb_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vapb_parent_hws, .num_parents = ARRAY_SIZE(g12a_vapb_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap g12a_vapb_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VAPBCLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vapb_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vapb_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_vapb_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vapb_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vapb_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vapb_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "vapb_sel", .ops = &clk_regmap_mux_ops, /* * bit 31 selects from 2 possible parents: * vapb_0 or vapb_1 */ .parent_hws = (const struct clk_hw *[]) { &g12a_vapb_0.hw, &g12a_vapb_1.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap g12a_vapb = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 30, }, .hw.init = &(struct clk_init_data) { .name = "vapb", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vapb_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static const struct clk_hw *g12a_vclk_parent_hws[] = { &g12a_vid_pll.hw, &g12a_gp0_pll.hw, &g12a_hifi_pll.hw, &g12a_mpll1.hw, &g12a_fclk_div3.hw, &g12a_fclk_div4.hw, &g12a_fclk_div5.hw, &g12a_fclk_div7.hw, }; static struct clk_regmap g12a_vclk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_CNTL, .mask = 0x7, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vclk_parent_hws, .num_parents = ARRAY_SIZE(g12a_vclk_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_vclk2_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_CNTL, .mask = 0x7, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_vclk_parent_hws, .num_parents = ARRAY_SIZE(g12a_vclk_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_vclk_input = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_DIV, .bit_idx = 16, }, .hw.init = &(struct clk_init_data) { .name = "vclk_input", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk2_input = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 16, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_input", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VID_CLK_DIV, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "vclk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk_input.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_vclk2_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VIID_CLK_DIV, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2_input.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_vclk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 19, }, .hw.init = &(struct clk_init_data) { .name = "vclk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 19, }, .hw.init = &(struct clk_init_data) { .name = "vclk2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk_div1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk_div2_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk_div4_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div4_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk_div6_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div6_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk_div12_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div12_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk2_div1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk2_div2_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk2_div4_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div4_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk2_div6_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div6_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_vclk2_div12_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div12_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_fixed_factor g12a_vclk_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "vclk_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk_div2_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_vclk_div4 = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "vclk_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk_div4_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_vclk_div6 = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "vclk_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk_div6_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_vclk_div12 = { .mult = 1, .div = 12, .hw.init = &(struct clk_init_data){ .name = "vclk_div12", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk_div12_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_vclk2_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "vclk2_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2_div2_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_vclk2_div4 = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "vclk2_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2_div4_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_vclk2_div6 = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "vclk2_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2_div6_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor g12a_vclk2_div12 = { .mult = 1, .div = 12, .hw.init = &(struct clk_init_data){ .name = "vclk2_div12", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_vclk2_div12_en.hw }, .num_parents = 1, }, }; static u32 mux_table_cts_sel[] = { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12 }; static const struct clk_hw *g12a_cts_parent_hws[] = { &g12a_vclk_div1.hw, &g12a_vclk_div2.hw, &g12a_vclk_div4.hw, &g12a_vclk_div6.hw, &g12a_vclk_div12.hw, &g12a_vclk2_div1.hw, &g12a_vclk2_div2.hw, &g12a_vclk2_div4.hw, &g12a_vclk2_div6.hw, &g12a_vclk2_div12.hw, }; static struct clk_regmap g12a_cts_enci_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_DIV, .mask = 0xf, .shift = 28, .table = mux_table_cts_sel, }, .hw.init = &(struct clk_init_data){ .name = "cts_enci_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_cts_parent_hws, .num_parents = ARRAY_SIZE(g12a_cts_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_cts_encp_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_DIV, .mask = 0xf, .shift = 20, .table = mux_table_cts_sel, }, .hw.init = &(struct clk_init_data){ .name = "cts_encp_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_cts_parent_hws, .num_parents = ARRAY_SIZE(g12a_cts_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_cts_vdac_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_DIV, .mask = 0xf, .shift = 28, .table = mux_table_cts_sel, }, .hw.init = &(struct clk_init_data){ .name = "cts_vdac_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_cts_parent_hws, .num_parents = ARRAY_SIZE(g12a_cts_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; /* TOFIX: add support for cts_tcon */ static u32 mux_table_hdmi_tx_sel[] = { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12 }; static const struct clk_hw *g12a_cts_hdmi_tx_parent_hws[] = { &g12a_vclk_div1.hw, &g12a_vclk_div2.hw, &g12a_vclk_div4.hw, &g12a_vclk_div6.hw, &g12a_vclk_div12.hw, &g12a_vclk2_div1.hw, &g12a_vclk2_div2.hw, &g12a_vclk2_div4.hw, &g12a_vclk2_div6.hw, &g12a_vclk2_div12.hw, }; static struct clk_regmap g12a_hdmi_tx_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_HDMI_CLK_CNTL, .mask = 0xf, .shift = 16, .table = mux_table_hdmi_tx_sel, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_tx_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_cts_hdmi_tx_parent_hws, .num_parents = ARRAY_SIZE(g12a_cts_hdmi_tx_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_cts_enci = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "cts_enci", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cts_enci_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_cts_encp = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "cts_encp", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cts_encp_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_cts_vdac = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "cts_vdac", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_cts_vdac_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap g12a_hdmi_tx = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 5, }, .hw.init = &(struct clk_init_data) { .name = "hdmi_tx", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_hdmi_tx_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; /* MIPI DSI Host Clocks */ static const struct clk_hw *g12a_mipi_dsi_pxclk_parent_hws[] = { &g12a_vid_pll.hw, &g12a_gp0_pll.hw, &g12a_hifi_pll.hw, &g12a_mpll1.hw, &g12a_fclk_div2.hw, &g12a_fclk_div2p5.hw, &g12a_fclk_div3.hw, &g12a_fclk_div7.hw, }; static struct clk_regmap g12a_mipi_dsi_pxclk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MIPIDSI_PHY_CLK_CNTL, .mask = 0x7, .shift = 12, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mipi_dsi_pxclk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_mipi_dsi_pxclk_parent_hws, .num_parents = ARRAY_SIZE(g12a_mipi_dsi_pxclk_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap g12a_mipi_dsi_pxclk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MIPIDSI_PHY_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mipi_dsi_pxclk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mipi_dsi_pxclk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_mipi_dsi_pxclk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MIPIDSI_PHY_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "mipi_dsi_pxclk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mipi_dsi_pxclk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* HDMI Clocks */ static const struct clk_parent_data g12a_hdmi_parent_data[] = { { .fw_name = "xtal", }, { .hw = &g12a_fclk_div4.hw }, { .hw = &g12a_fclk_div3.hw }, { .hw = &g12a_fclk_div5.hw }, }; static struct clk_regmap g12a_hdmi_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_HDMI_CLK_CNTL, .mask = 0x3, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_sel", .ops = &clk_regmap_mux_ops, .parent_data = g12a_hdmi_parent_data, .num_parents = ARRAY_SIZE(g12a_hdmi_parent_data), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_hdmi_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_hdmi_sel.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap g12a_hdmi = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_HDMI_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "hdmi", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_hdmi_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; /* * The MALI IP is clocked by two identical clocks (mali_0 and mali_1) * muxed by a glitch-free switch. The CCF can manage this glitch-free * mux because it does top-to-bottom updates the each clock tree and * switches to the "inactive" one when CLK_SET_RATE_GATE is set. */ static const struct clk_parent_data g12a_mali_0_1_parent_data[] = { { .fw_name = "xtal", }, { .hw = &g12a_gp0_pll.hw }, { .hw = &g12a_hifi_pll.hw }, { .hw = &g12a_fclk_div2p5.hw }, { .hw = &g12a_fclk_div3.hw }, { .hw = &g12a_fclk_div4.hw }, { .hw = &g12a_fclk_div5.hw }, { .hw = &g12a_fclk_div7.hw }, }; static struct clk_regmap g12a_mali_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 0x7, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "mali_0_sel", .ops = &clk_regmap_mux_ops, .parent_data = g12a_mali_0_1_parent_data, .num_parents = 8, /* * Don't request the parent to change the rate because * all GPU frequencies can be derived from the fclk_* * clocks and one special GP0_PLL setting. This is * important because we need the MPLL clocks for audio. */ .flags = 0, }, }; static struct clk_regmap g12a_mali_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MALI_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mali_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mali_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_mali_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MALI_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "mali_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mali_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_mali_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 0x7, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "mali_1_sel", .ops = &clk_regmap_mux_ops, .parent_data = g12a_mali_0_1_parent_data, .num_parents = 8, /* * Don't request the parent to change the rate because * all GPU frequencies can be derived from the fclk_* * clocks and one special GP0_PLL setting. This is * important because we need the MPLL clocks for audio. */ .flags = 0, }, }; static struct clk_regmap g12a_mali_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MALI_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mali_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mali_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_mali_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MALI_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data){ .name = "mali_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_mali_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT, }, }; static const struct clk_hw *g12a_mali_parent_hws[] = { &g12a_mali_0.hw, &g12a_mali_1.hw, }; static struct clk_regmap g12a_mali = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "mali", .ops = &clk_regmap_mux_ops, .parent_hws = g12a_mali_parent_hws, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_ts_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_TS_CLK_CNTL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "ts_div", .ops = &clk_regmap_divider_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap g12a_ts = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_TS_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "ts", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_ts_div.hw }, .num_parents = 1, }, }; /* SPICC SCLK source clock */ static const struct clk_parent_data spicc_sclk_parent_data[] = { { .fw_name = "xtal", }, { .hw = &g12a_clk81.hw }, { .hw = &g12a_fclk_div4.hw }, { .hw = &g12a_fclk_div3.hw }, { .hw = &g12a_fclk_div5.hw }, { .hw = &g12a_fclk_div7.hw }, }; static struct clk_regmap g12a_spicc0_sclk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SPICC_CLK_CNTL, .mask = 7, .shift = 7, }, .hw.init = &(struct clk_init_data){ .name = "spicc0_sclk_sel", .ops = &clk_regmap_mux_ops, .parent_data = spicc_sclk_parent_data, .num_parents = ARRAY_SIZE(spicc_sclk_parent_data), }, }; static struct clk_regmap g12a_spicc0_sclk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SPICC_CLK_CNTL, .shift = 0, .width = 6, }, .hw.init = &(struct clk_init_data){ .name = "spicc0_sclk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_spicc0_sclk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_spicc0_sclk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SPICC_CLK_CNTL, .bit_idx = 6, }, .hw.init = &(struct clk_init_data){ .name = "spicc0_sclk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_spicc0_sclk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_spicc1_sclk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SPICC_CLK_CNTL, .mask = 7, .shift = 23, }, .hw.init = &(struct clk_init_data){ .name = "spicc1_sclk_sel", .ops = &clk_regmap_mux_ops, .parent_data = spicc_sclk_parent_data, .num_parents = ARRAY_SIZE(spicc_sclk_parent_data), }, }; static struct clk_regmap g12a_spicc1_sclk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SPICC_CLK_CNTL, .shift = 16, .width = 6, }, .hw.init = &(struct clk_init_data){ .name = "spicc1_sclk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_spicc1_sclk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap g12a_spicc1_sclk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SPICC_CLK_CNTL, .bit_idx = 22, }, .hw.init = &(struct clk_init_data){ .name = "spicc1_sclk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &g12a_spicc1_sclk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* Neural Network Accelerator source clock */ static const struct clk_parent_data nna_clk_parent_data[] = { { .fw_name = "xtal", }, { .hw = &g12a_gp0_pll.hw, }, { .hw = &g12a_hifi_pll.hw, }, { .hw = &g12a_fclk_div2p5.hw, }, { .hw = &g12a_fclk_div3.hw, }, { .hw = &g12a_fclk_div4.hw, }, { .hw = &g12a_fclk_div5.hw, }, { .hw = &g12a_fclk_div7.hw }, }; static struct clk_regmap sm1_nna_axi_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_NNA_CLK_CNTL, .mask = 7, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "nna_axi_clk_sel", .ops = &clk_regmap_mux_ops, .parent_data = nna_clk_parent_data, .num_parents = ARRAY_SIZE(nna_clk_parent_data), }, }; static struct clk_regmap sm1_nna_axi_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_NNA_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "nna_axi_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_nna_axi_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sm1_nna_axi_clk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_NNA_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "nna_axi_clk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_nna_axi_clk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sm1_nna_core_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_NNA_CLK_CNTL, .mask = 7, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "nna_core_clk_sel", .ops = &clk_regmap_mux_ops, .parent_data = nna_clk_parent_data, .num_parents = ARRAY_SIZE(nna_clk_parent_data), }, }; static struct clk_regmap sm1_nna_core_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_NNA_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "nna_core_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_nna_core_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sm1_nna_core_clk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_NNA_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data){ .name = "nna_core_clk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &sm1_nna_core_clk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; #define MESON_GATE(_name, _reg, _bit) \ MESON_PCLK(_name, _reg, _bit, &g12a_clk81.hw) #define MESON_GATE_RO(_name, _reg, _bit) \ MESON_PCLK_RO(_name, _reg, _bit, &g12a_clk81.hw) /* Everything Else (EE) domain gates */ static MESON_GATE(g12a_ddr, HHI_GCLK_MPEG0, 0); static MESON_GATE(g12a_dos, HHI_GCLK_MPEG0, 1); static MESON_GATE(g12a_audio_locker, HHI_GCLK_MPEG0, 2); static MESON_GATE(g12a_mipi_dsi_host, HHI_GCLK_MPEG0, 3); static MESON_GATE(g12a_eth_phy, HHI_GCLK_MPEG0, 4); static MESON_GATE(g12a_isa, HHI_GCLK_MPEG0, 5); static MESON_GATE(g12a_pl301, HHI_GCLK_MPEG0, 6); static MESON_GATE(g12a_periphs, HHI_GCLK_MPEG0, 7); static MESON_GATE(g12a_spicc_0, HHI_GCLK_MPEG0, 8); static MESON_GATE(g12a_i2c, HHI_GCLK_MPEG0, 9); static MESON_GATE(g12a_sana, HHI_GCLK_MPEG0, 10); static MESON_GATE(g12a_sd, HHI_GCLK_MPEG0, 11); static MESON_GATE(g12a_rng0, HHI_GCLK_MPEG0, 12); static MESON_GATE(g12a_uart0, HHI_GCLK_MPEG0, 13); static MESON_GATE(g12a_spicc_1, HHI_GCLK_MPEG0, 14); static MESON_GATE(g12a_hiu_reg, HHI_GCLK_MPEG0, 19); static MESON_GATE(g12a_mipi_dsi_phy, HHI_GCLK_MPEG0, 20); static MESON_GATE(g12a_assist_misc, HHI_GCLK_MPEG0, 23); static MESON_GATE(g12a_emmc_a, HHI_GCLK_MPEG0, 4); static MESON_GATE(g12a_emmc_b, HHI_GCLK_MPEG0, 25); static MESON_GATE(g12a_emmc_c, HHI_GCLK_MPEG0, 26); static MESON_GATE(g12a_audio_codec, HHI_GCLK_MPEG0, 28); static MESON_GATE(g12a_audio, HHI_GCLK_MPEG1, 0); static MESON_GATE(g12a_eth_core, HHI_GCLK_MPEG1, 3); static MESON_GATE(g12a_demux, HHI_GCLK_MPEG1, 4); static MESON_GATE(g12a_audio_ififo, HHI_GCLK_MPEG1, 11); static MESON_GATE(g12a_adc, HHI_GCLK_MPEG1, 13); static MESON_GATE(g12a_uart1, HHI_GCLK_MPEG1, 16); static MESON_GATE(g12a_g2d, HHI_GCLK_MPEG1, 20); static MESON_GATE(g12a_reset, HHI_GCLK_MPEG1, 23); static MESON_GATE(g12a_pcie_comb, HHI_GCLK_MPEG1, 24); static MESON_GATE(g12a_parser, HHI_GCLK_MPEG1, 25); static MESON_GATE(g12a_usb_general, HHI_GCLK_MPEG1, 26); static MESON_GATE(g12a_pcie_phy, HHI_GCLK_MPEG1, 27); static MESON_GATE(g12a_ahb_arb0, HHI_GCLK_MPEG1, 29); static MESON_GATE(g12a_ahb_data_bus, HHI_GCLK_MPEG2, 1); static MESON_GATE(g12a_ahb_ctrl_bus, HHI_GCLK_MPEG2, 2); static MESON_GATE(g12a_htx_hdcp22, HHI_GCLK_MPEG2, 3); static MESON_GATE(g12a_htx_pclk, HHI_GCLK_MPEG2, 4); static MESON_GATE(g12a_bt656, HHI_GCLK_MPEG2, 6); static MESON_GATE(g12a_usb1_to_ddr, HHI_GCLK_MPEG2, 8); static MESON_GATE(g12a_mmc_pclk, HHI_GCLK_MPEG2, 11); static MESON_GATE(g12a_uart2, HHI_GCLK_MPEG2, 15); static MESON_GATE(g12a_vpu_intr, HHI_GCLK_MPEG2, 25); static MESON_GATE(g12a_gic, HHI_GCLK_MPEG2, 30); static MESON_GATE(g12a_vclk2_venci0, HHI_GCLK_OTHER, 1); static MESON_GATE(g12a_vclk2_venci1, HHI_GCLK_OTHER, 2); static MESON_GATE(g12a_vclk2_vencp0, HHI_GCLK_OTHER, 3); static MESON_GATE(g12a_vclk2_vencp1, HHI_GCLK_OTHER, 4); static MESON_GATE(g12a_vclk2_venct0, HHI_GCLK_OTHER, 5); static MESON_GATE(g12a_vclk2_venct1, HHI_GCLK_OTHER, 6); static MESON_GATE(g12a_vclk2_other, HHI_GCLK_OTHER, 7); static MESON_GATE(g12a_vclk2_enci, HHI_GCLK_OTHER, 8); static MESON_GATE(g12a_vclk2_encp, HHI_GCLK_OTHER, 9); static MESON_GATE(g12a_dac_clk, HHI_GCLK_OTHER, 10); static MESON_GATE(g12a_aoclk_gate, HHI_GCLK_OTHER, 14); static MESON_GATE(g12a_iec958_gate, HHI_GCLK_OTHER, 16); static MESON_GATE(g12a_enc480p, HHI_GCLK_OTHER, 20); static MESON_GATE(g12a_rng1, HHI_GCLK_OTHER, 21); static MESON_GATE(g12a_vclk2_enct, HHI_GCLK_OTHER, 22); static MESON_GATE(g12a_vclk2_encl, HHI_GCLK_OTHER, 23); static MESON_GATE(g12a_vclk2_venclmmc, HHI_GCLK_OTHER, 24); static MESON_GATE(g12a_vclk2_vencl, HHI_GCLK_OTHER, 25); static MESON_GATE(g12a_vclk2_other1, HHI_GCLK_OTHER, 26); static MESON_GATE_RO(g12a_dma, HHI_GCLK_OTHER2, 0); static MESON_GATE_RO(g12a_efuse, HHI_GCLK_OTHER2, 1); static MESON_GATE_RO(g12a_rom_boot, HHI_GCLK_OTHER2, 2); static MESON_GATE_RO(g12a_reset_sec, HHI_GCLK_OTHER2, 3); static MESON_GATE_RO(g12a_sec_ahb_apb3, HHI_GCLK_OTHER2, 4); /* Array of all clocks provided by this provider */ static struct clk_hw *g12a_hw_clks[] = { [CLKID_SYS_PLL] = &g12a_sys_pll.hw, [CLKID_FIXED_PLL] = &g12a_fixed_pll.hw, [CLKID_FCLK_DIV2] = &g12a_fclk_div2.hw, [CLKID_FCLK_DIV3] = &g12a_fclk_div3.hw, [CLKID_FCLK_DIV4] = &g12a_fclk_div4.hw, [CLKID_FCLK_DIV5] = &g12a_fclk_div5.hw, [CLKID_FCLK_DIV7] = &g12a_fclk_div7.hw, [CLKID_FCLK_DIV2P5] = &g12a_fclk_div2p5.hw, [CLKID_GP0_PLL] = &g12a_gp0_pll.hw, [CLKID_MPEG_SEL] = &g12a_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &g12a_mpeg_clk_div.hw, [CLKID_CLK81] = &g12a_clk81.hw, [CLKID_MPLL0] = &g12a_mpll0.hw, [CLKID_MPLL1] = &g12a_mpll1.hw, [CLKID_MPLL2] = &g12a_mpll2.hw, [CLKID_MPLL3] = &g12a_mpll3.hw, [CLKID_DDR] = &g12a_ddr.hw, [CLKID_DOS] = &g12a_dos.hw, [CLKID_AUDIO_LOCKER] = &g12a_audio_locker.hw, [CLKID_MIPI_DSI_HOST] = &g12a_mipi_dsi_host.hw, [CLKID_ETH_PHY] = &g12a_eth_phy.hw, [CLKID_ISA] = &g12a_isa.hw, [CLKID_PL301] = &g12a_pl301.hw, [CLKID_PERIPHS] = &g12a_periphs.hw, [CLKID_SPICC0] = &g12a_spicc_0.hw, [CLKID_I2C] = &g12a_i2c.hw, [CLKID_SANA] = &g12a_sana.hw, [CLKID_SD] = &g12a_sd.hw, [CLKID_RNG0] = &g12a_rng0.hw, [CLKID_UART0] = &g12a_uart0.hw, [CLKID_SPICC1] = &g12a_spicc_1.hw, [CLKID_HIU_IFACE] = &g12a_hiu_reg.hw, [CLKID_MIPI_DSI_PHY] = &g12a_mipi_dsi_phy.hw, [CLKID_ASSIST_MISC] = &g12a_assist_misc.hw, [CLKID_SD_EMMC_A] = &g12a_emmc_a.hw, [CLKID_SD_EMMC_B] = &g12a_emmc_b.hw, [CLKID_SD_EMMC_C] = &g12a_emmc_c.hw, [CLKID_AUDIO_CODEC] = &g12a_audio_codec.hw, [CLKID_AUDIO] = &g12a_audio.hw, [CLKID_ETH] = &g12a_eth_core.hw, [CLKID_DEMUX] = &g12a_demux.hw, [CLKID_AUDIO_IFIFO] = &g12a_audio_ififo.hw, [CLKID_ADC] = &g12a_adc.hw, [CLKID_UART1] = &g12a_uart1.hw, [CLKID_G2D] = &g12a_g2d.hw, [CLKID_RESET] = &g12a_reset.hw, [CLKID_PCIE_COMB] = &g12a_pcie_comb.hw, [CLKID_PARSER] = &g12a_parser.hw, [CLKID_USB] = &g12a_usb_general.hw, [CLKID_PCIE_PHY] = &g12a_pcie_phy.hw, [CLKID_AHB_ARB0] = &g12a_ahb_arb0.hw, [CLKID_AHB_DATA_BUS] = &g12a_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &g12a_ahb_ctrl_bus.hw, [CLKID_HTX_HDCP22] = &g12a_htx_hdcp22.hw, [CLKID_HTX_PCLK] = &g12a_htx_pclk.hw, [CLKID_BT656] = &g12a_bt656.hw, [CLKID_USB1_DDR_BRIDGE] = &g12a_usb1_to_ddr.hw, [CLKID_MMC_PCLK] = &g12a_mmc_pclk.hw, [CLKID_UART2] = &g12a_uart2.hw, [CLKID_VPU_INTR] = &g12a_vpu_intr.hw, [CLKID_GIC] = &g12a_gic.hw, [CLKID_SD_EMMC_A_CLK0_SEL] = &g12a_sd_emmc_a_clk0_sel.hw, [CLKID_SD_EMMC_A_CLK0_DIV] = &g12a_sd_emmc_a_clk0_div.hw, [CLKID_SD_EMMC_A_CLK0] = &g12a_sd_emmc_a_clk0.hw, [CLKID_SD_EMMC_B_CLK0_SEL] = &g12a_sd_emmc_b_clk0_sel.hw, [CLKID_SD_EMMC_B_CLK0_DIV] = &g12a_sd_emmc_b_clk0_div.hw, [CLKID_SD_EMMC_B_CLK0] = &g12a_sd_emmc_b_clk0.hw, [CLKID_SD_EMMC_C_CLK0_SEL] = &g12a_sd_emmc_c_clk0_sel.hw, [CLKID_SD_EMMC_C_CLK0_DIV] = &g12a_sd_emmc_c_clk0_div.hw, [CLKID_SD_EMMC_C_CLK0] = &g12a_sd_emmc_c_clk0.hw, [CLKID_MPLL0_DIV] = &g12a_mpll0_div.hw, [CLKID_MPLL1_DIV] = &g12a_mpll1_div.hw, [CLKID_MPLL2_DIV] = &g12a_mpll2_div.hw, [CLKID_MPLL3_DIV] = &g12a_mpll3_div.hw, [CLKID_FCLK_DIV2_DIV] = &g12a_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &g12a_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &g12a_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &g12a_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &g12a_fclk_div7_div.hw, [CLKID_FCLK_DIV2P5_DIV] = &g12a_fclk_div2p5_div.hw, [CLKID_HIFI_PLL] = &g12a_hifi_pll.hw, [CLKID_VCLK2_VENCI0] = &g12a_vclk2_venci0.hw, [CLKID_VCLK2_VENCI1] = &g12a_vclk2_venci1.hw, [CLKID_VCLK2_VENCP0] = &g12a_vclk2_vencp0.hw, [CLKID_VCLK2_VENCP1] = &g12a_vclk2_vencp1.hw, [CLKID_VCLK2_VENCT0] = &g12a_vclk2_venct0.hw, [CLKID_VCLK2_VENCT1] = &g12a_vclk2_venct1.hw, [CLKID_VCLK2_OTHER] = &g12a_vclk2_other.hw, [CLKID_VCLK2_ENCI] = &g12a_vclk2_enci.hw, [CLKID_VCLK2_ENCP] = &g12a_vclk2_encp.hw, [CLKID_DAC_CLK] = &g12a_dac_clk.hw, [CLKID_AOCLK] = &g12a_aoclk_gate.hw, [CLKID_IEC958] = &g12a_iec958_gate.hw, [CLKID_ENC480P] = &g12a_enc480p.hw, [CLKID_RNG1] = &g12a_rng1.hw, [CLKID_VCLK2_ENCT] = &g12a_vclk2_enct.hw, [CLKID_VCLK2_ENCL] = &g12a_vclk2_encl.hw, [CLKID_VCLK2_VENCLMMC] = &g12a_vclk2_venclmmc.hw, [CLKID_VCLK2_VENCL] = &g12a_vclk2_vencl.hw, [CLKID_VCLK2_OTHER1] = &g12a_vclk2_other1.hw, [CLKID_FIXED_PLL_DCO] = &g12a_fixed_pll_dco.hw, [CLKID_SYS_PLL_DCO] = &g12a_sys_pll_dco.hw, [CLKID_GP0_PLL_DCO] = &g12a_gp0_pll_dco.hw, [CLKID_HIFI_PLL_DCO] = &g12a_hifi_pll_dco.hw, [CLKID_DMA] = &g12a_dma.hw, [CLKID_EFUSE] = &g12a_efuse.hw, [CLKID_ROM_BOOT] = &g12a_rom_boot.hw, [CLKID_RESET_SEC] = &g12a_reset_sec.hw, [CLKID_SEC_AHB_APB3] = &g12a_sec_ahb_apb3.hw, [CLKID_MPLL_PREDIV] = &g12a_mpll_prediv.hw, [CLKID_VPU_0_SEL] = &g12a_vpu_0_sel.hw, [CLKID_VPU_0_DIV] = &g12a_vpu_0_div.hw, [CLKID_VPU_0] = &g12a_vpu_0.hw, [CLKID_VPU_1_SEL] = &g12a_vpu_1_sel.hw, [CLKID_VPU_1_DIV] = &g12a_vpu_1_div.hw, [CLKID_VPU_1] = &g12a_vpu_1.hw, [CLKID_VPU] = &g12a_vpu.hw, [CLKID_VAPB_0_SEL] = &g12a_vapb_0_sel.hw, [CLKID_VAPB_0_DIV] = &g12a_vapb_0_div.hw, [CLKID_VAPB_0] = &g12a_vapb_0.hw, [CLKID_VAPB_1_SEL] = &g12a_vapb_1_sel.hw, [CLKID_VAPB_1_DIV] = &g12a_vapb_1_div.hw, [CLKID_VAPB_1] = &g12a_vapb_1.hw, [CLKID_VAPB_SEL] = &g12a_vapb_sel.hw, [CLKID_VAPB] = &g12a_vapb.hw, [CLKID_HDMI_PLL_DCO] = &g12a_hdmi_pll_dco.hw, [CLKID_HDMI_PLL_OD] = &g12a_hdmi_pll_od.hw, [CLKID_HDMI_PLL_OD2] = &g12a_hdmi_pll_od2.hw, [CLKID_HDMI_PLL] = &g12a_hdmi_pll.hw, [CLKID_VID_PLL] = &g12a_vid_pll_div.hw, [CLKID_VID_PLL_SEL] = &g12a_vid_pll_sel.hw, [CLKID_VID_PLL_DIV] = &g12a_vid_pll.hw, [CLKID_VCLK_SEL] = &g12a_vclk_sel.hw, [CLKID_VCLK2_SEL] = &g12a_vclk2_sel.hw, [CLKID_VCLK_INPUT] = &g12a_vclk_input.hw, [CLKID_VCLK2_INPUT] = &g12a_vclk2_input.hw, [CLKID_VCLK_DIV] = &g12a_vclk_div.hw, [CLKID_VCLK2_DIV] = &g12a_vclk2_div.hw, [CLKID_VCLK] = &g12a_vclk.hw, [CLKID_VCLK2] = &g12a_vclk2.hw, [CLKID_VCLK_DIV1] = &g12a_vclk_div1.hw, [CLKID_VCLK_DIV2_EN] = &g12a_vclk_div2_en.hw, [CLKID_VCLK_DIV4_EN] = &g12a_vclk_div4_en.hw, [CLKID_VCLK_DIV6_EN] = &g12a_vclk_div6_en.hw, [CLKID_VCLK_DIV12_EN] = &g12a_vclk_div12_en.hw, [CLKID_VCLK2_DIV1] = &g12a_vclk2_div1.hw, [CLKID_VCLK2_DIV2_EN] = &g12a_vclk2_div2_en.hw, [CLKID_VCLK2_DIV4_EN] = &g12a_vclk2_div4_en.hw, [CLKID_VCLK2_DIV6_EN] = &g12a_vclk2_div6_en.hw, [CLKID_VCLK2_DIV12_EN] = &g12a_vclk2_div12_en.hw, [CLKID_VCLK_DIV2] = &g12a_vclk_div2.hw, [CLKID_VCLK_DIV4] = &g12a_vclk_div4.hw, [CLKID_VCLK_DIV6] = &g12a_vclk_div6.hw, [CLKID_VCLK_DIV12] = &g12a_vclk_div12.hw, [CLKID_VCLK2_DIV2] = &g12a_vclk2_div2.hw, [CLKID_VCLK2_DIV4] = &g12a_vclk2_div4.hw, [CLKID_VCLK2_DIV6] = &g12a_vclk2_div6.hw, [CLKID_VCLK2_DIV12] = &g12a_vclk2_div12.hw, [CLKID_CTS_ENCI_SEL] = &g12a_cts_enci_sel.hw, [CLKID_CTS_ENCP_SEL] = &g12a_cts_encp_sel.hw, [CLKID_CTS_VDAC_SEL] = &g12a_cts_vdac_sel.hw, [CLKID_HDMI_TX_SEL] = &g12a_hdmi_tx_sel.hw, [CLKID_CTS_ENCI] = &g12a_cts_enci.hw, [CLKID_CTS_ENCP] = &g12a_cts_encp.hw, [CLKID_CTS_VDAC] = &g12a_cts_vdac.hw, [CLKID_HDMI_TX] = &g12a_hdmi_tx.hw, [CLKID_HDMI_SEL] = &g12a_hdmi_sel.hw, [CLKID_HDMI_DIV] = &g12a_hdmi_div.hw, [CLKID_HDMI] = &g12a_hdmi.hw, [CLKID_MALI_0_SEL] = &g12a_mali_0_sel.hw, [CLKID_MALI_0_DIV] = &g12a_mali_0_div.hw, [CLKID_MALI_0] = &g12a_mali_0.hw, [CLKID_MALI_1_SEL] = &g12a_mali_1_sel.hw, [CLKID_MALI_1_DIV] = &g12a_mali_1_div.hw, [CLKID_MALI_1] = &g12a_mali_1.hw, [CLKID_MALI] = &g12a_mali.hw, [CLKID_MPLL_50M_DIV] = &g12a_mpll_50m_div.hw, [CLKID_MPLL_50M] = &g12a_mpll_50m.hw, [CLKID_SYS_PLL_DIV16_EN] = &g12a_sys_pll_div16_en.hw, [CLKID_SYS_PLL_DIV16] = &g12a_sys_pll_div16.hw, [CLKID_CPU_CLK_DYN0_SEL] = &g12a_cpu_clk_premux0.hw, [CLKID_CPU_CLK_DYN0_DIV] = &g12a_cpu_clk_mux0_div.hw, [CLKID_CPU_CLK_DYN0] = &g12a_cpu_clk_postmux0.hw, [CLKID_CPU_CLK_DYN1_SEL] = &g12a_cpu_clk_premux1.hw, [CLKID_CPU_CLK_DYN1_DIV] = &g12a_cpu_clk_mux1_div.hw, [CLKID_CPU_CLK_DYN1] = &g12a_cpu_clk_postmux1.hw, [CLKID_CPU_CLK_DYN] = &g12a_cpu_clk_dyn.hw, [CLKID_CPU_CLK] = &g12a_cpu_clk.hw, [CLKID_CPU_CLK_DIV16_EN] = &g12a_cpu_clk_div16_en.hw, [CLKID_CPU_CLK_DIV16] = &g12a_cpu_clk_div16.hw, [CLKID_CPU_CLK_APB_DIV] = &g12a_cpu_clk_apb_div.hw, [CLKID_CPU_CLK_APB] = &g12a_cpu_clk_apb.hw, [CLKID_CPU_CLK_ATB_DIV] = &g12a_cpu_clk_atb_div.hw, [CLKID_CPU_CLK_ATB] = &g12a_cpu_clk_atb.hw, [CLKID_CPU_CLK_AXI_DIV] = &g12a_cpu_clk_axi_div.hw, [CLKID_CPU_CLK_AXI] = &g12a_cpu_clk_axi.hw, [CLKID_CPU_CLK_TRACE_DIV] = &g12a_cpu_clk_trace_div.hw, [CLKID_CPU_CLK_TRACE] = &g12a_cpu_clk_trace.hw, [CLKID_PCIE_PLL_DCO] = &g12a_pcie_pll_dco.hw, [CLKID_PCIE_PLL_DCO_DIV2] = &g12a_pcie_pll_dco_div2.hw, [CLKID_PCIE_PLL_OD] = &g12a_pcie_pll_od.hw, [CLKID_PCIE_PLL] = &g12a_pcie_pll.hw, [CLKID_VDEC_1_SEL] = &g12a_vdec_1_sel.hw, [CLKID_VDEC_1_DIV] = &g12a_vdec_1_div.hw, [CLKID_VDEC_1] = &g12a_vdec_1.hw, [CLKID_VDEC_HEVC_SEL] = &g12a_vdec_hevc_sel.hw, [CLKID_VDEC_HEVC_DIV] = &g12a_vdec_hevc_div.hw, [CLKID_VDEC_HEVC] = &g12a_vdec_hevc.hw, [CLKID_VDEC_HEVCF_SEL] = &g12a_vdec_hevcf_sel.hw, [CLKID_VDEC_HEVCF_DIV] = &g12a_vdec_hevcf_div.hw, [CLKID_VDEC_HEVCF] = &g12a_vdec_hevcf.hw, [CLKID_TS_DIV] = &g12a_ts_div.hw, [CLKID_TS] = &g12a_ts.hw, [CLKID_SPICC0_SCLK_SEL] = &g12a_spicc0_sclk_sel.hw, [CLKID_SPICC0_SCLK_DIV] = &g12a_spicc0_sclk_div.hw, [CLKID_SPICC0_SCLK] = &g12a_spicc0_sclk.hw, [CLKID_SPICC1_SCLK_SEL] = &g12a_spicc1_sclk_sel.hw, [CLKID_SPICC1_SCLK_DIV] = &g12a_spicc1_sclk_div.hw, [CLKID_SPICC1_SCLK] = &g12a_spicc1_sclk.hw, [CLKID_MIPI_DSI_PXCLK_SEL] = &g12a_mipi_dsi_pxclk_sel.hw, [CLKID_MIPI_DSI_PXCLK_DIV] = &g12a_mipi_dsi_pxclk_div.hw, [CLKID_MIPI_DSI_PXCLK] = &g12a_mipi_dsi_pxclk.hw, }; static struct clk_hw *g12b_hw_clks[] = { [CLKID_SYS_PLL] = &g12a_sys_pll.hw, [CLKID_FIXED_PLL] = &g12a_fixed_pll.hw, [CLKID_FCLK_DIV2] = &g12a_fclk_div2.hw, [CLKID_FCLK_DIV3] = &g12a_fclk_div3.hw, [CLKID_FCLK_DIV4] = &g12a_fclk_div4.hw, [CLKID_FCLK_DIV5] = &g12a_fclk_div5.hw, [CLKID_FCLK_DIV7] = &g12a_fclk_div7.hw, [CLKID_FCLK_DIV2P5] = &g12a_fclk_div2p5.hw, [CLKID_GP0_PLL] = &g12a_gp0_pll.hw, [CLKID_MPEG_SEL] = &g12a_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &g12a_mpeg_clk_div.hw, [CLKID_CLK81] = &g12a_clk81.hw, [CLKID_MPLL0] = &g12a_mpll0.hw, [CLKID_MPLL1] = &g12a_mpll1.hw, [CLKID_MPLL2] = &g12a_mpll2.hw, [CLKID_MPLL3] = &g12a_mpll3.hw, [CLKID_DDR] = &g12a_ddr.hw, [CLKID_DOS] = &g12a_dos.hw, [CLKID_AUDIO_LOCKER] = &g12a_audio_locker.hw, [CLKID_MIPI_DSI_HOST] = &g12a_mipi_dsi_host.hw, [CLKID_ETH_PHY] = &g12a_eth_phy.hw, [CLKID_ISA] = &g12a_isa.hw, [CLKID_PL301] = &g12a_pl301.hw, [CLKID_PERIPHS] = &g12a_periphs.hw, [CLKID_SPICC0] = &g12a_spicc_0.hw, [CLKID_I2C] = &g12a_i2c.hw, [CLKID_SANA] = &g12a_sana.hw, [CLKID_SD] = &g12a_sd.hw, [CLKID_RNG0] = &g12a_rng0.hw, [CLKID_UART0] = &g12a_uart0.hw, [CLKID_SPICC1] = &g12a_spicc_1.hw, [CLKID_HIU_IFACE] = &g12a_hiu_reg.hw, [CLKID_MIPI_DSI_PHY] = &g12a_mipi_dsi_phy.hw, [CLKID_ASSIST_MISC] = &g12a_assist_misc.hw, [CLKID_SD_EMMC_A] = &g12a_emmc_a.hw, [CLKID_SD_EMMC_B] = &g12a_emmc_b.hw, [CLKID_SD_EMMC_C] = &g12a_emmc_c.hw, [CLKID_AUDIO_CODEC] = &g12a_audio_codec.hw, [CLKID_AUDIO] = &g12a_audio.hw, [CLKID_ETH] = &g12a_eth_core.hw, [CLKID_DEMUX] = &g12a_demux.hw, [CLKID_AUDIO_IFIFO] = &g12a_audio_ififo.hw, [CLKID_ADC] = &g12a_adc.hw, [CLKID_UART1] = &g12a_uart1.hw, [CLKID_G2D] = &g12a_g2d.hw, [CLKID_RESET] = &g12a_reset.hw, [CLKID_PCIE_COMB] = &g12a_pcie_comb.hw, [CLKID_PARSER] = &g12a_parser.hw, [CLKID_USB] = &g12a_usb_general.hw, [CLKID_PCIE_PHY] = &g12a_pcie_phy.hw, [CLKID_AHB_ARB0] = &g12a_ahb_arb0.hw, [CLKID_AHB_DATA_BUS] = &g12a_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &g12a_ahb_ctrl_bus.hw, [CLKID_HTX_HDCP22] = &g12a_htx_hdcp22.hw, [CLKID_HTX_PCLK] = &g12a_htx_pclk.hw, [CLKID_BT656] = &g12a_bt656.hw, [CLKID_USB1_DDR_BRIDGE] = &g12a_usb1_to_ddr.hw, [CLKID_MMC_PCLK] = &g12a_mmc_pclk.hw, [CLKID_UART2] = &g12a_uart2.hw, [CLKID_VPU_INTR] = &g12a_vpu_intr.hw, [CLKID_GIC] = &g12a_gic.hw, [CLKID_SD_EMMC_A_CLK0_SEL] = &g12a_sd_emmc_a_clk0_sel.hw, [CLKID_SD_EMMC_A_CLK0_DIV] = &g12a_sd_emmc_a_clk0_div.hw, [CLKID_SD_EMMC_A_CLK0] = &g12a_sd_emmc_a_clk0.hw, [CLKID_SD_EMMC_B_CLK0_SEL] = &g12a_sd_emmc_b_clk0_sel.hw, [CLKID_SD_EMMC_B_CLK0_DIV] = &g12a_sd_emmc_b_clk0_div.hw, [CLKID_SD_EMMC_B_CLK0] = &g12a_sd_emmc_b_clk0.hw, [CLKID_SD_EMMC_C_CLK0_SEL] = &g12a_sd_emmc_c_clk0_sel.hw, [CLKID_SD_EMMC_C_CLK0_DIV] = &g12a_sd_emmc_c_clk0_div.hw, [CLKID_SD_EMMC_C_CLK0] = &g12a_sd_emmc_c_clk0.hw, [CLKID_MPLL0_DIV] = &g12a_mpll0_div.hw, [CLKID_MPLL1_DIV] = &g12a_mpll1_div.hw, [CLKID_MPLL2_DIV] = &g12a_mpll2_div.hw, [CLKID_MPLL3_DIV] = &g12a_mpll3_div.hw, [CLKID_FCLK_DIV2_DIV] = &g12a_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &g12a_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &g12a_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &g12a_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &g12a_fclk_div7_div.hw, [CLKID_FCLK_DIV2P5_DIV] = &g12a_fclk_div2p5_div.hw, [CLKID_HIFI_PLL] = &g12a_hifi_pll.hw, [CLKID_VCLK2_VENCI0] = &g12a_vclk2_venci0.hw, [CLKID_VCLK2_VENCI1] = &g12a_vclk2_venci1.hw, [CLKID_VCLK2_VENCP0] = &g12a_vclk2_vencp0.hw, [CLKID_VCLK2_VENCP1] = &g12a_vclk2_vencp1.hw, [CLKID_VCLK2_VENCT0] = &g12a_vclk2_venct0.hw, [CLKID_VCLK2_VENCT1] = &g12a_vclk2_venct1.hw, [CLKID_VCLK2_OTHER] = &g12a_vclk2_other.hw, [CLKID_VCLK2_ENCI] = &g12a_vclk2_enci.hw, [CLKID_VCLK2_ENCP] = &g12a_vclk2_encp.hw, [CLKID_DAC_CLK] = &g12a_dac_clk.hw, [CLKID_AOCLK] = &g12a_aoclk_gate.hw, [CLKID_IEC958] = &g12a_iec958_gate.hw, [CLKID_ENC480P] = &g12a_enc480p.hw, [CLKID_RNG1] = &g12a_rng1.hw, [CLKID_VCLK2_ENCT] = &g12a_vclk2_enct.hw, [CLKID_VCLK2_ENCL] = &g12a_vclk2_encl.hw, [CLKID_VCLK2_VENCLMMC] = &g12a_vclk2_venclmmc.hw, [CLKID_VCLK2_VENCL] = &g12a_vclk2_vencl.hw, [CLKID_VCLK2_OTHER1] = &g12a_vclk2_other1.hw, [CLKID_FIXED_PLL_DCO] = &g12a_fixed_pll_dco.hw, [CLKID_SYS_PLL_DCO] = &g12a_sys_pll_dco.hw, [CLKID_GP0_PLL_DCO] = &g12a_gp0_pll_dco.hw, [CLKID_HIFI_PLL_DCO] = &g12a_hifi_pll_dco.hw, [CLKID_DMA] = &g12a_dma.hw, [CLKID_EFUSE] = &g12a_efuse.hw, [CLKID_ROM_BOOT] = &g12a_rom_boot.hw, [CLKID_RESET_SEC] = &g12a_reset_sec.hw, [CLKID_SEC_AHB_APB3] = &g12a_sec_ahb_apb3.hw, [CLKID_MPLL_PREDIV] = &g12a_mpll_prediv.hw, [CLKID_VPU_0_SEL] = &g12a_vpu_0_sel.hw, [CLKID_VPU_0_DIV] = &g12a_vpu_0_div.hw, [CLKID_VPU_0] = &g12a_vpu_0.hw, [CLKID_VPU_1_SEL] = &g12a_vpu_1_sel.hw, [CLKID_VPU_1_DIV] = &g12a_vpu_1_div.hw, [CLKID_VPU_1] = &g12a_vpu_1.hw, [CLKID_VPU] = &g12a_vpu.hw, [CLKID_VAPB_0_SEL] = &g12a_vapb_0_sel.hw, [CLKID_VAPB_0_DIV] = &g12a_vapb_0_div.hw, [CLKID_VAPB_0] = &g12a_vapb_0.hw, [CLKID_VAPB_1_SEL] = &g12a_vapb_1_sel.hw, [CLKID_VAPB_1_DIV] = &g12a_vapb_1_div.hw, [CLKID_VAPB_1] = &g12a_vapb_1.hw, [CLKID_VAPB_SEL] = &g12a_vapb_sel.hw, [CLKID_VAPB] = &g12a_vapb.hw, [CLKID_HDMI_PLL_DCO] = &g12a_hdmi_pll_dco.hw, [CLKID_HDMI_PLL_OD] = &g12a_hdmi_pll_od.hw, [CLKID_HDMI_PLL_OD2] = &g12a_hdmi_pll_od2.hw, [CLKID_HDMI_PLL] = &g12a_hdmi_pll.hw, [CLKID_VID_PLL] = &g12a_vid_pll_div.hw, [CLKID_VID_PLL_SEL] = &g12a_vid_pll_sel.hw, [CLKID_VID_PLL_DIV] = &g12a_vid_pll.hw, [CLKID_VCLK_SEL] = &g12a_vclk_sel.hw, [CLKID_VCLK2_SEL] = &g12a_vclk2_sel.hw, [CLKID_VCLK_INPUT] = &g12a_vclk_input.hw, [CLKID_VCLK2_INPUT] = &g12a_vclk2_input.hw, [CLKID_VCLK_DIV] = &g12a_vclk_div.hw, [CLKID_VCLK2_DIV] = &g12a_vclk2_div.hw, [CLKID_VCLK] = &g12a_vclk.hw, [CLKID_VCLK2] = &g12a_vclk2.hw, [CLKID_VCLK_DIV1] = &g12a_vclk_div1.hw, [CLKID_VCLK_DIV2_EN] = &g12a_vclk_div2_en.hw, [CLKID_VCLK_DIV4_EN] = &g12a_vclk_div4_en.hw, [CLKID_VCLK_DIV6_EN] = &g12a_vclk_div6_en.hw, [CLKID_VCLK_DIV12_EN] = &g12a_vclk_div12_en.hw, [CLKID_VCLK2_DIV1] = &g12a_vclk2_div1.hw, [CLKID_VCLK2_DIV2_EN] = &g12a_vclk2_div2_en.hw, [CLKID_VCLK2_DIV4_EN] = &g12a_vclk2_div4_en.hw, [CLKID_VCLK2_DIV6_EN] = &g12a_vclk2_div6_en.hw, [CLKID_VCLK2_DIV12_EN] = &g12a_vclk2_div12_en.hw, [CLKID_VCLK_DIV2] = &g12a_vclk_div2.hw, [CLKID_VCLK_DIV4] = &g12a_vclk_div4.hw, [CLKID_VCLK_DIV6] = &g12a_vclk_div6.hw, [CLKID_VCLK_DIV12] = &g12a_vclk_div12.hw, [CLKID_VCLK2_DIV2] = &g12a_vclk2_div2.hw, [CLKID_VCLK2_DIV4] = &g12a_vclk2_div4.hw, [CLKID_VCLK2_DIV6] = &g12a_vclk2_div6.hw, [CLKID_VCLK2_DIV12] = &g12a_vclk2_div12.hw, [CLKID_CTS_ENCI_SEL] = &g12a_cts_enci_sel.hw, [CLKID_CTS_ENCP_SEL] = &g12a_cts_encp_sel.hw, [CLKID_CTS_VDAC_SEL] = &g12a_cts_vdac_sel.hw, [CLKID_HDMI_TX_SEL] = &g12a_hdmi_tx_sel.hw, [CLKID_CTS_ENCI] = &g12a_cts_enci.hw, [CLKID_CTS_ENCP] = &g12a_cts_encp.hw, [CLKID_CTS_VDAC] = &g12a_cts_vdac.hw, [CLKID_HDMI_TX] = &g12a_hdmi_tx.hw, [CLKID_HDMI_SEL] = &g12a_hdmi_sel.hw, [CLKID_HDMI_DIV] = &g12a_hdmi_div.hw, [CLKID_HDMI] = &g12a_hdmi.hw, [CLKID_MALI_0_SEL] = &g12a_mali_0_sel.hw, [CLKID_MALI_0_DIV] = &g12a_mali_0_div.hw, [CLKID_MALI_0] = &g12a_mali_0.hw, [CLKID_MALI_1_SEL] = &g12a_mali_1_sel.hw, [CLKID_MALI_1_DIV] = &g12a_mali_1_div.hw, [CLKID_MALI_1] = &g12a_mali_1.hw, [CLKID_MALI] = &g12a_mali.hw, [CLKID_MPLL_50M_DIV] = &g12a_mpll_50m_div.hw, [CLKID_MPLL_50M] = &g12a_mpll_50m.hw, [CLKID_SYS_PLL_DIV16_EN] = &g12a_sys_pll_div16_en.hw, [CLKID_SYS_PLL_DIV16] = &g12a_sys_pll_div16.hw, [CLKID_CPU_CLK_DYN0_SEL] = &g12a_cpu_clk_premux0.hw, [CLKID_CPU_CLK_DYN0_DIV] = &g12a_cpu_clk_mux0_div.hw, [CLKID_CPU_CLK_DYN0] = &g12a_cpu_clk_postmux0.hw, [CLKID_CPU_CLK_DYN1_SEL] = &g12a_cpu_clk_premux1.hw, [CLKID_CPU_CLK_DYN1_DIV] = &g12a_cpu_clk_mux1_div.hw, [CLKID_CPU_CLK_DYN1] = &g12a_cpu_clk_postmux1.hw, [CLKID_CPU_CLK_DYN] = &g12a_cpu_clk_dyn.hw, [CLKID_CPU_CLK] = &g12b_cpu_clk.hw, [CLKID_CPU_CLK_DIV16_EN] = &g12a_cpu_clk_div16_en.hw, [CLKID_CPU_CLK_DIV16] = &g12a_cpu_clk_div16.hw, [CLKID_CPU_CLK_APB_DIV] = &g12a_cpu_clk_apb_div.hw, [CLKID_CPU_CLK_APB] = &g12a_cpu_clk_apb.hw, [CLKID_CPU_CLK_ATB_DIV] = &g12a_cpu_clk_atb_div.hw, [CLKID_CPU_CLK_ATB] = &g12a_cpu_clk_atb.hw, [CLKID_CPU_CLK_AXI_DIV] = &g12a_cpu_clk_axi_div.hw, [CLKID_CPU_CLK_AXI] = &g12a_cpu_clk_axi.hw, [CLKID_CPU_CLK_TRACE_DIV] = &g12a_cpu_clk_trace_div.hw, [CLKID_CPU_CLK_TRACE] = &g12a_cpu_clk_trace.hw, [CLKID_PCIE_PLL_DCO] = &g12a_pcie_pll_dco.hw, [CLKID_PCIE_PLL_DCO_DIV2] = &g12a_pcie_pll_dco_div2.hw, [CLKID_PCIE_PLL_OD] = &g12a_pcie_pll_od.hw, [CLKID_PCIE_PLL] = &g12a_pcie_pll.hw, [CLKID_VDEC_1_SEL] = &g12a_vdec_1_sel.hw, [CLKID_VDEC_1_DIV] = &g12a_vdec_1_div.hw, [CLKID_VDEC_1] = &g12a_vdec_1.hw, [CLKID_VDEC_HEVC_SEL] = &g12a_vdec_hevc_sel.hw, [CLKID_VDEC_HEVC_DIV] = &g12a_vdec_hevc_div.hw, [CLKID_VDEC_HEVC] = &g12a_vdec_hevc.hw, [CLKID_VDEC_HEVCF_SEL] = &g12a_vdec_hevcf_sel.hw, [CLKID_VDEC_HEVCF_DIV] = &g12a_vdec_hevcf_div.hw, [CLKID_VDEC_HEVCF] = &g12a_vdec_hevcf.hw, [CLKID_TS_DIV] = &g12a_ts_div.hw, [CLKID_TS] = &g12a_ts.hw, [CLKID_SYS1_PLL_DCO] = &g12b_sys1_pll_dco.hw, [CLKID_SYS1_PLL] = &g12b_sys1_pll.hw, [CLKID_SYS1_PLL_DIV16_EN] = &g12b_sys1_pll_div16_en.hw, [CLKID_SYS1_PLL_DIV16] = &g12b_sys1_pll_div16.hw, [CLKID_CPUB_CLK_DYN0_SEL] = &g12b_cpub_clk_premux0.hw, [CLKID_CPUB_CLK_DYN0_DIV] = &g12b_cpub_clk_mux0_div.hw, [CLKID_CPUB_CLK_DYN0] = &g12b_cpub_clk_postmux0.hw, [CLKID_CPUB_CLK_DYN1_SEL] = &g12b_cpub_clk_premux1.hw, [CLKID_CPUB_CLK_DYN1_DIV] = &g12b_cpub_clk_mux1_div.hw, [CLKID_CPUB_CLK_DYN1] = &g12b_cpub_clk_postmux1.hw, [CLKID_CPUB_CLK_DYN] = &g12b_cpub_clk_dyn.hw, [CLKID_CPUB_CLK] = &g12b_cpub_clk.hw, [CLKID_CPUB_CLK_DIV16_EN] = &g12b_cpub_clk_div16_en.hw, [CLKID_CPUB_CLK_DIV16] = &g12b_cpub_clk_div16.hw, [CLKID_CPUB_CLK_DIV2] = &g12b_cpub_clk_div2.hw, [CLKID_CPUB_CLK_DIV3] = &g12b_cpub_clk_div3.hw, [CLKID_CPUB_CLK_DIV4] = &g12b_cpub_clk_div4.hw, [CLKID_CPUB_CLK_DIV5] = &g12b_cpub_clk_div5.hw, [CLKID_CPUB_CLK_DIV6] = &g12b_cpub_clk_div6.hw, [CLKID_CPUB_CLK_DIV7] = &g12b_cpub_clk_div7.hw, [CLKID_CPUB_CLK_DIV8] = &g12b_cpub_clk_div8.hw, [CLKID_CPUB_CLK_APB_SEL] = &g12b_cpub_clk_apb_sel.hw, [CLKID_CPUB_CLK_APB] = &g12b_cpub_clk_apb.hw, [CLKID_CPUB_CLK_ATB_SEL] = &g12b_cpub_clk_atb_sel.hw, [CLKID_CPUB_CLK_ATB] = &g12b_cpub_clk_atb.hw, [CLKID_CPUB_CLK_AXI_SEL] = &g12b_cpub_clk_axi_sel.hw, [CLKID_CPUB_CLK_AXI] = &g12b_cpub_clk_axi.hw, [CLKID_CPUB_CLK_TRACE_SEL] = &g12b_cpub_clk_trace_sel.hw, [CLKID_CPUB_CLK_TRACE] = &g12b_cpub_clk_trace.hw, [CLKID_SPICC0_SCLK_SEL] = &g12a_spicc0_sclk_sel.hw, [CLKID_SPICC0_SCLK_DIV] = &g12a_spicc0_sclk_div.hw, [CLKID_SPICC0_SCLK] = &g12a_spicc0_sclk.hw, [CLKID_SPICC1_SCLK_SEL] = &g12a_spicc1_sclk_sel.hw, [CLKID_SPICC1_SCLK_DIV] = &g12a_spicc1_sclk_div.hw, [CLKID_SPICC1_SCLK] = &g12a_spicc1_sclk.hw, [CLKID_NNA_AXI_CLK_SEL] = &sm1_nna_axi_clk_sel.hw, [CLKID_NNA_AXI_CLK_DIV] = &sm1_nna_axi_clk_div.hw, [CLKID_NNA_AXI_CLK] = &sm1_nna_axi_clk.hw, [CLKID_NNA_CORE_CLK_SEL] = &sm1_nna_core_clk_sel.hw, [CLKID_NNA_CORE_CLK_DIV] = &sm1_nna_core_clk_div.hw, [CLKID_NNA_CORE_CLK] = &sm1_nna_core_clk.hw, [CLKID_MIPI_DSI_PXCLK_SEL] = &g12a_mipi_dsi_pxclk_sel.hw, [CLKID_MIPI_DSI_PXCLK_DIV] = &g12a_mipi_dsi_pxclk_div.hw, [CLKID_MIPI_DSI_PXCLK] = &g12a_mipi_dsi_pxclk.hw, }; static struct clk_hw *sm1_hw_clks[] = { [CLKID_SYS_PLL] = &g12a_sys_pll.hw, [CLKID_FIXED_PLL] = &g12a_fixed_pll.hw, [CLKID_FCLK_DIV2] = &g12a_fclk_div2.hw, [CLKID_FCLK_DIV3] = &g12a_fclk_div3.hw, [CLKID_FCLK_DIV4] = &g12a_fclk_div4.hw, [CLKID_FCLK_DIV5] = &g12a_fclk_div5.hw, [CLKID_FCLK_DIV7] = &g12a_fclk_div7.hw, [CLKID_FCLK_DIV2P5] = &g12a_fclk_div2p5.hw, [CLKID_GP0_PLL] = &g12a_gp0_pll.hw, [CLKID_MPEG_SEL] = &g12a_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &g12a_mpeg_clk_div.hw, [CLKID_CLK81] = &g12a_clk81.hw, [CLKID_MPLL0] = &g12a_mpll0.hw, [CLKID_MPLL1] = &g12a_mpll1.hw, [CLKID_MPLL2] = &g12a_mpll2.hw, [CLKID_MPLL3] = &g12a_mpll3.hw, [CLKID_DDR] = &g12a_ddr.hw, [CLKID_DOS] = &g12a_dos.hw, [CLKID_AUDIO_LOCKER] = &g12a_audio_locker.hw, [CLKID_MIPI_DSI_HOST] = &g12a_mipi_dsi_host.hw, [CLKID_ETH_PHY] = &g12a_eth_phy.hw, [CLKID_ISA] = &g12a_isa.hw, [CLKID_PL301] = &g12a_pl301.hw, [CLKID_PERIPHS] = &g12a_periphs.hw, [CLKID_SPICC0] = &g12a_spicc_0.hw, [CLKID_I2C] = &g12a_i2c.hw, [CLKID_SANA] = &g12a_sana.hw, [CLKID_SD] = &g12a_sd.hw, [CLKID_RNG0] = &g12a_rng0.hw, [CLKID_UART0] = &g12a_uart0.hw, [CLKID_SPICC1] = &g12a_spicc_1.hw, [CLKID_HIU_IFACE] = &g12a_hiu_reg.hw, [CLKID_MIPI_DSI_PHY] = &g12a_mipi_dsi_phy.hw, [CLKID_ASSIST_MISC] = &g12a_assist_misc.hw, [CLKID_SD_EMMC_A] = &g12a_emmc_a.hw, [CLKID_SD_EMMC_B] = &g12a_emmc_b.hw, [CLKID_SD_EMMC_C] = &g12a_emmc_c.hw, [CLKID_AUDIO_CODEC] = &g12a_audio_codec.hw, [CLKID_AUDIO] = &g12a_audio.hw, [CLKID_ETH] = &g12a_eth_core.hw, [CLKID_DEMUX] = &g12a_demux.hw, [CLKID_AUDIO_IFIFO] = &g12a_audio_ififo.hw, [CLKID_ADC] = &g12a_adc.hw, [CLKID_UART1] = &g12a_uart1.hw, [CLKID_G2D] = &g12a_g2d.hw, [CLKID_RESET] = &g12a_reset.hw, [CLKID_PCIE_COMB] = &g12a_pcie_comb.hw, [CLKID_PARSER] = &g12a_parser.hw, [CLKID_USB] = &g12a_usb_general.hw, [CLKID_PCIE_PHY] = &g12a_pcie_phy.hw, [CLKID_AHB_ARB0] = &g12a_ahb_arb0.hw, [CLKID_AHB_DATA_BUS] = &g12a_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &g12a_ahb_ctrl_bus.hw, [CLKID_HTX_HDCP22] = &g12a_htx_hdcp22.hw, [CLKID_HTX_PCLK] = &g12a_htx_pclk.hw, [CLKID_BT656] = &g12a_bt656.hw, [CLKID_USB1_DDR_BRIDGE] = &g12a_usb1_to_ddr.hw, [CLKID_MMC_PCLK] = &g12a_mmc_pclk.hw, [CLKID_UART2] = &g12a_uart2.hw, [CLKID_VPU_INTR] = &g12a_vpu_intr.hw, [CLKID_GIC] = &g12a_gic.hw, [CLKID_SD_EMMC_A_CLK0_SEL] = &g12a_sd_emmc_a_clk0_sel.hw, [CLKID_SD_EMMC_A_CLK0_DIV] = &g12a_sd_emmc_a_clk0_div.hw, [CLKID_SD_EMMC_A_CLK0] = &g12a_sd_emmc_a_clk0.hw, [CLKID_SD_EMMC_B_CLK0_SEL] = &g12a_sd_emmc_b_clk0_sel.hw, [CLKID_SD_EMMC_B_CLK0_DIV] = &g12a_sd_emmc_b_clk0_div.hw, [CLKID_SD_EMMC_B_CLK0] = &g12a_sd_emmc_b_clk0.hw, [CLKID_SD_EMMC_C_CLK0_SEL] = &g12a_sd_emmc_c_clk0_sel.hw, [CLKID_SD_EMMC_C_CLK0_DIV] = &g12a_sd_emmc_c_clk0_div.hw, [CLKID_SD_EMMC_C_CLK0] = &g12a_sd_emmc_c_clk0.hw, [CLKID_MPLL0_DIV] = &g12a_mpll0_div.hw, [CLKID_MPLL1_DIV] = &g12a_mpll1_div.hw, [CLKID_MPLL2_DIV] = &g12a_mpll2_div.hw, [CLKID_MPLL3_DIV] = &g12a_mpll3_div.hw, [CLKID_FCLK_DIV2_DIV] = &g12a_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &g12a_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &g12a_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &g12a_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &g12a_fclk_div7_div.hw, [CLKID_FCLK_DIV2P5_DIV] = &g12a_fclk_div2p5_div.hw, [CLKID_HIFI_PLL] = &g12a_hifi_pll.hw, [CLKID_VCLK2_VENCI0] = &g12a_vclk2_venci0.hw, [CLKID_VCLK2_VENCI1] = &g12a_vclk2_venci1.hw, [CLKID_VCLK2_VENCP0] = &g12a_vclk2_vencp0.hw, [CLKID_VCLK2_VENCP1] = &g12a_vclk2_vencp1.hw, [CLKID_VCLK2_VENCT0] = &g12a_vclk2_venct0.hw, [CLKID_VCLK2_VENCT1] = &g12a_vclk2_venct1.hw, [CLKID_VCLK2_OTHER] = &g12a_vclk2_other.hw, [CLKID_VCLK2_ENCI] = &g12a_vclk2_enci.hw, [CLKID_VCLK2_ENCP] = &g12a_vclk2_encp.hw, [CLKID_DAC_CLK] = &g12a_dac_clk.hw, [CLKID_AOCLK] = &g12a_aoclk_gate.hw, [CLKID_IEC958] = &g12a_iec958_gate.hw, [CLKID_ENC480P] = &g12a_enc480p.hw, [CLKID_RNG1] = &g12a_rng1.hw, [CLKID_VCLK2_ENCT] = &g12a_vclk2_enct.hw, [CLKID_VCLK2_ENCL] = &g12a_vclk2_encl.hw, [CLKID_VCLK2_VENCLMMC] = &g12a_vclk2_venclmmc.hw, [CLKID_VCLK2_VENCL] = &g12a_vclk2_vencl.hw, [CLKID_VCLK2_OTHER1] = &g12a_vclk2_other1.hw, [CLKID_FIXED_PLL_DCO] = &g12a_fixed_pll_dco.hw, [CLKID_SYS_PLL_DCO] = &g12a_sys_pll_dco.hw, [CLKID_GP0_PLL_DCO] = &g12a_gp0_pll_dco.hw, [CLKID_HIFI_PLL_DCO] = &g12a_hifi_pll_dco.hw, [CLKID_DMA] = &g12a_dma.hw, [CLKID_EFUSE] = &g12a_efuse.hw, [CLKID_ROM_BOOT] = &g12a_rom_boot.hw, [CLKID_RESET_SEC] = &g12a_reset_sec.hw, [CLKID_SEC_AHB_APB3] = &g12a_sec_ahb_apb3.hw, [CLKID_MPLL_PREDIV] = &g12a_mpll_prediv.hw, [CLKID_VPU_0_SEL] = &g12a_vpu_0_sel.hw, [CLKID_VPU_0_DIV] = &g12a_vpu_0_div.hw, [CLKID_VPU_0] = &g12a_vpu_0.hw, [CLKID_VPU_1_SEL] = &g12a_vpu_1_sel.hw, [CLKID_VPU_1_DIV] = &g12a_vpu_1_div.hw, [CLKID_VPU_1] = &g12a_vpu_1.hw, [CLKID_VPU] = &g12a_vpu.hw, [CLKID_VAPB_0_SEL] = &g12a_vapb_0_sel.hw, [CLKID_VAPB_0_DIV] = &g12a_vapb_0_div.hw, [CLKID_VAPB_0] = &g12a_vapb_0.hw, [CLKID_VAPB_1_SEL] = &g12a_vapb_1_sel.hw, [CLKID_VAPB_1_DIV] = &g12a_vapb_1_div.hw, [CLKID_VAPB_1] = &g12a_vapb_1.hw, [CLKID_VAPB_SEL] = &g12a_vapb_sel.hw, [CLKID_VAPB] = &g12a_vapb.hw, [CLKID_HDMI_PLL_DCO] = &g12a_hdmi_pll_dco.hw, [CLKID_HDMI_PLL_OD] = &g12a_hdmi_pll_od.hw, [CLKID_HDMI_PLL_OD2] = &g12a_hdmi_pll_od2.hw, [CLKID_HDMI_PLL] = &g12a_hdmi_pll.hw, [CLKID_VID_PLL] = &g12a_vid_pll_div.hw, [CLKID_VID_PLL_SEL] = &g12a_vid_pll_sel.hw, [CLKID_VID_PLL_DIV] = &g12a_vid_pll.hw, [CLKID_VCLK_SEL] = &g12a_vclk_sel.hw, [CLKID_VCLK2_SEL] = &g12a_vclk2_sel.hw, [CLKID_VCLK_INPUT] = &g12a_vclk_input.hw, [CLKID_VCLK2_INPUT] = &g12a_vclk2_input.hw, [CLKID_VCLK_DIV] = &g12a_vclk_div.hw, [CLKID_VCLK2_DIV] = &g12a_vclk2_div.hw, [CLKID_VCLK] = &g12a_vclk.hw, [CLKID_VCLK2] = &g12a_vclk2.hw, [CLKID_VCLK_DIV1] = &g12a_vclk_div1.hw, [CLKID_VCLK_DIV2_EN] = &g12a_vclk_div2_en.hw, [CLKID_VCLK_DIV4_EN] = &g12a_vclk_div4_en.hw, [CLKID_VCLK_DIV6_EN] = &g12a_vclk_div6_en.hw, [CLKID_VCLK_DIV12_EN] = &g12a_vclk_div12_en.hw, [CLKID_VCLK2_DIV1] = &g12a_vclk2_div1.hw, [CLKID_VCLK2_DIV2_EN] = &g12a_vclk2_div2_en.hw, [CLKID_VCLK2_DIV4_EN] = &g12a_vclk2_div4_en.hw, [CLKID_VCLK2_DIV6_EN] = &g12a_vclk2_div6_en.hw, [CLKID_VCLK2_DIV12_EN] = &g12a_vclk2_div12_en.hw, [CLKID_VCLK_DIV2] = &g12a_vclk_div2.hw, [CLKID_VCLK_DIV4] = &g12a_vclk_div4.hw, [CLKID_VCLK_DIV6] = &g12a_vclk_div6.hw, [CLKID_VCLK_DIV12] = &g12a_vclk_div12.hw, [CLKID_VCLK2_DIV2] = &g12a_vclk2_div2.hw, [CLKID_VCLK2_DIV4] = &g12a_vclk2_div4.hw, [CLKID_VCLK2_DIV6] = &g12a_vclk2_div6.hw, [CLKID_VCLK2_DIV12] = &g12a_vclk2_div12.hw, [CLKID_CTS_ENCI_SEL] = &g12a_cts_enci_sel.hw, [CLKID_CTS_ENCP_SEL] = &g12a_cts_encp_sel.hw, [CLKID_CTS_VDAC_SEL] = &g12a_cts_vdac_sel.hw, [CLKID_HDMI_TX_SEL] = &g12a_hdmi_tx_sel.hw, [CLKID_CTS_ENCI] = &g12a_cts_enci.hw, [CLKID_CTS_ENCP] = &g12a_cts_encp.hw, [CLKID_CTS_VDAC] = &g12a_cts_vdac.hw, [CLKID_HDMI_TX] = &g12a_hdmi_tx.hw, [CLKID_HDMI_SEL] = &g12a_hdmi_sel.hw, [CLKID_HDMI_DIV] = &g12a_hdmi_div.hw, [CLKID_HDMI] = &g12a_hdmi.hw, [CLKID_MALI_0_SEL] = &g12a_mali_0_sel.hw, [CLKID_MALI_0_DIV] = &g12a_mali_0_div.hw, [CLKID_MALI_0] = &g12a_mali_0.hw, [CLKID_MALI_1_SEL] = &g12a_mali_1_sel.hw, [CLKID_MALI_1_DIV] = &g12a_mali_1_div.hw, [CLKID_MALI_1] = &g12a_mali_1.hw, [CLKID_MALI] = &g12a_mali.hw, [CLKID_MPLL_50M_DIV] = &g12a_mpll_50m_div.hw, [CLKID_MPLL_50M] = &g12a_mpll_50m.hw, [CLKID_SYS_PLL_DIV16_EN] = &g12a_sys_pll_div16_en.hw, [CLKID_SYS_PLL_DIV16] = &g12a_sys_pll_div16.hw, [CLKID_CPU_CLK_DYN0_SEL] = &g12a_cpu_clk_premux0.hw, [CLKID_CPU_CLK_DYN0_DIV] = &g12a_cpu_clk_mux0_div.hw, [CLKID_CPU_CLK_DYN0] = &g12a_cpu_clk_postmux0.hw, [CLKID_CPU_CLK_DYN1_SEL] = &g12a_cpu_clk_premux1.hw, [CLKID_CPU_CLK_DYN1_DIV] = &g12a_cpu_clk_mux1_div.hw, [CLKID_CPU_CLK_DYN1] = &g12a_cpu_clk_postmux1.hw, [CLKID_CPU_CLK_DYN] = &g12a_cpu_clk_dyn.hw, [CLKID_CPU_CLK] = &g12a_cpu_clk.hw, [CLKID_CPU_CLK_DIV16_EN] = &g12a_cpu_clk_div16_en.hw, [CLKID_CPU_CLK_DIV16] = &g12a_cpu_clk_div16.hw, [CLKID_CPU_CLK_APB_DIV] = &g12a_cpu_clk_apb_div.hw, [CLKID_CPU_CLK_APB] = &g12a_cpu_clk_apb.hw, [CLKID_CPU_CLK_ATB_DIV] = &g12a_cpu_clk_atb_div.hw, [CLKID_CPU_CLK_ATB] = &g12a_cpu_clk_atb.hw, [CLKID_CPU_CLK_AXI_DIV] = &g12a_cpu_clk_axi_div.hw, [CLKID_CPU_CLK_AXI] = &g12a_cpu_clk_axi.hw, [CLKID_CPU_CLK_TRACE_DIV] = &g12a_cpu_clk_trace_div.hw, [CLKID_CPU_CLK_TRACE] = &g12a_cpu_clk_trace.hw, [CLKID_PCIE_PLL_DCO] = &g12a_pcie_pll_dco.hw, [CLKID_PCIE_PLL_DCO_DIV2] = &g12a_pcie_pll_dco_div2.hw, [CLKID_PCIE_PLL_OD] = &g12a_pcie_pll_od.hw, [CLKID_PCIE_PLL] = &g12a_pcie_pll.hw, [CLKID_VDEC_1_SEL] = &g12a_vdec_1_sel.hw, [CLKID_VDEC_1_DIV] = &g12a_vdec_1_div.hw, [CLKID_VDEC_1] = &g12a_vdec_1.hw, [CLKID_VDEC_HEVC_SEL] = &g12a_vdec_hevc_sel.hw, [CLKID_VDEC_HEVC_DIV] = &g12a_vdec_hevc_div.hw, [CLKID_VDEC_HEVC] = &g12a_vdec_hevc.hw, [CLKID_VDEC_HEVCF_SEL] = &g12a_vdec_hevcf_sel.hw, [CLKID_VDEC_HEVCF_DIV] = &g12a_vdec_hevcf_div.hw, [CLKID_VDEC_HEVCF] = &g12a_vdec_hevcf.hw, [CLKID_TS_DIV] = &g12a_ts_div.hw, [CLKID_TS] = &g12a_ts.hw, [CLKID_GP1_PLL_DCO] = &sm1_gp1_pll_dco.hw, [CLKID_GP1_PLL] = &sm1_gp1_pll.hw, [CLKID_DSU_CLK_DYN0_SEL] = &sm1_dsu_clk_premux0.hw, [CLKID_DSU_CLK_DYN0_DIV] = &sm1_dsu_clk_premux1.hw, [CLKID_DSU_CLK_DYN0] = &sm1_dsu_clk_mux0_div.hw, [CLKID_DSU_CLK_DYN1_SEL] = &sm1_dsu_clk_postmux0.hw, [CLKID_DSU_CLK_DYN1_DIV] = &sm1_dsu_clk_mux1_div.hw, [CLKID_DSU_CLK_DYN1] = &sm1_dsu_clk_postmux1.hw, [CLKID_DSU_CLK_DYN] = &sm1_dsu_clk_dyn.hw, [CLKID_DSU_CLK_FINAL] = &sm1_dsu_final_clk.hw, [CLKID_DSU_CLK] = &sm1_dsu_clk.hw, [CLKID_CPU1_CLK] = &sm1_cpu1_clk.hw, [CLKID_CPU2_CLK] = &sm1_cpu2_clk.hw, [CLKID_CPU3_CLK] = &sm1_cpu3_clk.hw, [CLKID_SPICC0_SCLK_SEL] = &g12a_spicc0_sclk_sel.hw, [CLKID_SPICC0_SCLK_DIV] = &g12a_spicc0_sclk_div.hw, [CLKID_SPICC0_SCLK] = &g12a_spicc0_sclk.hw, [CLKID_SPICC1_SCLK_SEL] = &g12a_spicc1_sclk_sel.hw, [CLKID_SPICC1_SCLK_DIV] = &g12a_spicc1_sclk_div.hw, [CLKID_SPICC1_SCLK] = &g12a_spicc1_sclk.hw, [CLKID_NNA_AXI_CLK_SEL] = &sm1_nna_axi_clk_sel.hw, [CLKID_NNA_AXI_CLK_DIV] = &sm1_nna_axi_clk_div.hw, [CLKID_NNA_AXI_CLK] = &sm1_nna_axi_clk.hw, [CLKID_NNA_CORE_CLK_SEL] = &sm1_nna_core_clk_sel.hw, [CLKID_NNA_CORE_CLK_DIV] = &sm1_nna_core_clk_div.hw, [CLKID_NNA_CORE_CLK] = &sm1_nna_core_clk.hw, [CLKID_MIPI_DSI_PXCLK_SEL] = &g12a_mipi_dsi_pxclk_sel.hw, [CLKID_MIPI_DSI_PXCLK_DIV] = &g12a_mipi_dsi_pxclk_div.hw, [CLKID_MIPI_DSI_PXCLK] = &g12a_mipi_dsi_pxclk.hw, }; /* Convenience table to populate regmap in .probe */ static struct clk_regmap *const g12a_clk_regmaps[] = { &g12a_clk81, &g12a_dos, &g12a_ddr, &g12a_audio_locker, &g12a_mipi_dsi_host, &g12a_eth_phy, &g12a_isa, &g12a_pl301, &g12a_periphs, &g12a_spicc_0, &g12a_i2c, &g12a_sana, &g12a_sd, &g12a_rng0, &g12a_uart0, &g12a_spicc_1, &g12a_hiu_reg, &g12a_mipi_dsi_phy, &g12a_assist_misc, &g12a_emmc_a, &g12a_emmc_b, &g12a_emmc_c, &g12a_audio_codec, &g12a_audio, &g12a_eth_core, &g12a_demux, &g12a_audio_ififo, &g12a_adc, &g12a_uart1, &g12a_g2d, &g12a_reset, &g12a_pcie_comb, &g12a_parser, &g12a_usb_general, &g12a_pcie_phy, &g12a_ahb_arb0, &g12a_ahb_data_bus, &g12a_ahb_ctrl_bus, &g12a_htx_hdcp22, &g12a_htx_pclk, &g12a_bt656, &g12a_usb1_to_ddr, &g12a_mmc_pclk, &g12a_uart2, &g12a_vpu_intr, &g12a_gic, &g12a_sd_emmc_a_clk0, &g12a_sd_emmc_b_clk0, &g12a_sd_emmc_c_clk0, &g12a_mpeg_clk_div, &g12a_sd_emmc_a_clk0_div, &g12a_sd_emmc_b_clk0_div, &g12a_sd_emmc_c_clk0_div, &g12a_mpeg_clk_sel, &g12a_sd_emmc_a_clk0_sel, &g12a_sd_emmc_b_clk0_sel, &g12a_sd_emmc_c_clk0_sel, &g12a_mpll0, &g12a_mpll1, &g12a_mpll2, &g12a_mpll3, &g12a_mpll0_div, &g12a_mpll1_div, &g12a_mpll2_div, &g12a_mpll3_div, &g12a_fixed_pll, &g12a_sys_pll, &g12a_gp0_pll, &g12a_hifi_pll, &g12a_vclk2_venci0, &g12a_vclk2_venci1, &g12a_vclk2_vencp0, &g12a_vclk2_vencp1, &g12a_vclk2_venct0, &g12a_vclk2_venct1, &g12a_vclk2_other, &g12a_vclk2_enci, &g12a_vclk2_encp, &g12a_dac_clk, &g12a_aoclk_gate, &g12a_iec958_gate, &g12a_enc480p, &g12a_rng1, &g12a_vclk2_enct, &g12a_vclk2_encl, &g12a_vclk2_venclmmc, &g12a_vclk2_vencl, &g12a_vclk2_other1, &g12a_fixed_pll_dco, &g12a_sys_pll_dco, &g12a_gp0_pll_dco, &g12a_hifi_pll_dco, &g12a_fclk_div2, &g12a_fclk_div3, &g12a_fclk_div4, &g12a_fclk_div5, &g12a_fclk_div7, &g12a_fclk_div2p5, &g12a_dma, &g12a_efuse, &g12a_rom_boot, &g12a_reset_sec, &g12a_sec_ahb_apb3, &g12a_vpu_0_sel, &g12a_vpu_0_div, &g12a_vpu_0, &g12a_vpu_1_sel, &g12a_vpu_1_div, &g12a_vpu_1, &g12a_vpu, &g12a_vapb_0_sel, &g12a_vapb_0_div, &g12a_vapb_0, &g12a_vapb_1_sel, &g12a_vapb_1_div, &g12a_vapb_1, &g12a_vapb_sel, &g12a_vapb, &g12a_hdmi_pll_dco, &g12a_hdmi_pll_od, &g12a_hdmi_pll_od2, &g12a_hdmi_pll, &g12a_vid_pll_div, &g12a_vid_pll_sel, &g12a_vid_pll, &g12a_vclk_sel, &g12a_vclk2_sel, &g12a_vclk_input, &g12a_vclk2_input, &g12a_vclk_div, &g12a_vclk2_div, &g12a_vclk, &g12a_vclk2, &g12a_vclk_div1, &g12a_vclk_div2_en, &g12a_vclk_div4_en, &g12a_vclk_div6_en, &g12a_vclk_div12_en, &g12a_vclk2_div1, &g12a_vclk2_div2_en, &g12a_vclk2_div4_en, &g12a_vclk2_div6_en, &g12a_vclk2_div12_en, &g12a_cts_enci_sel, &g12a_cts_encp_sel, &g12a_cts_vdac_sel, &g12a_hdmi_tx_sel, &g12a_cts_enci, &g12a_cts_encp, &g12a_cts_vdac, &g12a_hdmi_tx, &g12a_hdmi_sel, &g12a_hdmi_div, &g12a_hdmi, &g12a_mali_0_sel, &g12a_mali_0_div, &g12a_mali_0, &g12a_mali_1_sel, &g12a_mali_1_div, &g12a_mali_1, &g12a_mali, &g12a_mpll_50m, &g12a_sys_pll_div16_en, &g12a_cpu_clk_premux0, &g12a_cpu_clk_mux0_div, &g12a_cpu_clk_postmux0, &g12a_cpu_clk_premux1, &g12a_cpu_clk_mux1_div, &g12a_cpu_clk_postmux1, &g12a_cpu_clk_dyn, &g12a_cpu_clk, &g12a_cpu_clk_div16_en, &g12a_cpu_clk_apb_div, &g12a_cpu_clk_apb, &g12a_cpu_clk_atb_div, &g12a_cpu_clk_atb, &g12a_cpu_clk_axi_div, &g12a_cpu_clk_axi, &g12a_cpu_clk_trace_div, &g12a_cpu_clk_trace, &g12a_pcie_pll_od, &g12a_pcie_pll_dco, &g12a_vdec_1_sel, &g12a_vdec_1_div, &g12a_vdec_1, &g12a_vdec_hevc_sel, &g12a_vdec_hevc_div, &g12a_vdec_hevc, &g12a_vdec_hevcf_sel, &g12a_vdec_hevcf_div, &g12a_vdec_hevcf, &g12a_ts_div, &g12a_ts, &g12b_cpu_clk, &g12b_sys1_pll_dco, &g12b_sys1_pll, &g12b_sys1_pll_div16_en, &g12b_cpub_clk_premux0, &g12b_cpub_clk_mux0_div, &g12b_cpub_clk_postmux0, &g12b_cpub_clk_premux1, &g12b_cpub_clk_mux1_div, &g12b_cpub_clk_postmux1, &g12b_cpub_clk_dyn, &g12b_cpub_clk, &g12b_cpub_clk_div16_en, &g12b_cpub_clk_apb_sel, &g12b_cpub_clk_apb, &g12b_cpub_clk_atb_sel, &g12b_cpub_clk_atb, &g12b_cpub_clk_axi_sel, &g12b_cpub_clk_axi, &g12b_cpub_clk_trace_sel, &g12b_cpub_clk_trace, &sm1_gp1_pll_dco, &sm1_gp1_pll, &sm1_dsu_clk_premux0, &sm1_dsu_clk_premux1, &sm1_dsu_clk_mux0_div, &sm1_dsu_clk_postmux0, &sm1_dsu_clk_mux1_div, &sm1_dsu_clk_postmux1, &sm1_dsu_clk_dyn, &sm1_dsu_final_clk, &sm1_dsu_clk, &sm1_cpu1_clk, &sm1_cpu2_clk, &sm1_cpu3_clk, &g12a_spicc0_sclk_sel, &g12a_spicc0_sclk_div, &g12a_spicc0_sclk, &g12a_spicc1_sclk_sel, &g12a_spicc1_sclk_div, &g12a_spicc1_sclk, &sm1_nna_axi_clk_sel, &sm1_nna_axi_clk_div, &sm1_nna_axi_clk, &sm1_nna_core_clk_sel, &sm1_nna_core_clk_div, &sm1_nna_core_clk, &g12a_mipi_dsi_pxclk_sel, &g12a_mipi_dsi_pxclk_div, &g12a_mipi_dsi_pxclk, }; static const struct reg_sequence g12a_init_regs[] = { { .reg = HHI_MPLL_CNTL0, .def = 0x00000543 }, }; #define DVFS_CON_ID "dvfs" static int meson_g12a_dvfs_setup_common(struct device *dev, struct clk_hw **hws) { struct clk *notifier_clk; struct clk_hw *xtal; int ret; xtal = clk_hw_get_parent_by_index(hws[CLKID_CPU_CLK_DYN1_SEL], 0); /* Setup clock notifier for cpu_clk_postmux0 */ g12a_cpu_clk_postmux0_nb_data.xtal = xtal; notifier_clk = devm_clk_hw_get_clk(dev, &g12a_cpu_clk_postmux0.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12a_cpu_clk_postmux0_nb_data.nb); if (ret) { dev_err(dev, "failed to register the cpu_clk_postmux0 notifier\n"); return ret; } /* Setup clock notifier for cpu_clk_dyn mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12a_cpu_clk_dyn.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpu_clk_dyn notifier\n"); return ret; } return 0; } static int meson_g12b_dvfs_setup(struct platform_device *pdev) { struct clk_hw **hws = g12b_hw_clks; struct device *dev = &pdev->dev; struct clk *notifier_clk; struct clk_hw *xtal; int ret; ret = meson_g12a_dvfs_setup_common(dev, hws); if (ret) return ret; xtal = clk_hw_get_parent_by_index(hws[CLKID_CPU_CLK_DYN1_SEL], 0); /* Setup clock notifier for cpu_clk mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12b_cpu_clk.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpu_clk notifier\n"); return ret; } /* Setup clock notifier for sys1_pll */ notifier_clk = devm_clk_hw_get_clk(dev, &g12b_sys1_pll.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12b_cpu_clk_sys1_pll_nb_data.nb); if (ret) { dev_err(dev, "failed to register the sys1_pll notifier\n"); return ret; } /* Add notifiers for the second CPU cluster */ /* Setup clock notifier for cpub_clk_postmux0 */ g12b_cpub_clk_postmux0_nb_data.xtal = xtal; notifier_clk = devm_clk_hw_get_clk(dev, &g12b_cpub_clk_postmux0.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12b_cpub_clk_postmux0_nb_data.nb); if (ret) { dev_err(dev, "failed to register the cpub_clk_postmux0 notifier\n"); return ret; } /* Setup clock notifier for cpub_clk_dyn mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12b_cpub_clk_dyn.hw, "dvfs"); ret = devm_clk_notifier_register(dev, notifier_clk, &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpub_clk_dyn notifier\n"); return ret; } /* Setup clock notifier for cpub_clk mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12b_cpub_clk.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpub_clk notifier\n"); return ret; } /* Setup clock notifier for sys_pll */ notifier_clk = devm_clk_hw_get_clk(dev, &g12a_sys_pll.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12b_cpub_clk_sys_pll_nb_data.nb); if (ret) { dev_err(dev, "failed to register the sys_pll notifier\n"); return ret; } return 0; } static int meson_g12a_dvfs_setup(struct platform_device *pdev) { struct clk_hw **hws = g12a_hw_clks; struct device *dev = &pdev->dev; struct clk *notifier_clk; int ret; ret = meson_g12a_dvfs_setup_common(dev, hws); if (ret) return ret; /* Setup clock notifier for cpu_clk mux */ notifier_clk = devm_clk_hw_get_clk(dev, &g12a_cpu_clk.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12a_cpu_clk_mux_nb); if (ret) { dev_err(dev, "failed to register the cpu_clk notifier\n"); return ret; } /* Setup clock notifier for sys_pll */ notifier_clk = devm_clk_hw_get_clk(dev, &g12a_sys_pll.hw, DVFS_CON_ID); ret = devm_clk_notifier_register(dev, notifier_clk, &g12a_sys_pll_nb_data.nb); if (ret) { dev_err(dev, "failed to register the sys_pll notifier\n"); return ret; } return 0; } struct meson_g12a_data { const struct meson_eeclkc_data eeclkc_data; int (*dvfs_setup)(struct platform_device *pdev); }; static int meson_g12a_probe(struct platform_device *pdev) { const struct meson_eeclkc_data *eeclkc_data; const struct meson_g12a_data *g12a_data; int ret; eeclkc_data = of_device_get_match_data(&pdev->dev); if (!eeclkc_data) return -EINVAL; ret = meson_eeclkc_probe(pdev); if (ret) return ret; g12a_data = container_of(eeclkc_data, struct meson_g12a_data, eeclkc_data); if (g12a_data->dvfs_setup) return g12a_data->dvfs_setup(pdev); return 0; } static const struct meson_g12a_data g12a_clkc_data = { .eeclkc_data = { .regmap_clks = g12a_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(g12a_clk_regmaps), .hw_clks = { .hws = g12a_hw_clks, .num = ARRAY_SIZE(g12a_hw_clks), }, .init_regs = g12a_init_regs, .init_count = ARRAY_SIZE(g12a_init_regs), }, .dvfs_setup = meson_g12a_dvfs_setup, }; static const struct meson_g12a_data g12b_clkc_data = { .eeclkc_data = { .regmap_clks = g12a_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(g12a_clk_regmaps), .hw_clks = { .hws = g12b_hw_clks, .num = ARRAY_SIZE(g12b_hw_clks), }, }, .dvfs_setup = meson_g12b_dvfs_setup, }; static const struct meson_g12a_data sm1_clkc_data = { .eeclkc_data = { .regmap_clks = g12a_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(g12a_clk_regmaps), .hw_clks = { .hws = sm1_hw_clks, .num = ARRAY_SIZE(sm1_hw_clks), }, }, .dvfs_setup = meson_g12a_dvfs_setup, }; static const struct of_device_id clkc_match_table[] = { { .compatible = "amlogic,g12a-clkc", .data = &g12a_clkc_data.eeclkc_data }, { .compatible = "amlogic,g12b-clkc", .data = &g12b_clkc_data.eeclkc_data }, { .compatible = "amlogic,sm1-clkc", .data = &sm1_clkc_data.eeclkc_data }, {} }; MODULE_DEVICE_TABLE(of, clkc_match_table); static struct platform_driver g12a_driver = { .probe = meson_g12a_probe, .driver = { .name = "g12a-clkc", .of_match_table = clkc_match_table, }, }; module_platform_driver(g12a_driver); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/g12a.c
// SPDX-License-Identifier: (GPL-2.0 OR MIT) /* * Copyright (c) 2019 BayLibre, SAS. * Author: Neil Armstrong <[email protected]> */ #include <linux/clk-provider.h> #include <linux/module.h> #include "clk-regmap.h" #include "clk-cpu-dyndiv.h" static inline struct meson_clk_cpu_dyndiv_data * meson_clk_cpu_dyndiv_data(struct clk_regmap *clk) { return (struct meson_clk_cpu_dyndiv_data *)clk->data; } static unsigned long meson_clk_cpu_dyndiv_recalc_rate(struct clk_hw *hw, unsigned long prate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_cpu_dyndiv_data *data = meson_clk_cpu_dyndiv_data(clk); return divider_recalc_rate(hw, prate, meson_parm_read(clk->map, &data->div), NULL, 0, data->div.width); } static int meson_clk_cpu_dyndiv_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_cpu_dyndiv_data *data = meson_clk_cpu_dyndiv_data(clk); return divider_determine_rate(hw, req, NULL, data->div.width, 0); } static int meson_clk_cpu_dyndiv_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_cpu_dyndiv_data *data = meson_clk_cpu_dyndiv_data(clk); unsigned int val; int ret; ret = divider_get_val(rate, parent_rate, NULL, data->div.width, 0); if (ret < 0) return ret; val = (unsigned int)ret << data->div.shift; /* Write the SYS_CPU_DYN_ENABLE bit before changing the divider */ meson_parm_write(clk->map, &data->dyn, 1); /* Update the divider while removing the SYS_CPU_DYN_ENABLE bit */ return regmap_update_bits(clk->map, data->div.reg_off, SETPMASK(data->div.width, data->div.shift) | SETPMASK(data->dyn.width, data->dyn.shift), val); }; const struct clk_ops meson_clk_cpu_dyndiv_ops = { .recalc_rate = meson_clk_cpu_dyndiv_recalc_rate, .determine_rate = meson_clk_cpu_dyndiv_determine_rate, .set_rate = meson_clk_cpu_dyndiv_set_rate, }; EXPORT_SYMBOL_GPL(meson_clk_cpu_dyndiv_ops); MODULE_DESCRIPTION("Amlogic CPU Dynamic Clock divider"); MODULE_AUTHOR("Neil Armstrong <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/clk-cpu-dyndiv.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2016 AmLogic, Inc. * Michael Turquette <[email protected]> */ #include <linux/clk-provider.h> #include <linux/init.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include <linux/module.h> #include "gxbb.h" #include "clk-regmap.h" #include "clk-pll.h" #include "clk-mpll.h" #include "meson-eeclk.h" #include "vid-pll-div.h" #include <dt-bindings/clock/gxbb-clkc.h> static DEFINE_SPINLOCK(meson_clk_lock); static const struct pll_params_table gxbb_gp0_pll_params_table[] = { PLL_PARAMS(32, 1), PLL_PARAMS(33, 1), PLL_PARAMS(34, 1), PLL_PARAMS(35, 1), PLL_PARAMS(36, 1), PLL_PARAMS(37, 1), PLL_PARAMS(38, 1), PLL_PARAMS(39, 1), PLL_PARAMS(40, 1), PLL_PARAMS(41, 1), PLL_PARAMS(42, 1), PLL_PARAMS(43, 1), PLL_PARAMS(44, 1), PLL_PARAMS(45, 1), PLL_PARAMS(46, 1), PLL_PARAMS(47, 1), PLL_PARAMS(48, 1), PLL_PARAMS(49, 1), PLL_PARAMS(50, 1), PLL_PARAMS(51, 1), PLL_PARAMS(52, 1), PLL_PARAMS(53, 1), PLL_PARAMS(54, 1), PLL_PARAMS(55, 1), PLL_PARAMS(56, 1), PLL_PARAMS(57, 1), PLL_PARAMS(58, 1), PLL_PARAMS(59, 1), PLL_PARAMS(60, 1), PLL_PARAMS(61, 1), PLL_PARAMS(62, 1), { /* sentinel */ }, }; static const struct pll_params_table gxl_gp0_pll_params_table[] = { PLL_PARAMS(42, 1), PLL_PARAMS(43, 1), PLL_PARAMS(44, 1), PLL_PARAMS(45, 1), PLL_PARAMS(46, 1), PLL_PARAMS(47, 1), PLL_PARAMS(48, 1), PLL_PARAMS(49, 1), PLL_PARAMS(50, 1), PLL_PARAMS(51, 1), PLL_PARAMS(52, 1), PLL_PARAMS(53, 1), PLL_PARAMS(54, 1), PLL_PARAMS(55, 1), PLL_PARAMS(56, 1), PLL_PARAMS(57, 1), PLL_PARAMS(58, 1), PLL_PARAMS(59, 1), PLL_PARAMS(60, 1), PLL_PARAMS(61, 1), PLL_PARAMS(62, 1), PLL_PARAMS(63, 1), PLL_PARAMS(64, 1), PLL_PARAMS(65, 1), PLL_PARAMS(66, 1), { /* sentinel */ }, }; static struct clk_regmap gxbb_fixed_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_MPLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_MPLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_MPLL_CNTL, .shift = 9, .width = 5, }, .frac = { .reg_off = HHI_MPLL_CNTL2, .shift = 0, .width = 12, }, .l = { .reg_off = HHI_MPLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_MPLL_CNTL, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap gxbb_fixed_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "fixed_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fixed_pll_dco.hw }, .num_parents = 1, /* * This clock won't ever change at runtime so * CLK_SET_RATE_PARENT is not required */ }, }; static struct clk_fixed_factor gxbb_hdmi_pll_pre_mult = { .mult = 2, .div = 1, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_pre_mult", .ops = &clk_fixed_factor_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap gxbb_hdmi_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 9, .width = 5, }, .frac = { .reg_off = HHI_HDMI_PLL_CNTL2, .shift = 0, .width = 12, }, .l = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 28, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_hdmi_pll_pre_mult.hw }, .num_parents = 1, /* * Display directly handle hdmi pll registers ATM, we need * NOCACHE to keep our view of the clock as accurate as possible */ .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxl_hdmi_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 9, .width = 5, }, /* * On gxl, there is a register shift due to * HHI_HDMI_PLL_CNTL1 which does not exist on gxbb, * so we use the HHI_HDMI_PLL_CNTL2 define from GXBB * instead which is defined at the same offset. */ .frac = { .reg_off = HHI_HDMI_PLL_CNTL2, .shift = 0, .width = 10, }, .l = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_HDMI_PLL_CNTL, .shift = 28, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, /* * Display directly handle hdmi pll registers ATM, we need * NOCACHE to keep our view of the clock as accurate as possible */ .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_hdmi_pll_od = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL2, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_od", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_hdmi_pll_dco.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_hdmi_pll_od2 = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL2, .shift = 22, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_od2", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_hdmi_pll_od.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_hdmi_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL2, .shift = 18, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_hdmi_pll_od2.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxl_hdmi_pll_od = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL + 8, .shift = 21, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_od", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxl_hdmi_pll_dco.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxl_hdmi_pll_od2 = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL + 8, .shift = 23, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll_od2", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxl_hdmi_pll_od.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxl_hdmi_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_PLL_CNTL + 8, .shift = 19, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxl_hdmi_pll_od2.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_sys_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 9, .width = 5, }, .l = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_SYS_PLL_CNTL, .shift = 29, .width = 1, }, }, .hw.init = &(struct clk_init_data){ .name = "sys_pll_dco", .ops = &meson_clk_pll_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap gxbb_sys_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SYS_PLL_CNTL, .shift = 10, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "sys_pll", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sys_pll_dco.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct reg_sequence gxbb_gp0_init_regs[] = { { .reg = HHI_GP0_PLL_CNTL2, .def = 0x69c80000 }, { .reg = HHI_GP0_PLL_CNTL3, .def = 0x0a5590c4 }, { .reg = HHI_GP0_PLL_CNTL4, .def = 0x0000500d }, }; static struct clk_regmap gxbb_gp0_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 9, .width = 5, }, .l = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 29, .width = 1, }, .table = gxbb_gp0_pll_params_table, .init_regs = gxbb_gp0_init_regs, .init_count = ARRAY_SIZE(gxbb_gp0_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "gp0_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static const struct reg_sequence gxl_gp0_init_regs[] = { { .reg = HHI_GP0_PLL_CNTL1, .def = 0xc084b000 }, { .reg = HHI_GP0_PLL_CNTL2, .def = 0xb75020be }, { .reg = HHI_GP0_PLL_CNTL3, .def = 0x0a59a288 }, { .reg = HHI_GP0_PLL_CNTL4, .def = 0xc000004d }, { .reg = HHI_GP0_PLL_CNTL5, .def = 0x00078000 }, }; static struct clk_regmap gxl_gp0_pll_dco = { .data = &(struct meson_clk_pll_data){ .en = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 30, .width = 1, }, .m = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 0, .width = 9, }, .n = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 9, .width = 5, }, .frac = { .reg_off = HHI_GP0_PLL_CNTL1, .shift = 0, .width = 10, }, .l = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 31, .width = 1, }, .rst = { .reg_off = HHI_GP0_PLL_CNTL, .shift = 29, .width = 1, }, .table = gxl_gp0_pll_params_table, .init_regs = gxl_gp0_init_regs, .init_count = ARRAY_SIZE(gxl_gp0_init_regs), }, .hw.init = &(struct clk_init_data){ .name = "gp0_pll_dco", .ops = &meson_clk_pll_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap gxbb_gp0_pll = { .data = &(struct clk_regmap_div_data){ .offset = HHI_GP0_PLL_CNTL, .shift = 16, .width = 2, .flags = CLK_DIVIDER_POWER_OF_TWO, }, .hw.init = &(struct clk_init_data){ .name = "gp0_pll", .ops = &clk_regmap_divider_ops, .parent_data = &(const struct clk_parent_data) { /* * Note: * GXL and GXBB have different gp0_pll_dco (with * different struct clk_hw). We fallback to the global * naming string mechanism so gp0_pll picks up the * appropriate one. */ .name = "gp0_pll_dco", .index = -1, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_fixed_factor gxbb_fclk_div2_div = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "fclk_div2_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_fclk_div2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 27, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fclk_div2_div.hw }, .num_parents = 1, .flags = CLK_IS_CRITICAL, }, }; static struct clk_fixed_factor gxbb_fclk_div3_div = { .mult = 1, .div = 3, .hw.init = &(struct clk_init_data){ .name = "fclk_div3_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_fclk_div3 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 28, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div3", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fclk_div3_div.hw }, .num_parents = 1, /* * FIXME: * This clock, as fdiv2, is used by the SCPI FW and is required * by the platform to operate correctly. * Until the following condition are met, we need this clock to * be marked as critical: * a) The SCPI generic driver claims and enable all the clocks * it needs * b) CCF has a clock hand-off mechanism to make the sure the * clock stays on until the proper driver comes along */ .flags = CLK_IS_CRITICAL, }, }; static struct clk_fixed_factor gxbb_fclk_div4_div = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "fclk_div4_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_fclk_div4 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 29, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div4", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fclk_div4_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_fclk_div5_div = { .mult = 1, .div = 5, .hw.init = &(struct clk_init_data){ .name = "fclk_div5_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_fclk_div5 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div5", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fclk_div5_div.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_fclk_div7_div = { .mult = 1, .div = 7, .hw.init = &(struct clk_init_data){ .name = "fclk_div7_div", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_fclk_div7 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL6, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div7", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fclk_div7_div.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_mpll_prediv = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPLL_CNTL5, .shift = 12, .width = 1, }, .hw.init = &(struct clk_init_data){ .name = "mpll_prediv", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_fixed_pll.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_mpll0_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL7, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL, .shift = 25, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL7, .shift = 16, .width = 9, }, .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data){ .name = "mpll0_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap gxl_mpll0_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL7, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL7, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL7, .shift = 16, .width = 9, }, .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data){ .name = "mpll0_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_mpll0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL7, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll0", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { /* * Note: * GXL and GXBB have different SDM_EN registers. We * fallback to the global naming string mechanism so * mpll0_div picks up the appropriate one. */ .name = "mpll0_div", .index = -1, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_mpll1_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL8, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL8, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL8, .shift = 16, .width = 9, }, .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data){ .name = "mpll1_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_mpll1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL8, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_mpll2_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL9, .shift = 0, .width = 14, }, .sdm_en = { .reg_off = HHI_MPLL_CNTL9, .shift = 15, .width = 1, }, .n2 = { .reg_off = HHI_MPLL_CNTL9, .shift = 16, .width = 9, }, .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data){ .name = "mpll2_div", .ops = &meson_clk_mpll_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll_prediv.hw }, .num_parents = 1, }, }; static struct clk_regmap gxbb_mpll2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPLL_CNTL9, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "mpll2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_clk81[] = { 0, 2, 3, 4, 5, 6, 7 }; static const struct clk_parent_data clk81_parent_data[] = { { .fw_name = "xtal", }, { .hw = &gxbb_fclk_div7.hw }, { .hw = &gxbb_mpll1.hw }, { .hw = &gxbb_mpll2.hw }, { .hw = &gxbb_fclk_div4.hw }, { .hw = &gxbb_fclk_div3.hw }, { .hw = &gxbb_fclk_div5.hw }, }; static struct clk_regmap gxbb_mpeg_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MPEG_CLK_CNTL, .mask = 0x7, .shift = 12, .table = mux_table_clk81, }, .hw.init = &(struct clk_init_data){ .name = "mpeg_clk_sel", .ops = &clk_regmap_mux_ro_ops, /* * bits 14:12 selects from 8 possible parents: * xtal, 1'b0 (wtf), fclk_div7, mpll_clkout1, mpll_clkout2, * fclk_div4, fclk_div3, fclk_div5 */ .parent_data = clk81_parent_data, .num_parents = ARRAY_SIZE(clk81_parent_data), }, }; static struct clk_regmap gxbb_mpeg_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MPEG_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mpeg_clk_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpeg_clk_sel.hw }, .num_parents = 1, }, }; /* the mother of dragons gates */ static struct clk_regmap gxbb_clk81 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MPEG_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "clk81", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpeg_clk_div.hw }, .num_parents = 1, .flags = CLK_IS_CRITICAL, }, }; static struct clk_regmap gxbb_sar_adc_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SAR_CLK_CNTL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "sar_adc_clk_sel", .ops = &clk_regmap_mux_ops, /* NOTE: The datasheet doesn't list the parents for bit 10 */ .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &gxbb_clk81.hw }, }, .num_parents = 2, }, }; static struct clk_regmap gxbb_sar_adc_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SAR_CLK_CNTL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "sar_adc_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sar_adc_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_sar_adc_clk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SAR_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "sar_adc_clk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sar_adc_clk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* * The MALI IP is clocked by two identical clocks (mali_0 and mali_1) * muxed by a glitch-free switch. The CCF can manage this glitch-free * mux because it does top-to-bottom updates the each clock tree and * switches to the "inactive" one when CLK_SET_RATE_GATE is set. */ static const struct clk_parent_data gxbb_mali_0_1_parent_data[] = { { .fw_name = "xtal", }, { .hw = &gxbb_gp0_pll.hw }, { .hw = &gxbb_mpll2.hw }, { .hw = &gxbb_mpll1.hw }, { .hw = &gxbb_fclk_div7.hw }, { .hw = &gxbb_fclk_div4.hw }, { .hw = &gxbb_fclk_div3.hw }, { .hw = &gxbb_fclk_div5.hw }, }; static struct clk_regmap gxbb_mali_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 0x7, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "mali_0_sel", .ops = &clk_regmap_mux_ops, .parent_data = gxbb_mali_0_1_parent_data, .num_parents = 8, /* * Don't request the parent to change the rate because * all GPU frequencies can be derived from the fclk_* * clocks and one special GP0_PLL setting. This is * important because we need the MPLL clocks for audio. */ .flags = 0, }, }; static struct clk_regmap gxbb_mali_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MALI_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mali_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mali_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_mali_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MALI_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "mali_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mali_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_mali_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 0x7, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "mali_1_sel", .ops = &clk_regmap_mux_ops, .parent_data = gxbb_mali_0_1_parent_data, .num_parents = 8, /* * Don't request the parent to change the rate because * all GPU frequencies can be derived from the fclk_* * clocks and one special GP0_PLL setting. This is * important because we need the MPLL clocks for audio. */ .flags = 0, }, }; static struct clk_regmap gxbb_mali_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_MALI_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "mali_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mali_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_mali_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_MALI_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data){ .name = "mali_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mali_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT, }, }; static const struct clk_hw *gxbb_mali_parent_hws[] = { &gxbb_mali_0.hw, &gxbb_mali_1.hw, }; static struct clk_regmap gxbb_mali = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_MALI_CLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "mali", .ops = &clk_regmap_mux_ops, .parent_hws = gxbb_mali_parent_hws, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_cts_amclk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_AUD_CLK_CNTL, .mask = 0x3, .shift = 9, .table = (u32[]){ 1, 2, 3 }, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cts_amclk_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll0.hw, &gxbb_mpll1.hw, &gxbb_mpll2.hw, }, .num_parents = 3, }, }; static struct clk_regmap gxbb_cts_amclk_div = { .data = &(struct clk_regmap_div_data) { .offset = HHI_AUD_CLK_CNTL, .shift = 0, .width = 8, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cts_amclk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_cts_amclk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_cts_amclk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_AUD_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "cts_amclk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_cts_amclk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_cts_mclk_i958_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_AUD_CLK_CNTL2, .mask = 0x3, .shift = 25, .table = (u32[]){ 1, 2, 3 }, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "cts_mclk_i958_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll0.hw, &gxbb_mpll1.hw, &gxbb_mpll2.hw, }, .num_parents = 3, }, }; static struct clk_regmap gxbb_cts_mclk_i958_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_AUD_CLK_CNTL2, .shift = 16, .width = 8, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "cts_mclk_i958_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_cts_mclk_i958_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_cts_mclk_i958 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_AUD_CLK_CNTL2, .bit_idx = 24, }, .hw.init = &(struct clk_init_data){ .name = "cts_mclk_i958", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_cts_mclk_i958_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_cts_i958 = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_AUD_CLK_CNTL2, .mask = 0x1, .shift = 27, }, .hw.init = &(struct clk_init_data){ .name = "cts_i958", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_cts_amclk.hw, &gxbb_cts_mclk_i958.hw }, .num_parents = 2, /* *The parent is specific to origin of the audio data. Let the * consumer choose the appropriate parent */ .flags = CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT, }, }; static const struct clk_parent_data gxbb_32k_clk_parent_data[] = { { .fw_name = "xtal", }, /* * FIXME: This clock is provided by the ao clock controller but the * clock is not yet part of the binding of this controller, so string * name must be use to set this parent. */ { .name = "cts_slow_oscin", .index = -1 }, { .hw = &gxbb_fclk_div3.hw }, { .hw = &gxbb_fclk_div5.hw }, }; static struct clk_regmap gxbb_32k_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_32K_CLK_CNTL, .mask = 0x3, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "32k_clk_sel", .ops = &clk_regmap_mux_ops, .parent_data = gxbb_32k_clk_parent_data, .num_parents = 4, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_32k_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_32K_CLK_CNTL, .shift = 0, .width = 14, }, .hw.init = &(struct clk_init_data){ .name = "32k_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_32k_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_DIVIDER_ROUND_CLOSEST, }, }; static struct clk_regmap gxbb_32k_clk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_32K_CLK_CNTL, .bit_idx = 15, }, .hw.init = &(struct clk_init_data){ .name = "32k_clk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_32k_clk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_parent_data gxbb_sd_emmc_clk0_parent_data[] = { { .fw_name = "xtal", }, { .hw = &gxbb_fclk_div2.hw }, { .hw = &gxbb_fclk_div3.hw }, { .hw = &gxbb_fclk_div5.hw }, { .hw = &gxbb_fclk_div7.hw }, /* * Following these parent clocks, we should also have had mpll2, mpll3 * and gp0_pll but these clocks are too precious to be used here. All * the necessary rates for MMC and NAND operation can be acheived using * xtal or fclk_div clocks */ }; /* SDIO clock */ static struct clk_regmap gxbb_sd_emmc_a_clk0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .mask = 0x7, .shift = 9, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_a_clk0_sel", .ops = &clk_regmap_mux_ops, .parent_data = gxbb_sd_emmc_clk0_parent_data, .num_parents = ARRAY_SIZE(gxbb_sd_emmc_clk0_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_sd_emmc_a_clk0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_a_clk0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sd_emmc_a_clk0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_sd_emmc_a_clk0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_a_clk0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sd_emmc_a_clk0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* SDcard clock */ static struct clk_regmap gxbb_sd_emmc_b_clk0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .mask = 0x7, .shift = 25, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_b_clk0_sel", .ops = &clk_regmap_mux_ops, .parent_data = gxbb_sd_emmc_clk0_parent_data, .num_parents = ARRAY_SIZE(gxbb_sd_emmc_clk0_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_sd_emmc_b_clk0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .shift = 16, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_b_clk0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sd_emmc_b_clk0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_sd_emmc_b_clk0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_SD_EMMC_CLK_CNTL, .bit_idx = 23, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_b_clk0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sd_emmc_b_clk0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* EMMC/NAND clock */ static struct clk_regmap gxbb_sd_emmc_c_clk0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_NAND_CLK_CNTL, .mask = 0x7, .shift = 9, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_c_clk0_sel", .ops = &clk_regmap_mux_ops, .parent_data = gxbb_sd_emmc_clk0_parent_data, .num_parents = ARRAY_SIZE(gxbb_sd_emmc_clk0_parent_data), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_sd_emmc_c_clk0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_NAND_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc_c_clk0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sd_emmc_c_clk0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_sd_emmc_c_clk0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_NAND_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_c_clk0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_sd_emmc_c_clk0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* VPU Clock */ static const struct clk_hw *gxbb_vpu_parent_hws[] = { &gxbb_fclk_div4.hw, &gxbb_fclk_div3.hw, &gxbb_fclk_div5.hw, &gxbb_fclk_div7.hw, }; static struct clk_regmap gxbb_vpu_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_sel", .ops = &clk_regmap_mux_ops, /* * bits 9:10 selects from 4 possible parents: * fclk_div4, fclk_div3, fclk_div5, fclk_div7, */ .parent_hws = gxbb_vpu_parent_hws, .num_parents = ARRAY_SIZE(gxbb_vpu_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap gxbb_vpu_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VPU_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vpu_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vpu_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vpu_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VPU_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vpu_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vpu_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vpu_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 0x3, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_sel", .ops = &clk_regmap_mux_ops, /* * bits 25:26 selects from 4 possible parents: * fclk_div4, fclk_div3, fclk_div5, fclk_div7, */ .parent_hws = gxbb_vpu_parent_hws, .num_parents = ARRAY_SIZE(gxbb_vpu_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap gxbb_vpu_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VPU_CLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vpu_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vpu_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vpu_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VPU_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vpu_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vpu_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vpu = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VPU_CLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "vpu", .ops = &clk_regmap_mux_ops, /* * bit 31 selects from 2 possible parents: * vpu_0 or vpu_1 */ .parent_hws = (const struct clk_hw *[]) { &gxbb_vpu_0.hw, &gxbb_vpu_1.hw }, .num_parents = 2, .flags = CLK_SET_RATE_NO_REPARENT, }, }; /* VAPB Clock */ static const struct clk_hw *gxbb_vapb_parent_hws[] = { &gxbb_fclk_div4.hw, &gxbb_fclk_div3.hw, &gxbb_fclk_div5.hw, &gxbb_fclk_div7.hw, }; static struct clk_regmap gxbb_vapb_0_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "vapb_0_sel", .ops = &clk_regmap_mux_ops, /* * bits 9:10 selects from 4 possible parents: * fclk_div4, fclk_div3, fclk_div5, fclk_div7, */ .parent_hws = gxbb_vapb_parent_hws, .num_parents = ARRAY_SIZE(gxbb_vapb_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap gxbb_vapb_0_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VAPBCLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vapb_0_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vapb_0_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vapb_0 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vapb_0", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vapb_0_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vapb_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 0x3, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "vapb_1_sel", .ops = &clk_regmap_mux_ops, /* * bits 25:26 selects from 4 possible parents: * fclk_div4, fclk_div3, fclk_div5, fclk_div7, */ .parent_hws = gxbb_vapb_parent_hws, .num_parents = ARRAY_SIZE(gxbb_vapb_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap gxbb_vapb_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VAPBCLK_CNTL, .shift = 16, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "vapb_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vapb_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vapb_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vapb_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vapb_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vapb_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VAPBCLK_CNTL, .mask = 1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "vapb_sel", .ops = &clk_regmap_mux_ops, /* * bit 31 selects from 2 possible parents: * vapb_0 or vapb_1 */ .parent_hws = (const struct clk_hw *[]) { &gxbb_vapb_0.hw, &gxbb_vapb_1.hw }, .num_parents = 2, .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap gxbb_vapb = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VAPBCLK_CNTL, .bit_idx = 30, }, .hw.init = &(struct clk_init_data) { .name = "vapb", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vapb_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; /* Video Clocks */ static struct clk_regmap gxbb_vid_pll_div = { .data = &(struct meson_vid_pll_div_data){ .val = { .reg_off = HHI_VID_PLL_CLK_DIV, .shift = 0, .width = 15, }, .sel = { .reg_off = HHI_VID_PLL_CLK_DIV, .shift = 16, .width = 2, }, }, .hw.init = &(struct clk_init_data) { .name = "vid_pll_div", .ops = &meson_vid_pll_div_ro_ops, .parent_data = &(const struct clk_parent_data) { /* * Note: * GXL and GXBB have different hdmi_plls (with * different struct clk_hw). We fallback to the global * naming string mechanism so vid_pll_div picks up the * appropriate one. */ .name = "hdmi_pll", .index = -1, }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE, }, }; static const struct clk_parent_data gxbb_vid_pll_parent_data[] = { { .hw = &gxbb_vid_pll_div.hw }, /* * Note: * GXL and GXBB have different hdmi_plls (with * different struct clk_hw). We fallback to the global * naming string mechanism so vid_pll_div picks up the * appropriate one. */ { .name = "hdmi_pll", .index = -1 }, }; static struct clk_regmap gxbb_vid_pll_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_PLL_CLK_DIV, .mask = 0x1, .shift = 18, }, .hw.init = &(struct clk_init_data){ .name = "vid_pll_sel", .ops = &clk_regmap_mux_ops, /* * bit 18 selects from 2 possible parents: * vid_pll_div or hdmi_pll */ .parent_data = gxbb_vid_pll_parent_data, .num_parents = ARRAY_SIZE(gxbb_vid_pll_parent_data), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_vid_pll = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_PLL_CLK_DIV, .bit_idx = 19, }, .hw.init = &(struct clk_init_data) { .name = "vid_pll", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vid_pll_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static const struct clk_hw *gxbb_vclk_parent_hws[] = { &gxbb_vid_pll.hw, &gxbb_fclk_div4.hw, &gxbb_fclk_div3.hw, &gxbb_fclk_div5.hw, &gxbb_vid_pll.hw, &gxbb_fclk_div7.hw, &gxbb_mpll1.hw, }; static struct clk_regmap gxbb_vclk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_CNTL, .mask = 0x7, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk_sel", .ops = &clk_regmap_mux_ops, /* * bits 16:18 selects from 8 possible parents: * vid_pll, fclk_div4, fclk_div3, fclk_div5, * vid_pll, fclk_div7, mp1 */ .parent_hws = gxbb_vclk_parent_hws, .num_parents = ARRAY_SIZE(gxbb_vclk_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_vclk2_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_CNTL, .mask = 0x7, .shift = 16, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_sel", .ops = &clk_regmap_mux_ops, /* * bits 16:18 selects from 8 possible parents: * vid_pll, fclk_div4, fclk_div3, fclk_div5, * vid_pll, fclk_div7, mp1 */ .parent_hws = gxbb_vclk_parent_hws, .num_parents = ARRAY_SIZE(gxbb_vclk_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_vclk_input = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_DIV, .bit_idx = 16, }, .hw.init = &(struct clk_init_data) { .name = "vclk_input", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk2_input = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_DIV, .bit_idx = 16, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_input", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VID_CLK_DIV, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "vclk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk_input.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_vclk2_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VIID_CLK_DIV, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "vclk2_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2_input.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_vclk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 19, }, .hw.init = &(struct clk_init_data) { .name = "vclk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk2 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 19, }, .hw.init = &(struct clk_init_data) { .name = "vclk2", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk_div1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk_div2_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk_div4_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div4_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk_div6_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div6_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk_div12_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "vclk_div12_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk2_div1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk2_div2_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div2_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk2_div4_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div4_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk2_div6_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div6_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_vclk2_div12_en = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VIID_CLK_CNTL, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "vclk2_div12_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_fixed_factor gxbb_vclk_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "vclk_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk_div2_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_vclk_div4 = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "vclk_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk_div4_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_vclk_div6 = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "vclk_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk_div6_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_vclk_div12 = { .mult = 1, .div = 12, .hw.init = &(struct clk_init_data){ .name = "vclk_div12", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk_div12_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_vclk2_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "vclk2_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2_div2_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_vclk2_div4 = { .mult = 1, .div = 4, .hw.init = &(struct clk_init_data){ .name = "vclk2_div4", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2_div4_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_vclk2_div6 = { .mult = 1, .div = 6, .hw.init = &(struct clk_init_data){ .name = "vclk2_div6", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2_div6_en.hw }, .num_parents = 1, }, }; static struct clk_fixed_factor gxbb_vclk2_div12 = { .mult = 1, .div = 12, .hw.init = &(struct clk_init_data){ .name = "vclk2_div12", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vclk2_div12_en.hw }, .num_parents = 1, }, }; static u32 mux_table_cts_sel[] = { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12 }; static const struct clk_hw *gxbb_cts_parent_hws[] = { &gxbb_vclk_div1.hw, &gxbb_vclk_div2.hw, &gxbb_vclk_div4.hw, &gxbb_vclk_div6.hw, &gxbb_vclk_div12.hw, &gxbb_vclk2_div1.hw, &gxbb_vclk2_div2.hw, &gxbb_vclk2_div4.hw, &gxbb_vclk2_div6.hw, &gxbb_vclk2_div12.hw, }; static struct clk_regmap gxbb_cts_enci_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_DIV, .mask = 0xf, .shift = 28, .table = mux_table_cts_sel, }, .hw.init = &(struct clk_init_data){ .name = "cts_enci_sel", .ops = &clk_regmap_mux_ops, .parent_hws = gxbb_cts_parent_hws, .num_parents = ARRAY_SIZE(gxbb_cts_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_cts_encp_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VID_CLK_DIV, .mask = 0xf, .shift = 20, .table = mux_table_cts_sel, }, .hw.init = &(struct clk_init_data){ .name = "cts_encp_sel", .ops = &clk_regmap_mux_ops, .parent_hws = gxbb_cts_parent_hws, .num_parents = ARRAY_SIZE(gxbb_cts_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_cts_vdac_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VIID_CLK_DIV, .mask = 0xf, .shift = 28, .table = mux_table_cts_sel, }, .hw.init = &(struct clk_init_data){ .name = "cts_vdac_sel", .ops = &clk_regmap_mux_ops, .parent_hws = gxbb_cts_parent_hws, .num_parents = ARRAY_SIZE(gxbb_cts_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; /* TOFIX: add support for cts_tcon */ static u32 mux_table_hdmi_tx_sel[] = { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12 }; static const struct clk_hw *gxbb_cts_hdmi_tx_parent_hws[] = { &gxbb_vclk_div1.hw, &gxbb_vclk_div2.hw, &gxbb_vclk_div4.hw, &gxbb_vclk_div6.hw, &gxbb_vclk_div12.hw, &gxbb_vclk2_div1.hw, &gxbb_vclk2_div2.hw, &gxbb_vclk2_div4.hw, &gxbb_vclk2_div6.hw, &gxbb_vclk2_div12.hw, }; static struct clk_regmap gxbb_hdmi_tx_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_HDMI_CLK_CNTL, .mask = 0xf, .shift = 16, .table = mux_table_hdmi_tx_sel, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_tx_sel", .ops = &clk_regmap_mux_ops, /* * bits 31:28 selects from 12 possible parents: * vclk_div1, vclk_div2, vclk_div4, vclk_div6, vclk_div12 * vclk2_div1, vclk2_div2, vclk2_div4, vclk2_div6, vclk2_div12, * cts_tcon */ .parent_hws = gxbb_cts_hdmi_tx_parent_hws, .num_parents = ARRAY_SIZE(gxbb_cts_hdmi_tx_parent_hws), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_cts_enci = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "cts_enci", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_cts_enci_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_cts_encp = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "cts_encp", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_cts_encp_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_cts_vdac = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "cts_vdac", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_cts_vdac_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; static struct clk_regmap gxbb_hdmi_tx = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VID_CLK_CNTL2, .bit_idx = 5, }, .hw.init = &(struct clk_init_data) { .name = "hdmi_tx", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_hdmi_tx_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; /* HDMI Clocks */ static const struct clk_parent_data gxbb_hdmi_parent_data[] = { { .fw_name = "xtal", }, { .hw = &gxbb_fclk_div4.hw }, { .hw = &gxbb_fclk_div3.hw }, { .hw = &gxbb_fclk_div5.hw }, }; static struct clk_regmap gxbb_hdmi_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_HDMI_CLK_CNTL, .mask = 0x3, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_sel", .ops = &clk_regmap_mux_ops, .parent_data = gxbb_hdmi_parent_data, .num_parents = ARRAY_SIZE(gxbb_hdmi_parent_data), .flags = CLK_SET_RATE_NO_REPARENT | CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_hdmi_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_HDMI_CLK_CNTL, .shift = 0, .width = 7, }, .hw.init = &(struct clk_init_data){ .name = "hdmi_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_hdmi_sel.hw }, .num_parents = 1, .flags = CLK_GET_RATE_NOCACHE, }, }; static struct clk_regmap gxbb_hdmi = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_HDMI_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "hdmi", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_hdmi_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, }, }; /* VDEC clocks */ static const struct clk_hw *gxbb_vdec_parent_hws[] = { &gxbb_fclk_div4.hw, &gxbb_fclk_div3.hw, &gxbb_fclk_div5.hw, &gxbb_fclk_div7.hw, }; static struct clk_regmap gxbb_vdec_1_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC_CLK_CNTL, .mask = 0x3, .shift = 9, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_1_sel", .ops = &clk_regmap_mux_ops, .parent_hws = gxbb_vdec_parent_hws, .num_parents = ARRAY_SIZE(gxbb_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vdec_1_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC_CLK_CNTL, .shift = 0, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_1_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vdec_1_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vdec_1 = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC_CLK_CNTL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "vdec_1", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vdec_1_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vdec_hevc_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_VDEC2_CLK_CNTL, .mask = 0x3, .shift = 25, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevc_sel", .ops = &clk_regmap_mux_ops, .parent_hws = gxbb_vdec_parent_hws, .num_parents = ARRAY_SIZE(gxbb_vdec_parent_hws), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vdec_hevc_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_VDEC2_CLK_CNTL, .shift = 16, .width = 7, .flags = CLK_DIVIDER_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "vdec_hevc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vdec_hevc_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_vdec_hevc = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_VDEC2_CLK_CNTL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "vdec_hevc", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_vdec_hevc_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_gen_clk[] = { 0, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, }; static const struct clk_parent_data gen_clk_parent_data[] = { { .fw_name = "xtal", }, { .hw = &gxbb_vdec_1.hw }, { .hw = &gxbb_vdec_hevc.hw }, { .hw = &gxbb_mpll0.hw }, { .hw = &gxbb_mpll1.hw }, { .hw = &gxbb_mpll2.hw }, { .hw = &gxbb_fclk_div4.hw }, { .hw = &gxbb_fclk_div3.hw }, { .hw = &gxbb_fclk_div5.hw }, { .hw = &gxbb_fclk_div7.hw }, { .hw = &gxbb_gp0_pll.hw }, }; static struct clk_regmap gxbb_gen_clk_sel = { .data = &(struct clk_regmap_mux_data){ .offset = HHI_GEN_CLK_CNTL, .mask = 0xf, .shift = 12, .table = mux_table_gen_clk, }, .hw.init = &(struct clk_init_data){ .name = "gen_clk_sel", .ops = &clk_regmap_mux_ops, /* * bits 15:12 selects from 14 possible parents: * xtal, [rtc_oscin_i], [sys_cpu_div16], [ddr_dpll_pt], * vid_pll, vid2_pll (hevc), mpll0, mpll1, mpll2, fdiv4, * fdiv3, fdiv5, [cts_msr_clk], fdiv7, gp0_pll */ .parent_data = gen_clk_parent_data, .num_parents = ARRAY_SIZE(gen_clk_parent_data), }, }; static struct clk_regmap gxbb_gen_clk_div = { .data = &(struct clk_regmap_div_data){ .offset = HHI_GEN_CLK_CNTL, .shift = 0, .width = 11, }, .hw.init = &(struct clk_init_data){ .name = "gen_clk_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_gen_clk_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gxbb_gen_clk = { .data = &(struct clk_regmap_gate_data){ .offset = HHI_GEN_CLK_CNTL, .bit_idx = 7, }, .hw.init = &(struct clk_init_data){ .name = "gen_clk", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gxbb_gen_clk_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; #define MESON_GATE(_name, _reg, _bit) \ MESON_PCLK(_name, _reg, _bit, &gxbb_clk81.hw) /* Everything Else (EE) domain gates */ static MESON_GATE(gxbb_ddr, HHI_GCLK_MPEG0, 0); static MESON_GATE(gxbb_dos, HHI_GCLK_MPEG0, 1); static MESON_GATE(gxbb_isa, HHI_GCLK_MPEG0, 5); static MESON_GATE(gxbb_pl301, HHI_GCLK_MPEG0, 6); static MESON_GATE(gxbb_periphs, HHI_GCLK_MPEG0, 7); static MESON_GATE(gxbb_spicc, HHI_GCLK_MPEG0, 8); static MESON_GATE(gxbb_i2c, HHI_GCLK_MPEG0, 9); static MESON_GATE(gxbb_sana, HHI_GCLK_MPEG0, 10); static MESON_GATE(gxbb_smart_card, HHI_GCLK_MPEG0, 11); static MESON_GATE(gxbb_rng0, HHI_GCLK_MPEG0, 12); static MESON_GATE(gxbb_uart0, HHI_GCLK_MPEG0, 13); static MESON_GATE(gxbb_sdhc, HHI_GCLK_MPEG0, 14); static MESON_GATE(gxbb_stream, HHI_GCLK_MPEG0, 15); static MESON_GATE(gxbb_async_fifo, HHI_GCLK_MPEG0, 16); static MESON_GATE(gxbb_sdio, HHI_GCLK_MPEG0, 17); static MESON_GATE(gxbb_abuf, HHI_GCLK_MPEG0, 18); static MESON_GATE(gxbb_hiu_iface, HHI_GCLK_MPEG0, 19); static MESON_GATE(gxbb_assist_misc, HHI_GCLK_MPEG0, 23); static MESON_GATE(gxbb_emmc_a, HHI_GCLK_MPEG0, 24); static MESON_GATE(gxbb_emmc_b, HHI_GCLK_MPEG0, 25); static MESON_GATE(gxbb_emmc_c, HHI_GCLK_MPEG0, 26); static MESON_GATE(gxl_acodec, HHI_GCLK_MPEG0, 28); static MESON_GATE(gxbb_spi, HHI_GCLK_MPEG0, 30); static MESON_GATE(gxbb_i2s_spdif, HHI_GCLK_MPEG1, 2); static MESON_GATE(gxbb_eth, HHI_GCLK_MPEG1, 3); static MESON_GATE(gxbb_demux, HHI_GCLK_MPEG1, 4); static MESON_GATE(gxbb_blkmv, HHI_GCLK_MPEG1, 14); static MESON_GATE(gxbb_aiu, HHI_GCLK_MPEG1, 15); static MESON_GATE(gxbb_uart1, HHI_GCLK_MPEG1, 16); static MESON_GATE(gxbb_g2d, HHI_GCLK_MPEG1, 20); static MESON_GATE(gxbb_usb0, HHI_GCLK_MPEG1, 21); static MESON_GATE(gxbb_usb1, HHI_GCLK_MPEG1, 22); static MESON_GATE(gxbb_reset, HHI_GCLK_MPEG1, 23); static MESON_GATE(gxbb_nand, HHI_GCLK_MPEG1, 24); static MESON_GATE(gxbb_dos_parser, HHI_GCLK_MPEG1, 25); static MESON_GATE(gxbb_usb, HHI_GCLK_MPEG1, 26); static MESON_GATE(gxbb_vdin1, HHI_GCLK_MPEG1, 28); static MESON_GATE(gxbb_ahb_arb0, HHI_GCLK_MPEG1, 29); static MESON_GATE(gxbb_efuse, HHI_GCLK_MPEG1, 30); static MESON_GATE(gxbb_boot_rom, HHI_GCLK_MPEG1, 31); static MESON_GATE(gxbb_ahb_data_bus, HHI_GCLK_MPEG2, 1); static MESON_GATE(gxbb_ahb_ctrl_bus, HHI_GCLK_MPEG2, 2); static MESON_GATE(gxbb_hdmi_intr_sync, HHI_GCLK_MPEG2, 3); static MESON_GATE(gxbb_hdmi_pclk, HHI_GCLK_MPEG2, 4); static MESON_GATE(gxbb_usb1_ddr_bridge, HHI_GCLK_MPEG2, 8); static MESON_GATE(gxbb_usb0_ddr_bridge, HHI_GCLK_MPEG2, 9); static MESON_GATE(gxbb_mmc_pclk, HHI_GCLK_MPEG2, 11); static MESON_GATE(gxbb_dvin, HHI_GCLK_MPEG2, 12); static MESON_GATE(gxbb_uart2, HHI_GCLK_MPEG2, 15); static MESON_GATE(gxbb_sar_adc, HHI_GCLK_MPEG2, 22); static MESON_GATE(gxbb_vpu_intr, HHI_GCLK_MPEG2, 25); static MESON_GATE(gxbb_sec_ahb_ahb3_bridge, HHI_GCLK_MPEG2, 26); static MESON_GATE(gxbb_clk81_a53, HHI_GCLK_MPEG2, 29); static MESON_GATE(gxbb_vclk2_venci0, HHI_GCLK_OTHER, 1); static MESON_GATE(gxbb_vclk2_venci1, HHI_GCLK_OTHER, 2); static MESON_GATE(gxbb_vclk2_vencp0, HHI_GCLK_OTHER, 3); static MESON_GATE(gxbb_vclk2_vencp1, HHI_GCLK_OTHER, 4); static MESON_GATE(gxbb_gclk_venci_int0, HHI_GCLK_OTHER, 8); static MESON_GATE(gxbb_gclk_vencp_int, HHI_GCLK_OTHER, 9); static MESON_GATE(gxbb_dac_clk, HHI_GCLK_OTHER, 10); static MESON_GATE(gxbb_aoclk_gate, HHI_GCLK_OTHER, 14); static MESON_GATE(gxbb_iec958_gate, HHI_GCLK_OTHER, 16); static MESON_GATE(gxbb_enc480p, HHI_GCLK_OTHER, 20); static MESON_GATE(gxbb_rng1, HHI_GCLK_OTHER, 21); static MESON_GATE(gxbb_gclk_venci_int1, HHI_GCLK_OTHER, 22); static MESON_GATE(gxbb_vclk2_venclmcc, HHI_GCLK_OTHER, 24); static MESON_GATE(gxbb_vclk2_vencl, HHI_GCLK_OTHER, 25); static MESON_GATE(gxbb_vclk_other, HHI_GCLK_OTHER, 26); static MESON_GATE(gxbb_edp, HHI_GCLK_OTHER, 31); /* Always On (AO) domain gates */ static MESON_GATE(gxbb_ao_media_cpu, HHI_GCLK_AO, 0); static MESON_GATE(gxbb_ao_ahb_sram, HHI_GCLK_AO, 1); static MESON_GATE(gxbb_ao_ahb_bus, HHI_GCLK_AO, 2); static MESON_GATE(gxbb_ao_iface, HHI_GCLK_AO, 3); static MESON_GATE(gxbb_ao_i2c, HHI_GCLK_AO, 4); /* AIU gates */ static MESON_PCLK(gxbb_aiu_glue, HHI_GCLK_MPEG1, 6, &gxbb_aiu.hw); static MESON_PCLK(gxbb_iec958, HHI_GCLK_MPEG1, 7, &gxbb_aiu_glue.hw); static MESON_PCLK(gxbb_i2s_out, HHI_GCLK_MPEG1, 8, &gxbb_aiu_glue.hw); static MESON_PCLK(gxbb_amclk, HHI_GCLK_MPEG1, 9, &gxbb_aiu_glue.hw); static MESON_PCLK(gxbb_aififo2, HHI_GCLK_MPEG1, 10, &gxbb_aiu_glue.hw); static MESON_PCLK(gxbb_mixer, HHI_GCLK_MPEG1, 11, &gxbb_aiu_glue.hw); static MESON_PCLK(gxbb_mixer_iface, HHI_GCLK_MPEG1, 12, &gxbb_aiu_glue.hw); static MESON_PCLK(gxbb_adc, HHI_GCLK_MPEG1, 13, &gxbb_aiu_glue.hw); /* Array of all clocks provided by this provider */ static struct clk_hw *gxbb_hw_clks[] = { [CLKID_SYS_PLL] = &gxbb_sys_pll.hw, [CLKID_HDMI_PLL] = &gxbb_hdmi_pll.hw, [CLKID_FIXED_PLL] = &gxbb_fixed_pll.hw, [CLKID_FCLK_DIV2] = &gxbb_fclk_div2.hw, [CLKID_FCLK_DIV3] = &gxbb_fclk_div3.hw, [CLKID_FCLK_DIV4] = &gxbb_fclk_div4.hw, [CLKID_FCLK_DIV5] = &gxbb_fclk_div5.hw, [CLKID_FCLK_DIV7] = &gxbb_fclk_div7.hw, [CLKID_GP0_PLL] = &gxbb_gp0_pll.hw, [CLKID_MPEG_SEL] = &gxbb_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &gxbb_mpeg_clk_div.hw, [CLKID_CLK81] = &gxbb_clk81.hw, [CLKID_MPLL0] = &gxbb_mpll0.hw, [CLKID_MPLL1] = &gxbb_mpll1.hw, [CLKID_MPLL2] = &gxbb_mpll2.hw, [CLKID_DDR] = &gxbb_ddr.hw, [CLKID_DOS] = &gxbb_dos.hw, [CLKID_ISA] = &gxbb_isa.hw, [CLKID_PL301] = &gxbb_pl301.hw, [CLKID_PERIPHS] = &gxbb_periphs.hw, [CLKID_SPICC] = &gxbb_spicc.hw, [CLKID_I2C] = &gxbb_i2c.hw, [CLKID_SAR_ADC] = &gxbb_sar_adc.hw, [CLKID_SMART_CARD] = &gxbb_smart_card.hw, [CLKID_RNG0] = &gxbb_rng0.hw, [CLKID_UART0] = &gxbb_uart0.hw, [CLKID_SDHC] = &gxbb_sdhc.hw, [CLKID_STREAM] = &gxbb_stream.hw, [CLKID_ASYNC_FIFO] = &gxbb_async_fifo.hw, [CLKID_SDIO] = &gxbb_sdio.hw, [CLKID_ABUF] = &gxbb_abuf.hw, [CLKID_HIU_IFACE] = &gxbb_hiu_iface.hw, [CLKID_ASSIST_MISC] = &gxbb_assist_misc.hw, [CLKID_SPI] = &gxbb_spi.hw, [CLKID_I2S_SPDIF] = &gxbb_i2s_spdif.hw, [CLKID_ETH] = &gxbb_eth.hw, [CLKID_DEMUX] = &gxbb_demux.hw, [CLKID_AIU_GLUE] = &gxbb_aiu_glue.hw, [CLKID_IEC958] = &gxbb_iec958.hw, [CLKID_I2S_OUT] = &gxbb_i2s_out.hw, [CLKID_AMCLK] = &gxbb_amclk.hw, [CLKID_AIFIFO2] = &gxbb_aififo2.hw, [CLKID_MIXER] = &gxbb_mixer.hw, [CLKID_MIXER_IFACE] = &gxbb_mixer_iface.hw, [CLKID_ADC] = &gxbb_adc.hw, [CLKID_BLKMV] = &gxbb_blkmv.hw, [CLKID_AIU] = &gxbb_aiu.hw, [CLKID_UART1] = &gxbb_uart1.hw, [CLKID_G2D] = &gxbb_g2d.hw, [CLKID_USB0] = &gxbb_usb0.hw, [CLKID_USB1] = &gxbb_usb1.hw, [CLKID_RESET] = &gxbb_reset.hw, [CLKID_NAND] = &gxbb_nand.hw, [CLKID_DOS_PARSER] = &gxbb_dos_parser.hw, [CLKID_USB] = &gxbb_usb.hw, [CLKID_VDIN1] = &gxbb_vdin1.hw, [CLKID_AHB_ARB0] = &gxbb_ahb_arb0.hw, [CLKID_EFUSE] = &gxbb_efuse.hw, [CLKID_BOOT_ROM] = &gxbb_boot_rom.hw, [CLKID_AHB_DATA_BUS] = &gxbb_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &gxbb_ahb_ctrl_bus.hw, [CLKID_HDMI_INTR_SYNC] = &gxbb_hdmi_intr_sync.hw, [CLKID_HDMI_PCLK] = &gxbb_hdmi_pclk.hw, [CLKID_USB1_DDR_BRIDGE] = &gxbb_usb1_ddr_bridge.hw, [CLKID_USB0_DDR_BRIDGE] = &gxbb_usb0_ddr_bridge.hw, [CLKID_MMC_PCLK] = &gxbb_mmc_pclk.hw, [CLKID_DVIN] = &gxbb_dvin.hw, [CLKID_UART2] = &gxbb_uart2.hw, [CLKID_SANA] = &gxbb_sana.hw, [CLKID_VPU_INTR] = &gxbb_vpu_intr.hw, [CLKID_SEC_AHB_AHB3_BRIDGE] = &gxbb_sec_ahb_ahb3_bridge.hw, [CLKID_CLK81_A53] = &gxbb_clk81_a53.hw, [CLKID_VCLK2_VENCI0] = &gxbb_vclk2_venci0.hw, [CLKID_VCLK2_VENCI1] = &gxbb_vclk2_venci1.hw, [CLKID_VCLK2_VENCP0] = &gxbb_vclk2_vencp0.hw, [CLKID_VCLK2_VENCP1] = &gxbb_vclk2_vencp1.hw, [CLKID_GCLK_VENCI_INT0] = &gxbb_gclk_venci_int0.hw, [CLKID_GCLK_VENCI_INT] = &gxbb_gclk_vencp_int.hw, [CLKID_DAC_CLK] = &gxbb_dac_clk.hw, [CLKID_AOCLK_GATE] = &gxbb_aoclk_gate.hw, [CLKID_IEC958_GATE] = &gxbb_iec958_gate.hw, [CLKID_ENC480P] = &gxbb_enc480p.hw, [CLKID_RNG1] = &gxbb_rng1.hw, [CLKID_GCLK_VENCI_INT1] = &gxbb_gclk_venci_int1.hw, [CLKID_VCLK2_VENCLMCC] = &gxbb_vclk2_venclmcc.hw, [CLKID_VCLK2_VENCL] = &gxbb_vclk2_vencl.hw, [CLKID_VCLK_OTHER] = &gxbb_vclk_other.hw, [CLKID_EDP] = &gxbb_edp.hw, [CLKID_AO_MEDIA_CPU] = &gxbb_ao_media_cpu.hw, [CLKID_AO_AHB_SRAM] = &gxbb_ao_ahb_sram.hw, [CLKID_AO_AHB_BUS] = &gxbb_ao_ahb_bus.hw, [CLKID_AO_IFACE] = &gxbb_ao_iface.hw, [CLKID_AO_I2C] = &gxbb_ao_i2c.hw, [CLKID_SD_EMMC_A] = &gxbb_emmc_a.hw, [CLKID_SD_EMMC_B] = &gxbb_emmc_b.hw, [CLKID_SD_EMMC_C] = &gxbb_emmc_c.hw, [CLKID_SAR_ADC_CLK] = &gxbb_sar_adc_clk.hw, [CLKID_SAR_ADC_SEL] = &gxbb_sar_adc_clk_sel.hw, [CLKID_SAR_ADC_DIV] = &gxbb_sar_adc_clk_div.hw, [CLKID_MALI_0_SEL] = &gxbb_mali_0_sel.hw, [CLKID_MALI_0_DIV] = &gxbb_mali_0_div.hw, [CLKID_MALI_0] = &gxbb_mali_0.hw, [CLKID_MALI_1_SEL] = &gxbb_mali_1_sel.hw, [CLKID_MALI_1_DIV] = &gxbb_mali_1_div.hw, [CLKID_MALI_1] = &gxbb_mali_1.hw, [CLKID_MALI] = &gxbb_mali.hw, [CLKID_CTS_AMCLK] = &gxbb_cts_amclk.hw, [CLKID_CTS_AMCLK_SEL] = &gxbb_cts_amclk_sel.hw, [CLKID_CTS_AMCLK_DIV] = &gxbb_cts_amclk_div.hw, [CLKID_CTS_MCLK_I958] = &gxbb_cts_mclk_i958.hw, [CLKID_CTS_MCLK_I958_SEL] = &gxbb_cts_mclk_i958_sel.hw, [CLKID_CTS_MCLK_I958_DIV] = &gxbb_cts_mclk_i958_div.hw, [CLKID_CTS_I958] = &gxbb_cts_i958.hw, [CLKID_32K_CLK] = &gxbb_32k_clk.hw, [CLKID_32K_CLK_SEL] = &gxbb_32k_clk_sel.hw, [CLKID_32K_CLK_DIV] = &gxbb_32k_clk_div.hw, [CLKID_SD_EMMC_A_CLK0_SEL] = &gxbb_sd_emmc_a_clk0_sel.hw, [CLKID_SD_EMMC_A_CLK0_DIV] = &gxbb_sd_emmc_a_clk0_div.hw, [CLKID_SD_EMMC_A_CLK0] = &gxbb_sd_emmc_a_clk0.hw, [CLKID_SD_EMMC_B_CLK0_SEL] = &gxbb_sd_emmc_b_clk0_sel.hw, [CLKID_SD_EMMC_B_CLK0_DIV] = &gxbb_sd_emmc_b_clk0_div.hw, [CLKID_SD_EMMC_B_CLK0] = &gxbb_sd_emmc_b_clk0.hw, [CLKID_SD_EMMC_C_CLK0_SEL] = &gxbb_sd_emmc_c_clk0_sel.hw, [CLKID_SD_EMMC_C_CLK0_DIV] = &gxbb_sd_emmc_c_clk0_div.hw, [CLKID_SD_EMMC_C_CLK0] = &gxbb_sd_emmc_c_clk0.hw, [CLKID_VPU_0_SEL] = &gxbb_vpu_0_sel.hw, [CLKID_VPU_0_DIV] = &gxbb_vpu_0_div.hw, [CLKID_VPU_0] = &gxbb_vpu_0.hw, [CLKID_VPU_1_SEL] = &gxbb_vpu_1_sel.hw, [CLKID_VPU_1_DIV] = &gxbb_vpu_1_div.hw, [CLKID_VPU_1] = &gxbb_vpu_1.hw, [CLKID_VPU] = &gxbb_vpu.hw, [CLKID_VAPB_0_SEL] = &gxbb_vapb_0_sel.hw, [CLKID_VAPB_0_DIV] = &gxbb_vapb_0_div.hw, [CLKID_VAPB_0] = &gxbb_vapb_0.hw, [CLKID_VAPB_1_SEL] = &gxbb_vapb_1_sel.hw, [CLKID_VAPB_1_DIV] = &gxbb_vapb_1_div.hw, [CLKID_VAPB_1] = &gxbb_vapb_1.hw, [CLKID_VAPB_SEL] = &gxbb_vapb_sel.hw, [CLKID_VAPB] = &gxbb_vapb.hw, [CLKID_HDMI_PLL_PRE_MULT] = &gxbb_hdmi_pll_pre_mult.hw, [CLKID_MPLL0_DIV] = &gxbb_mpll0_div.hw, [CLKID_MPLL1_DIV] = &gxbb_mpll1_div.hw, [CLKID_MPLL2_DIV] = &gxbb_mpll2_div.hw, [CLKID_MPLL_PREDIV] = &gxbb_mpll_prediv.hw, [CLKID_FCLK_DIV2_DIV] = &gxbb_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &gxbb_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &gxbb_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &gxbb_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &gxbb_fclk_div7_div.hw, [CLKID_VDEC_1_SEL] = &gxbb_vdec_1_sel.hw, [CLKID_VDEC_1_DIV] = &gxbb_vdec_1_div.hw, [CLKID_VDEC_1] = &gxbb_vdec_1.hw, [CLKID_VDEC_HEVC_SEL] = &gxbb_vdec_hevc_sel.hw, [CLKID_VDEC_HEVC_DIV] = &gxbb_vdec_hevc_div.hw, [CLKID_VDEC_HEVC] = &gxbb_vdec_hevc.hw, [CLKID_GEN_CLK_SEL] = &gxbb_gen_clk_sel.hw, [CLKID_GEN_CLK_DIV] = &gxbb_gen_clk_div.hw, [CLKID_GEN_CLK] = &gxbb_gen_clk.hw, [CLKID_FIXED_PLL_DCO] = &gxbb_fixed_pll_dco.hw, [CLKID_HDMI_PLL_DCO] = &gxbb_hdmi_pll_dco.hw, [CLKID_HDMI_PLL_OD] = &gxbb_hdmi_pll_od.hw, [CLKID_HDMI_PLL_OD2] = &gxbb_hdmi_pll_od2.hw, [CLKID_SYS_PLL_DCO] = &gxbb_sys_pll_dco.hw, [CLKID_GP0_PLL_DCO] = &gxbb_gp0_pll_dco.hw, [CLKID_VID_PLL_DIV] = &gxbb_vid_pll_div.hw, [CLKID_VID_PLL_SEL] = &gxbb_vid_pll_sel.hw, [CLKID_VID_PLL] = &gxbb_vid_pll.hw, [CLKID_VCLK_SEL] = &gxbb_vclk_sel.hw, [CLKID_VCLK2_SEL] = &gxbb_vclk2_sel.hw, [CLKID_VCLK_INPUT] = &gxbb_vclk_input.hw, [CLKID_VCLK2_INPUT] = &gxbb_vclk2_input.hw, [CLKID_VCLK_DIV] = &gxbb_vclk_div.hw, [CLKID_VCLK2_DIV] = &gxbb_vclk2_div.hw, [CLKID_VCLK] = &gxbb_vclk.hw, [CLKID_VCLK2] = &gxbb_vclk2.hw, [CLKID_VCLK_DIV1] = &gxbb_vclk_div1.hw, [CLKID_VCLK_DIV2_EN] = &gxbb_vclk_div2_en.hw, [CLKID_VCLK_DIV2] = &gxbb_vclk_div2.hw, [CLKID_VCLK_DIV4_EN] = &gxbb_vclk_div4_en.hw, [CLKID_VCLK_DIV4] = &gxbb_vclk_div4.hw, [CLKID_VCLK_DIV6_EN] = &gxbb_vclk_div6_en.hw, [CLKID_VCLK_DIV6] = &gxbb_vclk_div6.hw, [CLKID_VCLK_DIV12_EN] = &gxbb_vclk_div12_en.hw, [CLKID_VCLK_DIV12] = &gxbb_vclk_div12.hw, [CLKID_VCLK2_DIV1] = &gxbb_vclk2_div1.hw, [CLKID_VCLK2_DIV2_EN] = &gxbb_vclk2_div2_en.hw, [CLKID_VCLK2_DIV2] = &gxbb_vclk2_div2.hw, [CLKID_VCLK2_DIV4_EN] = &gxbb_vclk2_div4_en.hw, [CLKID_VCLK2_DIV4] = &gxbb_vclk2_div4.hw, [CLKID_VCLK2_DIV6_EN] = &gxbb_vclk2_div6_en.hw, [CLKID_VCLK2_DIV6] = &gxbb_vclk2_div6.hw, [CLKID_VCLK2_DIV12_EN] = &gxbb_vclk2_div12_en.hw, [CLKID_VCLK2_DIV12] = &gxbb_vclk2_div12.hw, [CLKID_CTS_ENCI_SEL] = &gxbb_cts_enci_sel.hw, [CLKID_CTS_ENCP_SEL] = &gxbb_cts_encp_sel.hw, [CLKID_CTS_VDAC_SEL] = &gxbb_cts_vdac_sel.hw, [CLKID_HDMI_TX_SEL] = &gxbb_hdmi_tx_sel.hw, [CLKID_CTS_ENCI] = &gxbb_cts_enci.hw, [CLKID_CTS_ENCP] = &gxbb_cts_encp.hw, [CLKID_CTS_VDAC] = &gxbb_cts_vdac.hw, [CLKID_HDMI_TX] = &gxbb_hdmi_tx.hw, [CLKID_HDMI_SEL] = &gxbb_hdmi_sel.hw, [CLKID_HDMI_DIV] = &gxbb_hdmi_div.hw, [CLKID_HDMI] = &gxbb_hdmi.hw, }; static struct clk_hw *gxl_hw_clks[] = { [CLKID_SYS_PLL] = &gxbb_sys_pll.hw, [CLKID_HDMI_PLL] = &gxl_hdmi_pll.hw, [CLKID_FIXED_PLL] = &gxbb_fixed_pll.hw, [CLKID_FCLK_DIV2] = &gxbb_fclk_div2.hw, [CLKID_FCLK_DIV3] = &gxbb_fclk_div3.hw, [CLKID_FCLK_DIV4] = &gxbb_fclk_div4.hw, [CLKID_FCLK_DIV5] = &gxbb_fclk_div5.hw, [CLKID_FCLK_DIV7] = &gxbb_fclk_div7.hw, [CLKID_GP0_PLL] = &gxbb_gp0_pll.hw, [CLKID_MPEG_SEL] = &gxbb_mpeg_clk_sel.hw, [CLKID_MPEG_DIV] = &gxbb_mpeg_clk_div.hw, [CLKID_CLK81] = &gxbb_clk81.hw, [CLKID_MPLL0] = &gxbb_mpll0.hw, [CLKID_MPLL1] = &gxbb_mpll1.hw, [CLKID_MPLL2] = &gxbb_mpll2.hw, [CLKID_DDR] = &gxbb_ddr.hw, [CLKID_DOS] = &gxbb_dos.hw, [CLKID_ISA] = &gxbb_isa.hw, [CLKID_PL301] = &gxbb_pl301.hw, [CLKID_PERIPHS] = &gxbb_periphs.hw, [CLKID_SPICC] = &gxbb_spicc.hw, [CLKID_I2C] = &gxbb_i2c.hw, [CLKID_SAR_ADC] = &gxbb_sar_adc.hw, [CLKID_SMART_CARD] = &gxbb_smart_card.hw, [CLKID_RNG0] = &gxbb_rng0.hw, [CLKID_UART0] = &gxbb_uart0.hw, [CLKID_SDHC] = &gxbb_sdhc.hw, [CLKID_STREAM] = &gxbb_stream.hw, [CLKID_ASYNC_FIFO] = &gxbb_async_fifo.hw, [CLKID_SDIO] = &gxbb_sdio.hw, [CLKID_ABUF] = &gxbb_abuf.hw, [CLKID_HIU_IFACE] = &gxbb_hiu_iface.hw, [CLKID_ASSIST_MISC] = &gxbb_assist_misc.hw, [CLKID_SPI] = &gxbb_spi.hw, [CLKID_I2S_SPDIF] = &gxbb_i2s_spdif.hw, [CLKID_ETH] = &gxbb_eth.hw, [CLKID_DEMUX] = &gxbb_demux.hw, [CLKID_AIU_GLUE] = &gxbb_aiu_glue.hw, [CLKID_IEC958] = &gxbb_iec958.hw, [CLKID_I2S_OUT] = &gxbb_i2s_out.hw, [CLKID_AMCLK] = &gxbb_amclk.hw, [CLKID_AIFIFO2] = &gxbb_aififo2.hw, [CLKID_MIXER] = &gxbb_mixer.hw, [CLKID_MIXER_IFACE] = &gxbb_mixer_iface.hw, [CLKID_ADC] = &gxbb_adc.hw, [CLKID_BLKMV] = &gxbb_blkmv.hw, [CLKID_AIU] = &gxbb_aiu.hw, [CLKID_UART1] = &gxbb_uart1.hw, [CLKID_G2D] = &gxbb_g2d.hw, [CLKID_USB0] = &gxbb_usb0.hw, [CLKID_USB1] = &gxbb_usb1.hw, [CLKID_RESET] = &gxbb_reset.hw, [CLKID_NAND] = &gxbb_nand.hw, [CLKID_DOS_PARSER] = &gxbb_dos_parser.hw, [CLKID_USB] = &gxbb_usb.hw, [CLKID_VDIN1] = &gxbb_vdin1.hw, [CLKID_AHB_ARB0] = &gxbb_ahb_arb0.hw, [CLKID_EFUSE] = &gxbb_efuse.hw, [CLKID_BOOT_ROM] = &gxbb_boot_rom.hw, [CLKID_AHB_DATA_BUS] = &gxbb_ahb_data_bus.hw, [CLKID_AHB_CTRL_BUS] = &gxbb_ahb_ctrl_bus.hw, [CLKID_HDMI_INTR_SYNC] = &gxbb_hdmi_intr_sync.hw, [CLKID_HDMI_PCLK] = &gxbb_hdmi_pclk.hw, [CLKID_USB1_DDR_BRIDGE] = &gxbb_usb1_ddr_bridge.hw, [CLKID_USB0_DDR_BRIDGE] = &gxbb_usb0_ddr_bridge.hw, [CLKID_MMC_PCLK] = &gxbb_mmc_pclk.hw, [CLKID_DVIN] = &gxbb_dvin.hw, [CLKID_UART2] = &gxbb_uart2.hw, [CLKID_SANA] = &gxbb_sana.hw, [CLKID_VPU_INTR] = &gxbb_vpu_intr.hw, [CLKID_SEC_AHB_AHB3_BRIDGE] = &gxbb_sec_ahb_ahb3_bridge.hw, [CLKID_CLK81_A53] = &gxbb_clk81_a53.hw, [CLKID_VCLK2_VENCI0] = &gxbb_vclk2_venci0.hw, [CLKID_VCLK2_VENCI1] = &gxbb_vclk2_venci1.hw, [CLKID_VCLK2_VENCP0] = &gxbb_vclk2_vencp0.hw, [CLKID_VCLK2_VENCP1] = &gxbb_vclk2_vencp1.hw, [CLKID_GCLK_VENCI_INT0] = &gxbb_gclk_venci_int0.hw, [CLKID_GCLK_VENCI_INT] = &gxbb_gclk_vencp_int.hw, [CLKID_DAC_CLK] = &gxbb_dac_clk.hw, [CLKID_AOCLK_GATE] = &gxbb_aoclk_gate.hw, [CLKID_IEC958_GATE] = &gxbb_iec958_gate.hw, [CLKID_ENC480P] = &gxbb_enc480p.hw, [CLKID_RNG1] = &gxbb_rng1.hw, [CLKID_GCLK_VENCI_INT1] = &gxbb_gclk_venci_int1.hw, [CLKID_VCLK2_VENCLMCC] = &gxbb_vclk2_venclmcc.hw, [CLKID_VCLK2_VENCL] = &gxbb_vclk2_vencl.hw, [CLKID_VCLK_OTHER] = &gxbb_vclk_other.hw, [CLKID_EDP] = &gxbb_edp.hw, [CLKID_AO_MEDIA_CPU] = &gxbb_ao_media_cpu.hw, [CLKID_AO_AHB_SRAM] = &gxbb_ao_ahb_sram.hw, [CLKID_AO_AHB_BUS] = &gxbb_ao_ahb_bus.hw, [CLKID_AO_IFACE] = &gxbb_ao_iface.hw, [CLKID_AO_I2C] = &gxbb_ao_i2c.hw, [CLKID_SD_EMMC_A] = &gxbb_emmc_a.hw, [CLKID_SD_EMMC_B] = &gxbb_emmc_b.hw, [CLKID_SD_EMMC_C] = &gxbb_emmc_c.hw, [CLKID_SAR_ADC_CLK] = &gxbb_sar_adc_clk.hw, [CLKID_SAR_ADC_SEL] = &gxbb_sar_adc_clk_sel.hw, [CLKID_SAR_ADC_DIV] = &gxbb_sar_adc_clk_div.hw, [CLKID_MALI_0_SEL] = &gxbb_mali_0_sel.hw, [CLKID_MALI_0_DIV] = &gxbb_mali_0_div.hw, [CLKID_MALI_0] = &gxbb_mali_0.hw, [CLKID_MALI_1_SEL] = &gxbb_mali_1_sel.hw, [CLKID_MALI_1_DIV] = &gxbb_mali_1_div.hw, [CLKID_MALI_1] = &gxbb_mali_1.hw, [CLKID_MALI] = &gxbb_mali.hw, [CLKID_CTS_AMCLK] = &gxbb_cts_amclk.hw, [CLKID_CTS_AMCLK_SEL] = &gxbb_cts_amclk_sel.hw, [CLKID_CTS_AMCLK_DIV] = &gxbb_cts_amclk_div.hw, [CLKID_CTS_MCLK_I958] = &gxbb_cts_mclk_i958.hw, [CLKID_CTS_MCLK_I958_SEL] = &gxbb_cts_mclk_i958_sel.hw, [CLKID_CTS_MCLK_I958_DIV] = &gxbb_cts_mclk_i958_div.hw, [CLKID_CTS_I958] = &gxbb_cts_i958.hw, [CLKID_32K_CLK] = &gxbb_32k_clk.hw, [CLKID_32K_CLK_SEL] = &gxbb_32k_clk_sel.hw, [CLKID_32K_CLK_DIV] = &gxbb_32k_clk_div.hw, [CLKID_SD_EMMC_A_CLK0_SEL] = &gxbb_sd_emmc_a_clk0_sel.hw, [CLKID_SD_EMMC_A_CLK0_DIV] = &gxbb_sd_emmc_a_clk0_div.hw, [CLKID_SD_EMMC_A_CLK0] = &gxbb_sd_emmc_a_clk0.hw, [CLKID_SD_EMMC_B_CLK0_SEL] = &gxbb_sd_emmc_b_clk0_sel.hw, [CLKID_SD_EMMC_B_CLK0_DIV] = &gxbb_sd_emmc_b_clk0_div.hw, [CLKID_SD_EMMC_B_CLK0] = &gxbb_sd_emmc_b_clk0.hw, [CLKID_SD_EMMC_C_CLK0_SEL] = &gxbb_sd_emmc_c_clk0_sel.hw, [CLKID_SD_EMMC_C_CLK0_DIV] = &gxbb_sd_emmc_c_clk0_div.hw, [CLKID_SD_EMMC_C_CLK0] = &gxbb_sd_emmc_c_clk0.hw, [CLKID_VPU_0_SEL] = &gxbb_vpu_0_sel.hw, [CLKID_VPU_0_DIV] = &gxbb_vpu_0_div.hw, [CLKID_VPU_0] = &gxbb_vpu_0.hw, [CLKID_VPU_1_SEL] = &gxbb_vpu_1_sel.hw, [CLKID_VPU_1_DIV] = &gxbb_vpu_1_div.hw, [CLKID_VPU_1] = &gxbb_vpu_1.hw, [CLKID_VPU] = &gxbb_vpu.hw, [CLKID_VAPB_0_SEL] = &gxbb_vapb_0_sel.hw, [CLKID_VAPB_0_DIV] = &gxbb_vapb_0_div.hw, [CLKID_VAPB_0] = &gxbb_vapb_0.hw, [CLKID_VAPB_1_SEL] = &gxbb_vapb_1_sel.hw, [CLKID_VAPB_1_DIV] = &gxbb_vapb_1_div.hw, [CLKID_VAPB_1] = &gxbb_vapb_1.hw, [CLKID_VAPB_SEL] = &gxbb_vapb_sel.hw, [CLKID_VAPB] = &gxbb_vapb.hw, [CLKID_MPLL0_DIV] = &gxl_mpll0_div.hw, [CLKID_MPLL1_DIV] = &gxbb_mpll1_div.hw, [CLKID_MPLL2_DIV] = &gxbb_mpll2_div.hw, [CLKID_MPLL_PREDIV] = &gxbb_mpll_prediv.hw, [CLKID_FCLK_DIV2_DIV] = &gxbb_fclk_div2_div.hw, [CLKID_FCLK_DIV3_DIV] = &gxbb_fclk_div3_div.hw, [CLKID_FCLK_DIV4_DIV] = &gxbb_fclk_div4_div.hw, [CLKID_FCLK_DIV5_DIV] = &gxbb_fclk_div5_div.hw, [CLKID_FCLK_DIV7_DIV] = &gxbb_fclk_div7_div.hw, [CLKID_VDEC_1_SEL] = &gxbb_vdec_1_sel.hw, [CLKID_VDEC_1_DIV] = &gxbb_vdec_1_div.hw, [CLKID_VDEC_1] = &gxbb_vdec_1.hw, [CLKID_VDEC_HEVC_SEL] = &gxbb_vdec_hevc_sel.hw, [CLKID_VDEC_HEVC_DIV] = &gxbb_vdec_hevc_div.hw, [CLKID_VDEC_HEVC] = &gxbb_vdec_hevc.hw, [CLKID_GEN_CLK_SEL] = &gxbb_gen_clk_sel.hw, [CLKID_GEN_CLK_DIV] = &gxbb_gen_clk_div.hw, [CLKID_GEN_CLK] = &gxbb_gen_clk.hw, [CLKID_FIXED_PLL_DCO] = &gxbb_fixed_pll_dco.hw, [CLKID_HDMI_PLL_DCO] = &gxl_hdmi_pll_dco.hw, [CLKID_HDMI_PLL_OD] = &gxl_hdmi_pll_od.hw, [CLKID_HDMI_PLL_OD2] = &gxl_hdmi_pll_od2.hw, [CLKID_SYS_PLL_DCO] = &gxbb_sys_pll_dco.hw, [CLKID_GP0_PLL_DCO] = &gxl_gp0_pll_dco.hw, [CLKID_VID_PLL_DIV] = &gxbb_vid_pll_div.hw, [CLKID_VID_PLL_SEL] = &gxbb_vid_pll_sel.hw, [CLKID_VID_PLL] = &gxbb_vid_pll.hw, [CLKID_VCLK_SEL] = &gxbb_vclk_sel.hw, [CLKID_VCLK2_SEL] = &gxbb_vclk2_sel.hw, [CLKID_VCLK_INPUT] = &gxbb_vclk_input.hw, [CLKID_VCLK2_INPUT] = &gxbb_vclk2_input.hw, [CLKID_VCLK_DIV] = &gxbb_vclk_div.hw, [CLKID_VCLK2_DIV] = &gxbb_vclk2_div.hw, [CLKID_VCLK] = &gxbb_vclk.hw, [CLKID_VCLK2] = &gxbb_vclk2.hw, [CLKID_VCLK_DIV1] = &gxbb_vclk_div1.hw, [CLKID_VCLK_DIV2_EN] = &gxbb_vclk_div2_en.hw, [CLKID_VCLK_DIV2] = &gxbb_vclk_div2.hw, [CLKID_VCLK_DIV4_EN] = &gxbb_vclk_div4_en.hw, [CLKID_VCLK_DIV4] = &gxbb_vclk_div4.hw, [CLKID_VCLK_DIV6_EN] = &gxbb_vclk_div6_en.hw, [CLKID_VCLK_DIV6] = &gxbb_vclk_div6.hw, [CLKID_VCLK_DIV12_EN] = &gxbb_vclk_div12_en.hw, [CLKID_VCLK_DIV12] = &gxbb_vclk_div12.hw, [CLKID_VCLK2_DIV1] = &gxbb_vclk2_div1.hw, [CLKID_VCLK2_DIV2_EN] = &gxbb_vclk2_div2_en.hw, [CLKID_VCLK2_DIV2] = &gxbb_vclk2_div2.hw, [CLKID_VCLK2_DIV4_EN] = &gxbb_vclk2_div4_en.hw, [CLKID_VCLK2_DIV4] = &gxbb_vclk2_div4.hw, [CLKID_VCLK2_DIV6_EN] = &gxbb_vclk2_div6_en.hw, [CLKID_VCLK2_DIV6] = &gxbb_vclk2_div6.hw, [CLKID_VCLK2_DIV12_EN] = &gxbb_vclk2_div12_en.hw, [CLKID_VCLK2_DIV12] = &gxbb_vclk2_div12.hw, [CLKID_CTS_ENCI_SEL] = &gxbb_cts_enci_sel.hw, [CLKID_CTS_ENCP_SEL] = &gxbb_cts_encp_sel.hw, [CLKID_CTS_VDAC_SEL] = &gxbb_cts_vdac_sel.hw, [CLKID_HDMI_TX_SEL] = &gxbb_hdmi_tx_sel.hw, [CLKID_CTS_ENCI] = &gxbb_cts_enci.hw, [CLKID_CTS_ENCP] = &gxbb_cts_encp.hw, [CLKID_CTS_VDAC] = &gxbb_cts_vdac.hw, [CLKID_HDMI_TX] = &gxbb_hdmi_tx.hw, [CLKID_HDMI_SEL] = &gxbb_hdmi_sel.hw, [CLKID_HDMI_DIV] = &gxbb_hdmi_div.hw, [CLKID_HDMI] = &gxbb_hdmi.hw, [CLKID_ACODEC] = &gxl_acodec.hw, }; static struct clk_regmap *const gxbb_clk_regmaps[] = { &gxbb_clk81, &gxbb_ddr, &gxbb_dos, &gxbb_isa, &gxbb_pl301, &gxbb_periphs, &gxbb_spicc, &gxbb_i2c, &gxbb_sar_adc, &gxbb_smart_card, &gxbb_rng0, &gxbb_uart0, &gxbb_sdhc, &gxbb_stream, &gxbb_async_fifo, &gxbb_sdio, &gxbb_abuf, &gxbb_hiu_iface, &gxbb_assist_misc, &gxbb_spi, &gxbb_i2s_spdif, &gxbb_eth, &gxbb_demux, &gxbb_aiu_glue, &gxbb_iec958, &gxbb_i2s_out, &gxbb_amclk, &gxbb_aififo2, &gxbb_mixer, &gxbb_mixer_iface, &gxbb_adc, &gxbb_blkmv, &gxbb_aiu, &gxbb_uart1, &gxbb_g2d, &gxbb_usb0, &gxbb_usb1, &gxbb_reset, &gxbb_nand, &gxbb_dos_parser, &gxbb_usb, &gxbb_vdin1, &gxbb_ahb_arb0, &gxbb_efuse, &gxbb_boot_rom, &gxbb_ahb_data_bus, &gxbb_ahb_ctrl_bus, &gxbb_hdmi_intr_sync, &gxbb_hdmi_pclk, &gxbb_usb1_ddr_bridge, &gxbb_usb0_ddr_bridge, &gxbb_mmc_pclk, &gxbb_dvin, &gxbb_uart2, &gxbb_sana, &gxbb_vpu_intr, &gxbb_sec_ahb_ahb3_bridge, &gxbb_clk81_a53, &gxbb_vclk2_venci0, &gxbb_vclk2_venci1, &gxbb_vclk2_vencp0, &gxbb_vclk2_vencp1, &gxbb_gclk_venci_int0, &gxbb_gclk_vencp_int, &gxbb_dac_clk, &gxbb_aoclk_gate, &gxbb_iec958_gate, &gxbb_enc480p, &gxbb_rng1, &gxbb_gclk_venci_int1, &gxbb_vclk2_venclmcc, &gxbb_vclk2_vencl, &gxbb_vclk_other, &gxbb_edp, &gxbb_ao_media_cpu, &gxbb_ao_ahb_sram, &gxbb_ao_ahb_bus, &gxbb_ao_iface, &gxbb_ao_i2c, &gxbb_emmc_a, &gxbb_emmc_b, &gxbb_emmc_c, &gxbb_sar_adc_clk, &gxbb_mali_0, &gxbb_mali_1, &gxbb_cts_amclk, &gxbb_cts_mclk_i958, &gxbb_32k_clk, &gxbb_sd_emmc_a_clk0, &gxbb_sd_emmc_b_clk0, &gxbb_sd_emmc_c_clk0, &gxbb_vpu_0, &gxbb_vpu_1, &gxbb_vapb_0, &gxbb_vapb_1, &gxbb_vapb, &gxbb_mpeg_clk_div, &gxbb_sar_adc_clk_div, &gxbb_mali_0_div, &gxbb_mali_1_div, &gxbb_cts_mclk_i958_div, &gxbb_32k_clk_div, &gxbb_sd_emmc_a_clk0_div, &gxbb_sd_emmc_b_clk0_div, &gxbb_sd_emmc_c_clk0_div, &gxbb_vpu_0_div, &gxbb_vpu_1_div, &gxbb_vapb_0_div, &gxbb_vapb_1_div, &gxbb_mpeg_clk_sel, &gxbb_sar_adc_clk_sel, &gxbb_mali_0_sel, &gxbb_mali_1_sel, &gxbb_mali, &gxbb_cts_amclk_sel, &gxbb_cts_mclk_i958_sel, &gxbb_cts_i958, &gxbb_32k_clk_sel, &gxbb_sd_emmc_a_clk0_sel, &gxbb_sd_emmc_b_clk0_sel, &gxbb_sd_emmc_c_clk0_sel, &gxbb_vpu_0_sel, &gxbb_vpu_1_sel, &gxbb_vpu, &gxbb_vapb_0_sel, &gxbb_vapb_1_sel, &gxbb_vapb_sel, &gxbb_mpll0, &gxbb_mpll1, &gxbb_mpll2, &gxbb_mpll0_div, &gxbb_mpll1_div, &gxbb_mpll2_div, &gxbb_cts_amclk_div, &gxbb_fixed_pll, &gxbb_sys_pll, &gxbb_mpll_prediv, &gxbb_fclk_div2, &gxbb_fclk_div3, &gxbb_fclk_div4, &gxbb_fclk_div5, &gxbb_fclk_div7, &gxbb_vdec_1_sel, &gxbb_vdec_1_div, &gxbb_vdec_1, &gxbb_vdec_hevc_sel, &gxbb_vdec_hevc_div, &gxbb_vdec_hevc, &gxbb_gen_clk_sel, &gxbb_gen_clk_div, &gxbb_gen_clk, &gxbb_fixed_pll_dco, &gxbb_sys_pll_dco, &gxbb_gp0_pll, &gxbb_vid_pll, &gxbb_vid_pll_sel, &gxbb_vid_pll_div, &gxbb_vclk, &gxbb_vclk_sel, &gxbb_vclk_div, &gxbb_vclk_input, &gxbb_vclk_div1, &gxbb_vclk_div2_en, &gxbb_vclk_div4_en, &gxbb_vclk_div6_en, &gxbb_vclk_div12_en, &gxbb_vclk2, &gxbb_vclk2_sel, &gxbb_vclk2_div, &gxbb_vclk2_input, &gxbb_vclk2_div1, &gxbb_vclk2_div2_en, &gxbb_vclk2_div4_en, &gxbb_vclk2_div6_en, &gxbb_vclk2_div12_en, &gxbb_cts_enci, &gxbb_cts_enci_sel, &gxbb_cts_encp, &gxbb_cts_encp_sel, &gxbb_cts_vdac, &gxbb_cts_vdac_sel, &gxbb_hdmi_tx, &gxbb_hdmi_tx_sel, &gxbb_hdmi_sel, &gxbb_hdmi_div, &gxbb_hdmi, &gxbb_gp0_pll_dco, &gxbb_hdmi_pll, &gxbb_hdmi_pll_od, &gxbb_hdmi_pll_od2, &gxbb_hdmi_pll_dco, }; static struct clk_regmap *const gxl_clk_regmaps[] = { &gxbb_clk81, &gxbb_ddr, &gxbb_dos, &gxbb_isa, &gxbb_pl301, &gxbb_periphs, &gxbb_spicc, &gxbb_i2c, &gxbb_sar_adc, &gxbb_smart_card, &gxbb_rng0, &gxbb_uart0, &gxbb_sdhc, &gxbb_stream, &gxbb_async_fifo, &gxbb_sdio, &gxbb_abuf, &gxbb_hiu_iface, &gxbb_assist_misc, &gxbb_spi, &gxbb_i2s_spdif, &gxbb_eth, &gxbb_demux, &gxbb_aiu_glue, &gxbb_iec958, &gxbb_i2s_out, &gxbb_amclk, &gxbb_aififo2, &gxbb_mixer, &gxbb_mixer_iface, &gxbb_adc, &gxbb_blkmv, &gxbb_aiu, &gxbb_uart1, &gxbb_g2d, &gxbb_usb0, &gxbb_usb1, &gxbb_reset, &gxbb_nand, &gxbb_dos_parser, &gxbb_usb, &gxbb_vdin1, &gxbb_ahb_arb0, &gxbb_efuse, &gxbb_boot_rom, &gxbb_ahb_data_bus, &gxbb_ahb_ctrl_bus, &gxbb_hdmi_intr_sync, &gxbb_hdmi_pclk, &gxbb_usb1_ddr_bridge, &gxbb_usb0_ddr_bridge, &gxbb_mmc_pclk, &gxbb_dvin, &gxbb_uart2, &gxbb_sana, &gxbb_vpu_intr, &gxbb_sec_ahb_ahb3_bridge, &gxbb_clk81_a53, &gxbb_vclk2_venci0, &gxbb_vclk2_venci1, &gxbb_vclk2_vencp0, &gxbb_vclk2_vencp1, &gxbb_gclk_venci_int0, &gxbb_gclk_vencp_int, &gxbb_dac_clk, &gxbb_aoclk_gate, &gxbb_iec958_gate, &gxbb_enc480p, &gxbb_rng1, &gxbb_gclk_venci_int1, &gxbb_vclk2_venclmcc, &gxbb_vclk2_vencl, &gxbb_vclk_other, &gxbb_edp, &gxbb_ao_media_cpu, &gxbb_ao_ahb_sram, &gxbb_ao_ahb_bus, &gxbb_ao_iface, &gxbb_ao_i2c, &gxbb_emmc_a, &gxbb_emmc_b, &gxbb_emmc_c, &gxbb_sar_adc_clk, &gxbb_mali_0, &gxbb_mali_1, &gxbb_cts_amclk, &gxbb_cts_mclk_i958, &gxbb_32k_clk, &gxbb_sd_emmc_a_clk0, &gxbb_sd_emmc_b_clk0, &gxbb_sd_emmc_c_clk0, &gxbb_vpu_0, &gxbb_vpu_1, &gxbb_vapb_0, &gxbb_vapb_1, &gxbb_vapb, &gxbb_mpeg_clk_div, &gxbb_sar_adc_clk_div, &gxbb_mali_0_div, &gxbb_mali_1_div, &gxbb_cts_mclk_i958_div, &gxbb_32k_clk_div, &gxbb_sd_emmc_a_clk0_div, &gxbb_sd_emmc_b_clk0_div, &gxbb_sd_emmc_c_clk0_div, &gxbb_vpu_0_div, &gxbb_vpu_1_div, &gxbb_vapb_0_div, &gxbb_vapb_1_div, &gxbb_mpeg_clk_sel, &gxbb_sar_adc_clk_sel, &gxbb_mali_0_sel, &gxbb_mali_1_sel, &gxbb_mali, &gxbb_cts_amclk_sel, &gxbb_cts_mclk_i958_sel, &gxbb_cts_i958, &gxbb_32k_clk_sel, &gxbb_sd_emmc_a_clk0_sel, &gxbb_sd_emmc_b_clk0_sel, &gxbb_sd_emmc_c_clk0_sel, &gxbb_vpu_0_sel, &gxbb_vpu_1_sel, &gxbb_vpu, &gxbb_vapb_0_sel, &gxbb_vapb_1_sel, &gxbb_vapb_sel, &gxbb_mpll0, &gxbb_mpll1, &gxbb_mpll2, &gxl_mpll0_div, &gxbb_mpll1_div, &gxbb_mpll2_div, &gxbb_cts_amclk_div, &gxbb_fixed_pll, &gxbb_sys_pll, &gxbb_mpll_prediv, &gxbb_fclk_div2, &gxbb_fclk_div3, &gxbb_fclk_div4, &gxbb_fclk_div5, &gxbb_fclk_div7, &gxbb_vdec_1_sel, &gxbb_vdec_1_div, &gxbb_vdec_1, &gxbb_vdec_hevc_sel, &gxbb_vdec_hevc_div, &gxbb_vdec_hevc, &gxbb_gen_clk_sel, &gxbb_gen_clk_div, &gxbb_gen_clk, &gxbb_fixed_pll_dco, &gxbb_sys_pll_dco, &gxbb_gp0_pll, &gxbb_vid_pll, &gxbb_vid_pll_sel, &gxbb_vid_pll_div, &gxbb_vclk, &gxbb_vclk_sel, &gxbb_vclk_div, &gxbb_vclk_input, &gxbb_vclk_div1, &gxbb_vclk_div2_en, &gxbb_vclk_div4_en, &gxbb_vclk_div6_en, &gxbb_vclk_div12_en, &gxbb_vclk2, &gxbb_vclk2_sel, &gxbb_vclk2_div, &gxbb_vclk2_input, &gxbb_vclk2_div1, &gxbb_vclk2_div2_en, &gxbb_vclk2_div4_en, &gxbb_vclk2_div6_en, &gxbb_vclk2_div12_en, &gxbb_cts_enci, &gxbb_cts_enci_sel, &gxbb_cts_encp, &gxbb_cts_encp_sel, &gxbb_cts_vdac, &gxbb_cts_vdac_sel, &gxbb_hdmi_tx, &gxbb_hdmi_tx_sel, &gxbb_hdmi_sel, &gxbb_hdmi_div, &gxbb_hdmi, &gxl_gp0_pll_dco, &gxl_hdmi_pll, &gxl_hdmi_pll_od, &gxl_hdmi_pll_od2, &gxl_hdmi_pll_dco, &gxl_acodec, }; static const struct meson_eeclkc_data gxbb_clkc_data = { .regmap_clks = gxbb_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(gxbb_clk_regmaps), .hw_clks = { .hws = gxbb_hw_clks, .num = ARRAY_SIZE(gxbb_hw_clks), }, }; static const struct meson_eeclkc_data gxl_clkc_data = { .regmap_clks = gxl_clk_regmaps, .regmap_clk_num = ARRAY_SIZE(gxl_clk_regmaps), .hw_clks = { .hws = gxl_hw_clks, .num = ARRAY_SIZE(gxl_hw_clks), }, }; static const struct of_device_id clkc_match_table[] = { { .compatible = "amlogic,gxbb-clkc", .data = &gxbb_clkc_data }, { .compatible = "amlogic,gxl-clkc", .data = &gxl_clkc_data }, {}, }; MODULE_DEVICE_TABLE(of, clkc_match_table); static struct platform_driver gxbb_driver = { .probe = meson_eeclkc_probe, .driver = { .name = "gxbb-clkc", .of_match_table = clkc_match_table, }, }; module_platform_driver(gxbb_driver); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/gxbb.c
// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (c) 2019 Amlogic, Inc. All rights reserved. * Author: Jian Hu <[email protected]> * * Copyright (c) 2023, SberDevices. All Rights Reserved. * Author: Dmitry Rokosov <[email protected]> */ #include <linux/clk-provider.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include "a1-peripherals.h" #include "clk-dualdiv.h" #include "clk-regmap.h" #include "meson-clkc-utils.h" #include <dt-bindings/clock/amlogic,a1-peripherals-clkc.h> static struct clk_regmap xtal_in = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_OSCIN_CTRL, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "xtal_in", .ops = &clk_regmap_gate_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap fixpll_in = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_OSCIN_CTRL, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "fixpll_in", .ops = &clk_regmap_gate_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap usb_phy_in = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_OSCIN_CTRL, .bit_idx = 2, }, .hw.init = &(struct clk_init_data) { .name = "usb_phy_in", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap usb_ctrl_in = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_OSCIN_CTRL, .bit_idx = 3, }, .hw.init = &(struct clk_init_data) { .name = "usb_ctrl_in", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap hifipll_in = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_OSCIN_CTRL, .bit_idx = 4, }, .hw.init = &(struct clk_init_data) { .name = "hifipll_in", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap syspll_in = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_OSCIN_CTRL, .bit_idx = 5, }, .hw.init = &(struct clk_init_data) { .name = "syspll_in", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap dds_in = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_OSCIN_CTRL, .bit_idx = 6, }, .hw.init = &(struct clk_init_data) { .name = "dds_in", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap rtc_32k_in = { .data = &(struct clk_regmap_gate_data){ .offset = RTC_BY_OSCIN_CTRL0, .bit_idx = 31, }, .hw.init = &(struct clk_init_data) { .name = "rtc_32k_in", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static const struct meson_clk_dualdiv_param clk_32k_div_table[] = { { .dual = 1, .n1 = 733, .m1 = 8, .n2 = 732, .m2 = 11, }, {} }; static struct clk_regmap rtc_32k_div = { .data = &(struct meson_clk_dualdiv_data){ .n1 = { .reg_off = RTC_BY_OSCIN_CTRL0, .shift = 0, .width = 12, }, .n2 = { .reg_off = RTC_BY_OSCIN_CTRL0, .shift = 12, .width = 12, }, .m1 = { .reg_off = RTC_BY_OSCIN_CTRL1, .shift = 0, .width = 12, }, .m2 = { .reg_off = RTC_BY_OSCIN_CTRL1, .shift = 12, .width = 12, }, .dual = { .reg_off = RTC_BY_OSCIN_CTRL0, .shift = 28, .width = 1, }, .table = clk_32k_div_table, }, .hw.init = &(struct clk_init_data){ .name = "rtc_32k_div", .ops = &meson_clk_dualdiv_ops, .parent_hws = (const struct clk_hw *[]) { &rtc_32k_in.hw }, .num_parents = 1, }, }; static struct clk_regmap rtc_32k_xtal = { .data = &(struct clk_regmap_gate_data){ .offset = RTC_BY_OSCIN_CTRL1, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "rtc_32k_xtal", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &rtc_32k_in.hw }, .num_parents = 1, }, }; static struct clk_regmap rtc_32k_sel = { .data = &(struct clk_regmap_mux_data) { .offset = RTC_CTRL, .mask = 0x3, .shift = 0, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "rtc_32k_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &rtc_32k_xtal.hw, &rtc_32k_div.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap rtc = { .data = &(struct clk_regmap_gate_data){ .offset = RTC_BY_OSCIN_CTRL0, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "rtc", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &rtc_32k_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static u32 mux_table_sys[] = { 0, 1, 2, 3, 7 }; static const struct clk_parent_data sys_parents[] = { { .fw_name = "xtal" }, { .fw_name = "fclk_div2" }, { .fw_name = "fclk_div3" }, { .fw_name = "fclk_div5" }, { .hw = &rtc.hw }, }; static struct clk_regmap sys_b_sel = { .data = &(struct clk_regmap_mux_data){ .offset = SYS_CLK_CTRL0, .mask = 0x7, .shift = 26, .table = mux_table_sys, }, .hw.init = &(struct clk_init_data){ .name = "sys_b_sel", .ops = &clk_regmap_mux_ro_ops, .parent_data = sys_parents, .num_parents = ARRAY_SIZE(sys_parents), }, }; static struct clk_regmap sys_b_div = { .data = &(struct clk_regmap_div_data){ .offset = SYS_CLK_CTRL0, .shift = 16, .width = 10, }, .hw.init = &(struct clk_init_data){ .name = "sys_b_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sys_b_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sys_b = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_CLK_CTRL0, .bit_idx = 29, }, .hw.init = &(struct clk_init_data) { .name = "sys_b", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sys_b_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sys_a_sel = { .data = &(struct clk_regmap_mux_data){ .offset = SYS_CLK_CTRL0, .mask = 0x7, .shift = 10, .table = mux_table_sys, }, .hw.init = &(struct clk_init_data){ .name = "sys_a_sel", .ops = &clk_regmap_mux_ro_ops, .parent_data = sys_parents, .num_parents = ARRAY_SIZE(sys_parents), }, }; static struct clk_regmap sys_a_div = { .data = &(struct clk_regmap_div_data){ .offset = SYS_CLK_CTRL0, .shift = 0, .width = 10, }, .hw.init = &(struct clk_init_data){ .name = "sys_a_div", .ops = &clk_regmap_divider_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sys_a_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sys_a = { .data = &(struct clk_regmap_gate_data){ .offset = SYS_CLK_CTRL0, .bit_idx = 13, }, .hw.init = &(struct clk_init_data) { .name = "sys_a", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sys_a_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sys = { .data = &(struct clk_regmap_mux_data){ .offset = SYS_CLK_CTRL0, .mask = 0x1, .shift = 31, }, .hw.init = &(struct clk_init_data){ .name = "sys", .ops = &clk_regmap_mux_ro_ops, .parent_hws = (const struct clk_hw *[]) { &sys_a.hw, &sys_b.hw, }, .num_parents = 2, /* * This clock is used by APB bus which is set in boot ROM code * and is required by the platform to operate correctly. * Until the following condition are met, we need this clock to * be marked as critical: * a) Mark the clock used by a firmware resource, if possible * b) CCF has a clock hand-off mechanism to make the sure the * clock stays on until the proper driver comes along */ .flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, }, }; static u32 mux_table_dsp_ab[] = { 0, 1, 2, 3, 4, 7 }; static const struct clk_parent_data dsp_ab_parent_data[] = { { .fw_name = "xtal", }, { .fw_name = "fclk_div2", }, { .fw_name = "fclk_div3", }, { .fw_name = "fclk_div5", }, { .fw_name = "hifi_pll", }, { .hw = &rtc.hw }, }; static struct clk_regmap dspa_a_sel = { .data = &(struct clk_regmap_mux_data){ .offset = DSPA_CLK_CTRL0, .mask = 0x7, .shift = 10, .table = mux_table_dsp_ab, }, .hw.init = &(struct clk_init_data){ .name = "dspa_a_sel", .ops = &clk_regmap_mux_ops, .parent_data = dsp_ab_parent_data, .num_parents = ARRAY_SIZE(dsp_ab_parent_data), }, }; static struct clk_regmap dspa_a_div = { .data = &(struct clk_regmap_div_data){ .offset = DSPA_CLK_CTRL0, .shift = 0, .width = 10, }, .hw.init = &(struct clk_init_data){ .name = "dspa_a_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &dspa_a_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspa_a = { .data = &(struct clk_regmap_gate_data){ .offset = DSPA_CLK_CTRL0, .bit_idx = 13, }, .hw.init = &(struct clk_init_data) { .name = "dspa_a", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &dspa_a_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspa_b_sel = { .data = &(struct clk_regmap_mux_data){ .offset = DSPA_CLK_CTRL0, .mask = 0x7, .shift = 26, .table = mux_table_dsp_ab, }, .hw.init = &(struct clk_init_data){ .name = "dspa_b_sel", .ops = &clk_regmap_mux_ops, .parent_data = dsp_ab_parent_data, .num_parents = ARRAY_SIZE(dsp_ab_parent_data), }, }; static struct clk_regmap dspa_b_div = { .data = &(struct clk_regmap_div_data){ .offset = DSPA_CLK_CTRL0, .shift = 16, .width = 10, }, .hw.init = &(struct clk_init_data){ .name = "dspa_b_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &dspa_b_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspa_b = { .data = &(struct clk_regmap_gate_data){ .offset = DSPA_CLK_CTRL0, .bit_idx = 29, }, .hw.init = &(struct clk_init_data) { .name = "dspa_b", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &dspa_b_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspa_sel = { .data = &(struct clk_regmap_mux_data){ .offset = DSPA_CLK_CTRL0, .mask = 0x1, .shift = 15, }, .hw.init = &(struct clk_init_data){ .name = "dspa_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &dspa_a.hw, &dspa_b.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspa_en = { .data = &(struct clk_regmap_gate_data){ .offset = DSPA_CLK_EN, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "dspa_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &dspa_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspa_en_nic = { .data = &(struct clk_regmap_gate_data){ .offset = DSPA_CLK_EN, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "dspa_en_nic", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &dspa_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspb_a_sel = { .data = &(struct clk_regmap_mux_data){ .offset = DSPB_CLK_CTRL0, .mask = 0x7, .shift = 10, .table = mux_table_dsp_ab, }, .hw.init = &(struct clk_init_data){ .name = "dspb_a_sel", .ops = &clk_regmap_mux_ops, .parent_data = dsp_ab_parent_data, .num_parents = ARRAY_SIZE(dsp_ab_parent_data), }, }; static struct clk_regmap dspb_a_div = { .data = &(struct clk_regmap_div_data){ .offset = DSPB_CLK_CTRL0, .shift = 0, .width = 10, }, .hw.init = &(struct clk_init_data){ .name = "dspb_a_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &dspb_a_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspb_a = { .data = &(struct clk_regmap_gate_data){ .offset = DSPB_CLK_CTRL0, .bit_idx = 13, }, .hw.init = &(struct clk_init_data) { .name = "dspb_a", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &dspb_a_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspb_b_sel = { .data = &(struct clk_regmap_mux_data){ .offset = DSPB_CLK_CTRL0, .mask = 0x7, .shift = 26, .table = mux_table_dsp_ab, }, .hw.init = &(struct clk_init_data){ .name = "dspb_b_sel", .ops = &clk_regmap_mux_ops, .parent_data = dsp_ab_parent_data, .num_parents = ARRAY_SIZE(dsp_ab_parent_data), }, }; static struct clk_regmap dspb_b_div = { .data = &(struct clk_regmap_div_data){ .offset = DSPB_CLK_CTRL0, .shift = 16, .width = 10, }, .hw.init = &(struct clk_init_data){ .name = "dspb_b_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &dspb_b_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspb_b = { .data = &(struct clk_regmap_gate_data){ .offset = DSPB_CLK_CTRL0, .bit_idx = 29, }, .hw.init = &(struct clk_init_data) { .name = "dspb_b", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &dspb_b_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspb_sel = { .data = &(struct clk_regmap_mux_data){ .offset = DSPB_CLK_CTRL0, .mask = 0x1, .shift = 15, }, .hw.init = &(struct clk_init_data){ .name = "dspb_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &dspb_a.hw, &dspb_b.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspb_en = { .data = &(struct clk_regmap_gate_data){ .offset = DSPB_CLK_EN, .bit_idx = 1, }, .hw.init = &(struct clk_init_data) { .name = "dspb_en", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &dspb_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dspb_en_nic = { .data = &(struct clk_regmap_gate_data){ .offset = DSPB_CLK_EN, .bit_idx = 0, }, .hw.init = &(struct clk_init_data) { .name = "dspb_en_nic", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &dspb_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap clk_24m = { .data = &(struct clk_regmap_gate_data){ .offset = CLK12_24_CTRL, .bit_idx = 11, }, .hw.init = &(struct clk_init_data) { .name = "24m", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_fixed_factor clk_24m_div2 = { .mult = 1, .div = 2, .hw.init = &(struct clk_init_data){ .name = "24m_div2", .ops = &clk_fixed_factor_ops, .parent_hws = (const struct clk_hw *[]) { &clk_24m.hw }, .num_parents = 1, }, }; static struct clk_regmap clk_12m = { .data = &(struct clk_regmap_gate_data){ .offset = CLK12_24_CTRL, .bit_idx = 10, }, .hw.init = &(struct clk_init_data) { .name = "12m", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &clk_24m_div2.hw }, .num_parents = 1, }, }; static struct clk_regmap fclk_div2_divn_pre = { .data = &(struct clk_regmap_div_data){ .offset = CLK12_24_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div2_divn_pre", .ops = &clk_regmap_divider_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "fclk_div2", }, .num_parents = 1, }, }; static struct clk_regmap fclk_div2_divn = { .data = &(struct clk_regmap_gate_data){ .offset = CLK12_24_CTRL, .bit_idx = 12, }, .hw.init = &(struct clk_init_data){ .name = "fclk_div2_divn", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &fclk_div2_divn_pre.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* * the index 2 is sys_pll_div16, it will be implemented in the CPU clock driver, * the index 4 is the clock measurement source, it's not supported yet */ static u32 gen_table[] = { 0, 1, 3, 5, 6, 7, 8 }; static const struct clk_parent_data gen_parent_data[] = { { .fw_name = "xtal", }, { .hw = &rtc.hw }, { .fw_name = "hifi_pll", }, { .fw_name = "fclk_div2", }, { .fw_name = "fclk_div3", }, { .fw_name = "fclk_div5", }, { .fw_name = "fclk_div7", }, }; static struct clk_regmap gen_sel = { .data = &(struct clk_regmap_mux_data){ .offset = GEN_CLK_CTRL, .mask = 0xf, .shift = 12, .table = gen_table, }, .hw.init = &(struct clk_init_data){ .name = "gen_sel", .ops = &clk_regmap_mux_ops, .parent_data = gen_parent_data, .num_parents = ARRAY_SIZE(gen_parent_data), /* * The GEN clock can be connected to an external pad, so it * may be set up directly from the device tree. Additionally, * the GEN clock can be inherited from a more accurate RTC * clock, so in certain situations, it may be necessary * to freeze its parent. */ .flags = CLK_SET_RATE_NO_REPARENT, }, }; static struct clk_regmap gen_div = { .data = &(struct clk_regmap_div_data){ .offset = GEN_CLK_CTRL, .shift = 0, .width = 11, }, .hw.init = &(struct clk_init_data){ .name = "gen_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &gen_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap gen = { .data = &(struct clk_regmap_gate_data){ .offset = GEN_CLK_CTRL, .bit_idx = 11, }, .hw.init = &(struct clk_init_data) { .name = "gen", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &gen_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap saradc_sel = { .data = &(struct clk_regmap_mux_data){ .offset = SAR_ADC_CLK_CTRL, .mask = 0x1, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "saradc_sel", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &sys.hw, }, }, .num_parents = 2, }, }; static struct clk_regmap saradc_div = { .data = &(struct clk_regmap_div_data){ .offset = SAR_ADC_CLK_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "saradc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &saradc_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap saradc = { .data = &(struct clk_regmap_gate_data){ .offset = SAR_ADC_CLK_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "saradc", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &saradc_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_parent_data pwm_abcd_parents[] = { { .fw_name = "xtal", }, { .hw = &sys.hw }, { .hw = &rtc.hw }, }; static struct clk_regmap pwm_a_sel = { .data = &(struct clk_regmap_mux_data){ .offset = PWM_CLK_AB_CTRL, .mask = 0x1, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "pwm_a_sel", .ops = &clk_regmap_mux_ops, .parent_data = pwm_abcd_parents, .num_parents = ARRAY_SIZE(pwm_abcd_parents), }, }; static struct clk_regmap pwm_a_div = { .data = &(struct clk_regmap_div_data){ .offset = PWM_CLK_AB_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "pwm_a_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_a_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_a = { .data = &(struct clk_regmap_gate_data){ .offset = PWM_CLK_AB_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "pwm_a", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_a_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_b_sel = { .data = &(struct clk_regmap_mux_data){ .offset = PWM_CLK_AB_CTRL, .mask = 0x1, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "pwm_b_sel", .ops = &clk_regmap_mux_ops, .parent_data = pwm_abcd_parents, .num_parents = ARRAY_SIZE(pwm_abcd_parents), }, }; static struct clk_regmap pwm_b_div = { .data = &(struct clk_regmap_div_data){ .offset = PWM_CLK_AB_CTRL, .shift = 16, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "pwm_b_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_b_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_b = { .data = &(struct clk_regmap_gate_data){ .offset = PWM_CLK_AB_CTRL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "pwm_b", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_b_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_c_sel = { .data = &(struct clk_regmap_mux_data){ .offset = PWM_CLK_CD_CTRL, .mask = 0x1, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "pwm_c_sel", .ops = &clk_regmap_mux_ops, .parent_data = pwm_abcd_parents, .num_parents = ARRAY_SIZE(pwm_abcd_parents), }, }; static struct clk_regmap pwm_c_div = { .data = &(struct clk_regmap_div_data){ .offset = PWM_CLK_CD_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "pwm_c_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_c_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_c = { .data = &(struct clk_regmap_gate_data){ .offset = PWM_CLK_CD_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "pwm_c", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_c_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_d_sel = { .data = &(struct clk_regmap_mux_data){ .offset = PWM_CLK_CD_CTRL, .mask = 0x1, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "pwm_d_sel", .ops = &clk_regmap_mux_ops, .parent_data = pwm_abcd_parents, .num_parents = ARRAY_SIZE(pwm_abcd_parents), }, }; static struct clk_regmap pwm_d_div = { .data = &(struct clk_regmap_div_data){ .offset = PWM_CLK_CD_CTRL, .shift = 16, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "pwm_d_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_d_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_d = { .data = &(struct clk_regmap_gate_data){ .offset = PWM_CLK_CD_CTRL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "pwm_d", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_d_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_parent_data pwm_ef_parents[] = { { .fw_name = "xtal", }, { .hw = &sys.hw }, { .fw_name = "fclk_div5", }, { .hw = &rtc.hw }, }; static struct clk_regmap pwm_e_sel = { .data = &(struct clk_regmap_mux_data){ .offset = PWM_CLK_EF_CTRL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "pwm_e_sel", .ops = &clk_regmap_mux_ops, .parent_data = pwm_ef_parents, .num_parents = ARRAY_SIZE(pwm_ef_parents), }, }; static struct clk_regmap pwm_e_div = { .data = &(struct clk_regmap_div_data){ .offset = PWM_CLK_EF_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "pwm_e_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_e_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_e = { .data = &(struct clk_regmap_gate_data){ .offset = PWM_CLK_EF_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "pwm_e", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_e_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_f_sel = { .data = &(struct clk_regmap_mux_data){ .offset = PWM_CLK_EF_CTRL, .mask = 0x3, .shift = 25, }, .hw.init = &(struct clk_init_data){ .name = "pwm_f_sel", .ops = &clk_regmap_mux_ops, .parent_data = pwm_ef_parents, .num_parents = ARRAY_SIZE(pwm_ef_parents), }, }; static struct clk_regmap pwm_f_div = { .data = &(struct clk_regmap_div_data){ .offset = PWM_CLK_EF_CTRL, .shift = 16, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "pwm_f_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_f_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap pwm_f = { .data = &(struct clk_regmap_gate_data){ .offset = PWM_CLK_EF_CTRL, .bit_idx = 24, }, .hw.init = &(struct clk_init_data) { .name = "pwm_f", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &pwm_f_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; /* * spicc clk * fdiv2 |\ |\ _____ * ---------| |---DIV--| | | | spicc out * ---------| | | |-----|GATE |--------- * ..... |/ | / |_____| * --------------------|/ * 24M */ static const struct clk_parent_data spicc_spifc_parents[] = { { .fw_name = "fclk_div2"}, { .fw_name = "fclk_div3"}, { .fw_name = "fclk_div5"}, { .fw_name = "hifi_pll" }, }; static struct clk_regmap spicc_sel = { .data = &(struct clk_regmap_mux_data){ .offset = SPICC_CLK_CTRL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "spicc_sel", .ops = &clk_regmap_mux_ops, .parent_data = spicc_spifc_parents, .num_parents = ARRAY_SIZE(spicc_spifc_parents), }, }; static struct clk_regmap spicc_div = { .data = &(struct clk_regmap_div_data){ .offset = SPICC_CLK_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "spicc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &spicc_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap spicc_sel2 = { .data = &(struct clk_regmap_mux_data){ .offset = SPICC_CLK_CTRL, .mask = 0x1, .shift = 15, }, .hw.init = &(struct clk_init_data){ .name = "spicc_sel2", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .hw = &spicc_div.hw }, { .fw_name = "xtal", }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap spicc = { .data = &(struct clk_regmap_gate_data){ .offset = SPICC_CLK_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "spicc", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &spicc_sel2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap ts_div = { .data = &(struct clk_regmap_div_data){ .offset = TS_CLK_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "ts_div", .ops = &clk_regmap_divider_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap ts = { .data = &(struct clk_regmap_gate_data){ .offset = TS_CLK_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "ts", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &ts_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap spifc_sel = { .data = &(struct clk_regmap_mux_data){ .offset = SPIFC_CLK_CTRL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "spifc_sel", .ops = &clk_regmap_mux_ops, .parent_data = spicc_spifc_parents, .num_parents = ARRAY_SIZE(spicc_spifc_parents), }, }; static struct clk_regmap spifc_div = { .data = &(struct clk_regmap_div_data){ .offset = SPIFC_CLK_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "spifc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &spifc_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap spifc_sel2 = { .data = &(struct clk_regmap_mux_data){ .offset = SPIFC_CLK_CTRL, .mask = 0x1, .shift = 15, }, .hw.init = &(struct clk_init_data){ .name = "spifc_sel2", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .hw = &spifc_div.hw }, { .fw_name = "xtal", }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap spifc = { .data = &(struct clk_regmap_gate_data){ .offset = SPIFC_CLK_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "spifc", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &spifc_sel2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_parent_data usb_bus_parents[] = { { .fw_name = "xtal", }, { .hw = &sys.hw }, { .fw_name = "fclk_div3", }, { .fw_name = "fclk_div5", }, }; static struct clk_regmap usb_bus_sel = { .data = &(struct clk_regmap_mux_data){ .offset = USB_BUSCLK_CTRL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "usb_bus_sel", .ops = &clk_regmap_mux_ops, .parent_data = usb_bus_parents, .num_parents = ARRAY_SIZE(usb_bus_parents), .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap usb_bus_div = { .data = &(struct clk_regmap_div_data){ .offset = USB_BUSCLK_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "usb_bus_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &usb_bus_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap usb_bus = { .data = &(struct clk_regmap_gate_data){ .offset = USB_BUSCLK_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "usb_bus", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &usb_bus_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const struct clk_parent_data sd_emmc_psram_dmc_parents[] = { { .fw_name = "fclk_div2", }, { .fw_name = "fclk_div3", }, { .fw_name = "fclk_div5", }, { .fw_name = "hifi_pll", }, }; static struct clk_regmap sd_emmc_sel = { .data = &(struct clk_regmap_mux_data){ .offset = SD_EMMC_CLK_CTRL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_sel", .ops = &clk_regmap_mux_ops, .parent_data = sd_emmc_psram_dmc_parents, .num_parents = ARRAY_SIZE(sd_emmc_psram_dmc_parents), }, }; static struct clk_regmap sd_emmc_div = { .data = &(struct clk_regmap_div_data){ .offset = SD_EMMC_CLK_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &sd_emmc_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sd_emmc_sel2 = { .data = &(struct clk_regmap_mux_data){ .offset = SD_EMMC_CLK_CTRL, .mask = 0x1, .shift = 15, }, .hw.init = &(struct clk_init_data){ .name = "sd_emmc_sel2", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .hw = &sd_emmc_div.hw }, { .fw_name = "xtal", }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap sd_emmc = { .data = &(struct clk_regmap_gate_data){ .offset = SD_EMMC_CLK_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "sd_emmc", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &sd_emmc_sel2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap psram_sel = { .data = &(struct clk_regmap_mux_data){ .offset = PSRAM_CLK_CTRL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "psram_sel", .ops = &clk_regmap_mux_ops, .parent_data = sd_emmc_psram_dmc_parents, .num_parents = ARRAY_SIZE(sd_emmc_psram_dmc_parents), }, }; static struct clk_regmap psram_div = { .data = &(struct clk_regmap_div_data){ .offset = PSRAM_CLK_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "psram_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &psram_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap psram_sel2 = { .data = &(struct clk_regmap_mux_data){ .offset = PSRAM_CLK_CTRL, .mask = 0x1, .shift = 15, }, .hw.init = &(struct clk_init_data){ .name = "psram_sel2", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .hw = &psram_div.hw }, { .fw_name = "xtal", }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap psram = { .data = &(struct clk_regmap_gate_data){ .offset = PSRAM_CLK_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "psram", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &psram_sel2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dmc_sel = { .data = &(struct clk_regmap_mux_data){ .offset = DMC_CLK_CTRL, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "dmc_sel", .ops = &clk_regmap_mux_ops, .parent_data = sd_emmc_psram_dmc_parents, .num_parents = ARRAY_SIZE(sd_emmc_psram_dmc_parents), }, }; static struct clk_regmap dmc_div = { .data = &(struct clk_regmap_div_data){ .offset = DMC_CLK_CTRL, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "dmc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &dmc_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dmc_sel2 = { .data = &(struct clk_regmap_mux_data){ .offset = DMC_CLK_CTRL, .mask = 0x1, .shift = 15, }, .hw.init = &(struct clk_init_data){ .name = "dmc_sel2", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .hw = &dmc_div.hw }, { .fw_name = "xtal", }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap dmc = { .data = &(struct clk_regmap_gate_data){ .offset = DMC_CLK_CTRL, .bit_idx = 8, }, .hw.init = &(struct clk_init_data) { .name = "dmc", .ops = &clk_regmap_gate_ro_ops, .parent_hws = (const struct clk_hw *[]) { &dmc_sel2.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap ceca_32k_in = { .data = &(struct clk_regmap_gate_data){ .offset = CECA_CLK_CTRL0, .bit_idx = 31, }, .hw.init = &(struct clk_init_data) { .name = "ceca_32k_in", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap ceca_32k_div = { .data = &(struct meson_clk_dualdiv_data){ .n1 = { .reg_off = CECA_CLK_CTRL0, .shift = 0, .width = 12, }, .n2 = { .reg_off = CECA_CLK_CTRL0, .shift = 12, .width = 12, }, .m1 = { .reg_off = CECA_CLK_CTRL1, .shift = 0, .width = 12, }, .m2 = { .reg_off = CECA_CLK_CTRL1, .shift = 12, .width = 12, }, .dual = { .reg_off = CECA_CLK_CTRL0, .shift = 28, .width = 1, }, .table = clk_32k_div_table, }, .hw.init = &(struct clk_init_data){ .name = "ceca_32k_div", .ops = &meson_clk_dualdiv_ops, .parent_hws = (const struct clk_hw *[]) { &ceca_32k_in.hw }, .num_parents = 1, }, }; static struct clk_regmap ceca_32k_sel_pre = { .data = &(struct clk_regmap_mux_data) { .offset = CECA_CLK_CTRL1, .mask = 0x1, .shift = 24, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "ceca_32k_sel_pre", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &ceca_32k_div.hw, &ceca_32k_in.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap ceca_32k_sel = { .data = &(struct clk_regmap_mux_data) { .offset = CECA_CLK_CTRL1, .mask = 0x1, .shift = 31, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "ceca_32k_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &ceca_32k_sel_pre.hw, &rtc.hw, }, .num_parents = 2, }, }; static struct clk_regmap ceca_32k_out = { .data = &(struct clk_regmap_gate_data){ .offset = CECA_CLK_CTRL0, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "ceca_32k_out", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &ceca_32k_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap cecb_32k_in = { .data = &(struct clk_regmap_gate_data){ .offset = CECB_CLK_CTRL0, .bit_idx = 31, }, .hw.init = &(struct clk_init_data) { .name = "cecb_32k_in", .ops = &clk_regmap_gate_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap cecb_32k_div = { .data = &(struct meson_clk_dualdiv_data){ .n1 = { .reg_off = CECB_CLK_CTRL0, .shift = 0, .width = 12, }, .n2 = { .reg_off = CECB_CLK_CTRL0, .shift = 12, .width = 12, }, .m1 = { .reg_off = CECB_CLK_CTRL1, .shift = 0, .width = 12, }, .m2 = { .reg_off = CECB_CLK_CTRL1, .shift = 12, .width = 12, }, .dual = { .reg_off = CECB_CLK_CTRL0, .shift = 28, .width = 1, }, .table = clk_32k_div_table, }, .hw.init = &(struct clk_init_data){ .name = "cecb_32k_div", .ops = &meson_clk_dualdiv_ops, .parent_hws = (const struct clk_hw *[]) { &cecb_32k_in.hw }, .num_parents = 1, }, }; static struct clk_regmap cecb_32k_sel_pre = { .data = &(struct clk_regmap_mux_data) { .offset = CECB_CLK_CTRL1, .mask = 0x1, .shift = 24, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cecb_32k_sel_pre", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &cecb_32k_div.hw, &cecb_32k_in.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap cecb_32k_sel = { .data = &(struct clk_regmap_mux_data) { .offset = CECB_CLK_CTRL1, .mask = 0x1, .shift = 31, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "cecb_32k_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &cecb_32k_sel_pre.hw, &rtc.hw, }, .num_parents = 2, }, }; static struct clk_regmap cecb_32k_out = { .data = &(struct clk_regmap_gate_data){ .offset = CECB_CLK_CTRL0, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "cecb_32k_out", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &cecb_32k_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; #define MESON_GATE(_name, _reg, _bit) \ MESON_PCLK(_name, _reg, _bit, &sys.hw) static MESON_GATE(clktree, SYS_CLK_EN0, 0); static MESON_GATE(reset_ctrl, SYS_CLK_EN0, 1); static MESON_GATE(analog_ctrl, SYS_CLK_EN0, 2); static MESON_GATE(pwr_ctrl, SYS_CLK_EN0, 3); static MESON_GATE(pad_ctrl, SYS_CLK_EN0, 4); static MESON_GATE(sys_ctrl, SYS_CLK_EN0, 5); static MESON_GATE(temp_sensor, SYS_CLK_EN0, 6); static MESON_GATE(am2axi_dev, SYS_CLK_EN0, 7); static MESON_GATE(spicc_b, SYS_CLK_EN0, 8); static MESON_GATE(spicc_a, SYS_CLK_EN0, 9); static MESON_GATE(msr, SYS_CLK_EN0, 10); static MESON_GATE(audio, SYS_CLK_EN0, 11); static MESON_GATE(jtag_ctrl, SYS_CLK_EN0, 12); static MESON_GATE(saradc_en, SYS_CLK_EN0, 13); static MESON_GATE(pwm_ef, SYS_CLK_EN0, 14); static MESON_GATE(pwm_cd, SYS_CLK_EN0, 15); static MESON_GATE(pwm_ab, SYS_CLK_EN0, 16); static MESON_GATE(cec, SYS_CLK_EN0, 17); static MESON_GATE(i2c_s, SYS_CLK_EN0, 18); static MESON_GATE(ir_ctrl, SYS_CLK_EN0, 19); static MESON_GATE(i2c_m_d, SYS_CLK_EN0, 20); static MESON_GATE(i2c_m_c, SYS_CLK_EN0, 21); static MESON_GATE(i2c_m_b, SYS_CLK_EN0, 22); static MESON_GATE(i2c_m_a, SYS_CLK_EN0, 23); static MESON_GATE(acodec, SYS_CLK_EN0, 24); static MESON_GATE(otp, SYS_CLK_EN0, 25); static MESON_GATE(sd_emmc_a, SYS_CLK_EN0, 26); static MESON_GATE(usb_phy, SYS_CLK_EN0, 27); static MESON_GATE(usb_ctrl, SYS_CLK_EN0, 28); static MESON_GATE(sys_dspb, SYS_CLK_EN0, 29); static MESON_GATE(sys_dspa, SYS_CLK_EN0, 30); static MESON_GATE(dma, SYS_CLK_EN0, 31); static MESON_GATE(irq_ctrl, SYS_CLK_EN1, 0); static MESON_GATE(nic, SYS_CLK_EN1, 1); static MESON_GATE(gic, SYS_CLK_EN1, 2); static MESON_GATE(uart_c, SYS_CLK_EN1, 3); static MESON_GATE(uart_b, SYS_CLK_EN1, 4); static MESON_GATE(uart_a, SYS_CLK_EN1, 5); static MESON_GATE(sys_psram, SYS_CLK_EN1, 6); static MESON_GATE(rsa, SYS_CLK_EN1, 8); static MESON_GATE(coresight, SYS_CLK_EN1, 9); static MESON_GATE(am2axi_vad, AXI_CLK_EN, 0); static MESON_GATE(audio_vad, AXI_CLK_EN, 1); static MESON_GATE(axi_dmc, AXI_CLK_EN, 3); static MESON_GATE(axi_psram, AXI_CLK_EN, 4); static MESON_GATE(ramb, AXI_CLK_EN, 5); static MESON_GATE(rama, AXI_CLK_EN, 6); static MESON_GATE(axi_spifc, AXI_CLK_EN, 7); static MESON_GATE(axi_nic, AXI_CLK_EN, 8); static MESON_GATE(axi_dma, AXI_CLK_EN, 9); static MESON_GATE(cpu_ctrl, AXI_CLK_EN, 10); static MESON_GATE(rom, AXI_CLK_EN, 11); static MESON_GATE(prod_i2c, AXI_CLK_EN, 12); /* Array of all clocks registered by this provider */ static struct clk_hw *a1_periphs_hw_clks[] = { [CLKID_XTAL_IN] = &xtal_in.hw, [CLKID_FIXPLL_IN] = &fixpll_in.hw, [CLKID_USB_PHY_IN] = &usb_phy_in.hw, [CLKID_USB_CTRL_IN] = &usb_ctrl_in.hw, [CLKID_HIFIPLL_IN] = &hifipll_in.hw, [CLKID_SYSPLL_IN] = &syspll_in.hw, [CLKID_DDS_IN] = &dds_in.hw, [CLKID_SYS] = &sys.hw, [CLKID_CLKTREE] = &clktree.hw, [CLKID_RESET_CTRL] = &reset_ctrl.hw, [CLKID_ANALOG_CTRL] = &analog_ctrl.hw, [CLKID_PWR_CTRL] = &pwr_ctrl.hw, [CLKID_PAD_CTRL] = &pad_ctrl.hw, [CLKID_SYS_CTRL] = &sys_ctrl.hw, [CLKID_TEMP_SENSOR] = &temp_sensor.hw, [CLKID_AM2AXI_DIV] = &am2axi_dev.hw, [CLKID_SPICC_B] = &spicc_b.hw, [CLKID_SPICC_A] = &spicc_a.hw, [CLKID_MSR] = &msr.hw, [CLKID_AUDIO] = &audio.hw, [CLKID_JTAG_CTRL] = &jtag_ctrl.hw, [CLKID_SARADC_EN] = &saradc_en.hw, [CLKID_PWM_EF] = &pwm_ef.hw, [CLKID_PWM_CD] = &pwm_cd.hw, [CLKID_PWM_AB] = &pwm_ab.hw, [CLKID_CEC] = &cec.hw, [CLKID_I2C_S] = &i2c_s.hw, [CLKID_IR_CTRL] = &ir_ctrl.hw, [CLKID_I2C_M_D] = &i2c_m_d.hw, [CLKID_I2C_M_C] = &i2c_m_c.hw, [CLKID_I2C_M_B] = &i2c_m_b.hw, [CLKID_I2C_M_A] = &i2c_m_a.hw, [CLKID_ACODEC] = &acodec.hw, [CLKID_OTP] = &otp.hw, [CLKID_SD_EMMC_A] = &sd_emmc_a.hw, [CLKID_USB_PHY] = &usb_phy.hw, [CLKID_USB_CTRL] = &usb_ctrl.hw, [CLKID_SYS_DSPB] = &sys_dspb.hw, [CLKID_SYS_DSPA] = &sys_dspa.hw, [CLKID_DMA] = &dma.hw, [CLKID_IRQ_CTRL] = &irq_ctrl.hw, [CLKID_NIC] = &nic.hw, [CLKID_GIC] = &gic.hw, [CLKID_UART_C] = &uart_c.hw, [CLKID_UART_B] = &uart_b.hw, [CLKID_UART_A] = &uart_a.hw, [CLKID_SYS_PSRAM] = &sys_psram.hw, [CLKID_RSA] = &rsa.hw, [CLKID_CORESIGHT] = &coresight.hw, [CLKID_AM2AXI_VAD] = &am2axi_vad.hw, [CLKID_AUDIO_VAD] = &audio_vad.hw, [CLKID_AXI_DMC] = &axi_dmc.hw, [CLKID_AXI_PSRAM] = &axi_psram.hw, [CLKID_RAMB] = &ramb.hw, [CLKID_RAMA] = &rama.hw, [CLKID_AXI_SPIFC] = &axi_spifc.hw, [CLKID_AXI_NIC] = &axi_nic.hw, [CLKID_AXI_DMA] = &axi_dma.hw, [CLKID_CPU_CTRL] = &cpu_ctrl.hw, [CLKID_ROM] = &rom.hw, [CLKID_PROC_I2C] = &prod_i2c.hw, [CLKID_DSPA_SEL] = &dspa_sel.hw, [CLKID_DSPB_SEL] = &dspb_sel.hw, [CLKID_DSPA_EN] = &dspa_en.hw, [CLKID_DSPA_EN_NIC] = &dspa_en_nic.hw, [CLKID_DSPB_EN] = &dspb_en.hw, [CLKID_DSPB_EN_NIC] = &dspb_en_nic.hw, [CLKID_RTC] = &rtc.hw, [CLKID_CECA_32K] = &ceca_32k_out.hw, [CLKID_CECB_32K] = &cecb_32k_out.hw, [CLKID_24M] = &clk_24m.hw, [CLKID_12M] = &clk_12m.hw, [CLKID_FCLK_DIV2_DIVN] = &fclk_div2_divn.hw, [CLKID_GEN] = &gen.hw, [CLKID_SARADC_SEL] = &saradc_sel.hw, [CLKID_SARADC] = &saradc.hw, [CLKID_PWM_A] = &pwm_a.hw, [CLKID_PWM_B] = &pwm_b.hw, [CLKID_PWM_C] = &pwm_c.hw, [CLKID_PWM_D] = &pwm_d.hw, [CLKID_PWM_E] = &pwm_e.hw, [CLKID_PWM_F] = &pwm_f.hw, [CLKID_SPICC] = &spicc.hw, [CLKID_TS] = &ts.hw, [CLKID_SPIFC] = &spifc.hw, [CLKID_USB_BUS] = &usb_bus.hw, [CLKID_SD_EMMC] = &sd_emmc.hw, [CLKID_PSRAM] = &psram.hw, [CLKID_DMC] = &dmc.hw, [CLKID_SYS_A_SEL] = &sys_a_sel.hw, [CLKID_SYS_A_DIV] = &sys_a_div.hw, [CLKID_SYS_A] = &sys_a.hw, [CLKID_SYS_B_SEL] = &sys_b_sel.hw, [CLKID_SYS_B_DIV] = &sys_b_div.hw, [CLKID_SYS_B] = &sys_b.hw, [CLKID_DSPA_A_SEL] = &dspa_a_sel.hw, [CLKID_DSPA_A_DIV] = &dspa_a_div.hw, [CLKID_DSPA_A] = &dspa_a.hw, [CLKID_DSPA_B_SEL] = &dspa_b_sel.hw, [CLKID_DSPA_B_DIV] = &dspa_b_div.hw, [CLKID_DSPA_B] = &dspa_b.hw, [CLKID_DSPB_A_SEL] = &dspb_a_sel.hw, [CLKID_DSPB_A_DIV] = &dspb_a_div.hw, [CLKID_DSPB_A] = &dspb_a.hw, [CLKID_DSPB_B_SEL] = &dspb_b_sel.hw, [CLKID_DSPB_B_DIV] = &dspb_b_div.hw, [CLKID_DSPB_B] = &dspb_b.hw, [CLKID_RTC_32K_IN] = &rtc_32k_in.hw, [CLKID_RTC_32K_DIV] = &rtc_32k_div.hw, [CLKID_RTC_32K_XTAL] = &rtc_32k_xtal.hw, [CLKID_RTC_32K_SEL] = &rtc_32k_sel.hw, [CLKID_CECB_32K_IN] = &cecb_32k_in.hw, [CLKID_CECB_32K_DIV] = &cecb_32k_div.hw, [CLKID_CECB_32K_SEL_PRE] = &cecb_32k_sel_pre.hw, [CLKID_CECB_32K_SEL] = &cecb_32k_sel.hw, [CLKID_CECA_32K_IN] = &ceca_32k_in.hw, [CLKID_CECA_32K_DIV] = &ceca_32k_div.hw, [CLKID_CECA_32K_SEL_PRE] = &ceca_32k_sel_pre.hw, [CLKID_CECA_32K_SEL] = &ceca_32k_sel.hw, [CLKID_DIV2_PRE] = &fclk_div2_divn_pre.hw, [CLKID_24M_DIV2] = &clk_24m_div2.hw, [CLKID_GEN_SEL] = &gen_sel.hw, [CLKID_GEN_DIV] = &gen_div.hw, [CLKID_SARADC_DIV] = &saradc_div.hw, [CLKID_PWM_A_SEL] = &pwm_a_sel.hw, [CLKID_PWM_A_DIV] = &pwm_a_div.hw, [CLKID_PWM_B_SEL] = &pwm_b_sel.hw, [CLKID_PWM_B_DIV] = &pwm_b_div.hw, [CLKID_PWM_C_SEL] = &pwm_c_sel.hw, [CLKID_PWM_C_DIV] = &pwm_c_div.hw, [CLKID_PWM_D_SEL] = &pwm_d_sel.hw, [CLKID_PWM_D_DIV] = &pwm_d_div.hw, [CLKID_PWM_E_SEL] = &pwm_e_sel.hw, [CLKID_PWM_E_DIV] = &pwm_e_div.hw, [CLKID_PWM_F_SEL] = &pwm_f_sel.hw, [CLKID_PWM_F_DIV] = &pwm_f_div.hw, [CLKID_SPICC_SEL] = &spicc_sel.hw, [CLKID_SPICC_DIV] = &spicc_div.hw, [CLKID_SPICC_SEL2] = &spicc_sel2.hw, [CLKID_TS_DIV] = &ts_div.hw, [CLKID_SPIFC_SEL] = &spifc_sel.hw, [CLKID_SPIFC_DIV] = &spifc_div.hw, [CLKID_SPIFC_SEL2] = &spifc_sel2.hw, [CLKID_USB_BUS_SEL] = &usb_bus_sel.hw, [CLKID_USB_BUS_DIV] = &usb_bus_div.hw, [CLKID_SD_EMMC_SEL] = &sd_emmc_sel.hw, [CLKID_SD_EMMC_DIV] = &sd_emmc_div.hw, [CLKID_SD_EMMC_SEL2] = &sd_emmc_sel2.hw, [CLKID_PSRAM_SEL] = &psram_sel.hw, [CLKID_PSRAM_DIV] = &psram_div.hw, [CLKID_PSRAM_SEL2] = &psram_sel2.hw, [CLKID_DMC_SEL] = &dmc_sel.hw, [CLKID_DMC_DIV] = &dmc_div.hw, [CLKID_DMC_SEL2] = &dmc_sel2.hw, }; /* Convenience table to populate regmap in .probe */ static struct clk_regmap *const a1_periphs_regmaps[] = { &xtal_in, &fixpll_in, &usb_phy_in, &usb_ctrl_in, &hifipll_in, &syspll_in, &dds_in, &sys, &clktree, &reset_ctrl, &analog_ctrl, &pwr_ctrl, &pad_ctrl, &sys_ctrl, &temp_sensor, &am2axi_dev, &spicc_b, &spicc_a, &msr, &audio, &jtag_ctrl, &saradc_en, &pwm_ef, &pwm_cd, &pwm_ab, &cec, &i2c_s, &ir_ctrl, &i2c_m_d, &i2c_m_c, &i2c_m_b, &i2c_m_a, &acodec, &otp, &sd_emmc_a, &usb_phy, &usb_ctrl, &sys_dspb, &sys_dspa, &dma, &irq_ctrl, &nic, &gic, &uart_c, &uart_b, &uart_a, &sys_psram, &rsa, &coresight, &am2axi_vad, &audio_vad, &axi_dmc, &axi_psram, &ramb, &rama, &axi_spifc, &axi_nic, &axi_dma, &cpu_ctrl, &rom, &prod_i2c, &dspa_sel, &dspb_sel, &dspa_en, &dspa_en_nic, &dspb_en, &dspb_en_nic, &rtc, &ceca_32k_out, &cecb_32k_out, &clk_24m, &clk_12m, &fclk_div2_divn, &gen, &saradc_sel, &saradc, &pwm_a, &pwm_b, &pwm_c, &pwm_d, &pwm_e, &pwm_f, &spicc, &ts, &spifc, &usb_bus, &sd_emmc, &psram, &dmc, &sys_a_sel, &sys_a_div, &sys_a, &sys_b_sel, &sys_b_div, &sys_b, &dspa_a_sel, &dspa_a_div, &dspa_a, &dspa_b_sel, &dspa_b_div, &dspa_b, &dspb_a_sel, &dspb_a_div, &dspb_a, &dspb_b_sel, &dspb_b_div, &dspb_b, &rtc_32k_in, &rtc_32k_div, &rtc_32k_xtal, &rtc_32k_sel, &cecb_32k_in, &cecb_32k_div, &cecb_32k_sel_pre, &cecb_32k_sel, &ceca_32k_in, &ceca_32k_div, &ceca_32k_sel_pre, &ceca_32k_sel, &fclk_div2_divn_pre, &gen_sel, &gen_div, &saradc_div, &pwm_a_sel, &pwm_a_div, &pwm_b_sel, &pwm_b_div, &pwm_c_sel, &pwm_c_div, &pwm_d_sel, &pwm_d_div, &pwm_e_sel, &pwm_e_div, &pwm_f_sel, &pwm_f_div, &spicc_sel, &spicc_div, &spicc_sel2, &ts_div, &spifc_sel, &spifc_div, &spifc_sel2, &usb_bus_sel, &usb_bus_div, &sd_emmc_sel, &sd_emmc_div, &sd_emmc_sel2, &psram_sel, &psram_div, &psram_sel2, &dmc_sel, &dmc_div, &dmc_sel2, }; static struct regmap_config a1_periphs_regmap_cfg = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, }; static struct meson_clk_hw_data a1_periphs_clks = { .hws = a1_periphs_hw_clks, .num = ARRAY_SIZE(a1_periphs_hw_clks), }; static int meson_a1_periphs_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; void __iomem *base; struct regmap *map; int clkid, i, err; base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) return dev_err_probe(dev, PTR_ERR(base), "can't ioremap resource\n"); map = devm_regmap_init_mmio(dev, base, &a1_periphs_regmap_cfg); if (IS_ERR(map)) return dev_err_probe(dev, PTR_ERR(map), "can't init regmap mmio region\n"); /* Populate regmap for the regmap backed clocks */ for (i = 0; i < ARRAY_SIZE(a1_periphs_regmaps); i++) a1_periphs_regmaps[i]->map = map; for (clkid = 0; clkid < a1_periphs_clks.num; clkid++) { err = devm_clk_hw_register(dev, a1_periphs_clks.hws[clkid]); if (err) return dev_err_probe(dev, err, "clock[%d] registration failed\n", clkid); } return devm_of_clk_add_hw_provider(dev, meson_clk_hw_get, &a1_periphs_clks); } static const struct of_device_id a1_periphs_clkc_match_table[] = { { .compatible = "amlogic,a1-peripherals-clkc", }, {} }; MODULE_DEVICE_TABLE(of, a1_periphs_clkc_match_table); static struct platform_driver a1_periphs_clkc_driver = { .probe = meson_a1_periphs_probe, .driver = { .name = "a1-peripherals-clkc", .of_match_table = a1_periphs_clkc_match_table, }, }; module_platform_driver(a1_periphs_clkc_driver); MODULE_AUTHOR("Jian Hu <[email protected]>"); MODULE_AUTHOR("Dmitry Rokosov <[email protected]>"); MODULE_LICENSE("GPL");
linux-master
drivers/clk/meson/a1-peripherals.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2019 BayLibre, SAS. * Author: Jerome Brunet <[email protected]> */ #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/mfd/syscon.h> #include <linux/regmap.h> #include <linux/module.h> #include "clk-regmap.h" #include "meson-eeclk.h" int meson_eeclkc_probe(struct platform_device *pdev) { const struct meson_eeclkc_data *data; struct device *dev = &pdev->dev; struct device_node *np; struct regmap *map; int ret, i; data = of_device_get_match_data(dev); if (!data) return -EINVAL; /* Get the hhi system controller node */ np = of_get_parent(dev->of_node); map = syscon_node_to_regmap(np); of_node_put(np); if (IS_ERR(map)) { dev_err(dev, "failed to get HHI regmap\n"); return PTR_ERR(map); } if (data->init_count) regmap_multi_reg_write(map, data->init_regs, data->init_count); /* Populate regmap for the regmap backed clocks */ for (i = 0; i < data->regmap_clk_num; i++) data->regmap_clks[i]->map = map; for (i = 0; i < data->hw_clks.num; i++) { /* array might be sparse */ if (!data->hw_clks.hws[i]) continue; ret = devm_clk_hw_register(dev, data->hw_clks.hws[i]); if (ret) { dev_err(dev, "Clock registration failed\n"); return ret; } } return devm_of_clk_add_hw_provider(dev, meson_clk_hw_get, (void *)&data->hw_clks); } EXPORT_SYMBOL_GPL(meson_eeclkc_probe); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/meson-eeclk.c
// SPDX-License-Identifier: (GPL-2.0 OR MIT) /* * Copyright (c) 2018 BayLibre, SAS. * Author: Jerome Brunet <[email protected]> */ #include <linux/clk-provider.h> #include <linux/module.h> #include "clk-regmap.h" #include "clk-phase.h" #define phase_step(_width) (360 / (1 << (_width))) static inline struct meson_clk_phase_data * meson_clk_phase_data(struct clk_regmap *clk) { return (struct meson_clk_phase_data *)clk->data; } static int meson_clk_degrees_from_val(unsigned int val, unsigned int width) { return phase_step(width) * val; } static unsigned int meson_clk_degrees_to_val(int degrees, unsigned int width) { unsigned int val = DIV_ROUND_CLOSEST(degrees, phase_step(width)); /* * This last calculation is here for cases when degrees is rounded * to 360, in which case val == (1 << width). */ return val % (1 << width); } static int meson_clk_phase_get_phase(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_phase_data *phase = meson_clk_phase_data(clk); unsigned int val; val = meson_parm_read(clk->map, &phase->ph); return meson_clk_degrees_from_val(val, phase->ph.width); } static int meson_clk_phase_set_phase(struct clk_hw *hw, int degrees) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_phase_data *phase = meson_clk_phase_data(clk); unsigned int val; val = meson_clk_degrees_to_val(degrees, phase->ph.width); meson_parm_write(clk->map, &phase->ph, val); return 0; } const struct clk_ops meson_clk_phase_ops = { .get_phase = meson_clk_phase_get_phase, .set_phase = meson_clk_phase_set_phase, }; EXPORT_SYMBOL_GPL(meson_clk_phase_ops); /* * This is a special clock for the audio controller. * The phase of mst_sclk clock output can be controlled independently * for the outside world (ph0), the tdmout (ph1) and tdmin (ph2). * Controlling these 3 phases as just one makes things simpler and * give the same clock view to all the element on the i2s bus. * If necessary, we can still control the phase in the tdm block * which makes these independent control redundant. */ static inline struct meson_clk_triphase_data * meson_clk_triphase_data(struct clk_regmap *clk) { return (struct meson_clk_triphase_data *)clk->data; } static int meson_clk_triphase_sync(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_triphase_data *tph = meson_clk_triphase_data(clk); unsigned int val; /* Get phase 0 and sync it to phase 1 and 2 */ val = meson_parm_read(clk->map, &tph->ph0); meson_parm_write(clk->map, &tph->ph1, val); meson_parm_write(clk->map, &tph->ph2, val); return 0; } static int meson_clk_triphase_get_phase(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_triphase_data *tph = meson_clk_triphase_data(clk); unsigned int val; /* Phase are in sync, reading phase 0 is enough */ val = meson_parm_read(clk->map, &tph->ph0); return meson_clk_degrees_from_val(val, tph->ph0.width); } static int meson_clk_triphase_set_phase(struct clk_hw *hw, int degrees) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_triphase_data *tph = meson_clk_triphase_data(clk); unsigned int val; val = meson_clk_degrees_to_val(degrees, tph->ph0.width); meson_parm_write(clk->map, &tph->ph0, val); meson_parm_write(clk->map, &tph->ph1, val); meson_parm_write(clk->map, &tph->ph2, val); return 0; } const struct clk_ops meson_clk_triphase_ops = { .init = meson_clk_triphase_sync, .get_phase = meson_clk_triphase_get_phase, .set_phase = meson_clk_triphase_set_phase, }; EXPORT_SYMBOL_GPL(meson_clk_triphase_ops); /* * This is a special clock for the audio controller. * This drive a bit clock inverter for which the * opposite value of the inverter bit needs to be manually * set into another bit */ static inline struct meson_sclk_ws_inv_data * meson_sclk_ws_inv_data(struct clk_regmap *clk) { return (struct meson_sclk_ws_inv_data *)clk->data; } static int meson_sclk_ws_inv_sync(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_ws_inv_data *tph = meson_sclk_ws_inv_data(clk); unsigned int val; /* Get phase and sync the inverted value to ws */ val = meson_parm_read(clk->map, &tph->ph); meson_parm_write(clk->map, &tph->ws, val ? 0 : 1); return 0; } static int meson_sclk_ws_inv_get_phase(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_ws_inv_data *tph = meson_sclk_ws_inv_data(clk); unsigned int val; val = meson_parm_read(clk->map, &tph->ph); return meson_clk_degrees_from_val(val, tph->ph.width); } static int meson_sclk_ws_inv_set_phase(struct clk_hw *hw, int degrees) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_sclk_ws_inv_data *tph = meson_sclk_ws_inv_data(clk); unsigned int val; val = meson_clk_degrees_to_val(degrees, tph->ph.width); meson_parm_write(clk->map, &tph->ph, val); meson_parm_write(clk->map, &tph->ws, val ? 0 : 1); return 0; } const struct clk_ops meson_sclk_ws_inv_ops = { .init = meson_sclk_ws_inv_sync, .get_phase = meson_sclk_ws_inv_get_phase, .set_phase = meson_sclk_ws_inv_set_phase, }; EXPORT_SYMBOL_GPL(meson_sclk_ws_inv_ops); MODULE_DESCRIPTION("Amlogic phase driver"); MODULE_AUTHOR("Jerome Brunet <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/clk-phase.c
// SPDX-License-Identifier: GPL-2.0+ /* * Amlogic Meson-AXG Clock Controller Driver * * Copyright (c) 2016 Baylibre SAS. * Author: Michael Turquette <[email protected]> * * Copyright (c) 2018 Amlogic, inc. * Author: Qiufang Dai <[email protected]> */ #include <linux/clk-provider.h> #include <linux/platform_device.h> #include <linux/reset-controller.h> #include <linux/mfd/syscon.h> #include <linux/module.h> #include "meson-aoclk.h" #include "clk-regmap.h" #include "clk-dualdiv.h" #include <dt-bindings/clock/axg-aoclkc.h> #include <dt-bindings/reset/axg-aoclkc.h> /* * AO Configuration Clock registers offsets * Register offsets from the data sheet must be multiplied by 4. */ #define AO_RTI_PWR_CNTL_REG1 0x0C #define AO_RTI_PWR_CNTL_REG0 0x10 #define AO_RTI_GEN_CNTL_REG0 0x40 #define AO_OSCIN_CNTL 0x58 #define AO_CRT_CLK_CNTL1 0x68 #define AO_SAR_CLK 0x90 #define AO_RTC_ALT_CLK_CNTL0 0x94 #define AO_RTC_ALT_CLK_CNTL1 0x98 #define AXG_AO_GATE(_name, _bit) \ static struct clk_regmap axg_aoclk_##_name = { \ .data = &(struct clk_regmap_gate_data) { \ .offset = (AO_RTI_GEN_CNTL_REG0), \ .bit_idx = (_bit), \ }, \ .hw.init = &(struct clk_init_data) { \ .name = "axg_ao_" #_name, \ .ops = &clk_regmap_gate_ops, \ .parent_data = &(const struct clk_parent_data) { \ .fw_name = "mpeg-clk", \ }, \ .num_parents = 1, \ .flags = CLK_IGNORE_UNUSED, \ }, \ } AXG_AO_GATE(remote, 0); AXG_AO_GATE(i2c_master, 1); AXG_AO_GATE(i2c_slave, 2); AXG_AO_GATE(uart1, 3); AXG_AO_GATE(uart2, 5); AXG_AO_GATE(ir_blaster, 6); AXG_AO_GATE(saradc, 7); static struct clk_regmap axg_aoclk_cts_oscin = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTI_PWR_CNTL_REG0, .bit_idx = 14, }, .hw.init = &(struct clk_init_data){ .name = "cts_oscin", .ops = &clk_regmap_gate_ro_ops, .parent_data = &(const struct clk_parent_data) { .fw_name = "xtal", }, .num_parents = 1, }, }; static struct clk_regmap axg_aoclk_32k_pre = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTC_ALT_CLK_CNTL0, .bit_idx = 31, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_32k_pre", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_aoclk_cts_oscin.hw }, .num_parents = 1, }, }; static const struct meson_clk_dualdiv_param axg_32k_div_table[] = { { .dual = 1, .n1 = 733, .m1 = 8, .n2 = 732, .m2 = 11, }, {} }; static struct clk_regmap axg_aoclk_32k_div = { .data = &(struct meson_clk_dualdiv_data){ .n1 = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 0, .width = 12, }, .n2 = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 12, .width = 12, }, .m1 = { .reg_off = AO_RTC_ALT_CLK_CNTL1, .shift = 0, .width = 12, }, .m2 = { .reg_off = AO_RTC_ALT_CLK_CNTL1, .shift = 12, .width = 12, }, .dual = { .reg_off = AO_RTC_ALT_CLK_CNTL0, .shift = 28, .width = 1, }, .table = axg_32k_div_table, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_32k_div", .ops = &meson_clk_dualdiv_ops, .parent_hws = (const struct clk_hw *[]) { &axg_aoclk_32k_pre.hw }, .num_parents = 1, }, }; static struct clk_regmap axg_aoclk_32k_sel = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTC_ALT_CLK_CNTL1, .mask = 0x1, .shift = 24, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_32k_sel", .ops = &clk_regmap_mux_ops, .parent_hws = (const struct clk_hw *[]) { &axg_aoclk_32k_div.hw, &axg_aoclk_32k_pre.hw, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_aoclk_32k = { .data = &(struct clk_regmap_gate_data){ .offset = AO_RTC_ALT_CLK_CNTL0, .bit_idx = 30, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_32k", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_aoclk_32k_sel.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_aoclk_cts_rtc_oscin = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTI_PWR_CNTL_REG0, .mask = 0x1, .shift = 10, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_cts_rtc_oscin", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .hw = &axg_aoclk_32k.hw }, { .fw_name = "ext_32k-0", }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_aoclk_clk81 = { .data = &(struct clk_regmap_mux_data) { .offset = AO_RTI_PWR_CNTL_REG0, .mask = 0x1, .shift = 8, .flags = CLK_MUX_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_clk81", .ops = &clk_regmap_mux_ro_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "mpeg-clk", }, { .hw = &axg_aoclk_cts_rtc_oscin.hw }, }, .num_parents = 2, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_aoclk_saradc_mux = { .data = &(struct clk_regmap_mux_data) { .offset = AO_SAR_CLK, .mask = 0x3, .shift = 9, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_saradc_mux", .ops = &clk_regmap_mux_ops, .parent_data = (const struct clk_parent_data []) { { .fw_name = "xtal", }, { .hw = &axg_aoclk_clk81.hw }, }, .num_parents = 2, }, }; static struct clk_regmap axg_aoclk_saradc_div = { .data = &(struct clk_regmap_div_data) { .offset = AO_SAR_CLK, .shift = 0, .width = 8, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_saradc_div", .ops = &clk_regmap_divider_ops, .parent_hws = (const struct clk_hw *[]) { &axg_aoclk_saradc_mux.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static struct clk_regmap axg_aoclk_saradc_gate = { .data = &(struct clk_regmap_gate_data) { .offset = AO_SAR_CLK, .bit_idx = 8, }, .hw.init = &(struct clk_init_data){ .name = "axg_ao_saradc_gate", .ops = &clk_regmap_gate_ops, .parent_hws = (const struct clk_hw *[]) { &axg_aoclk_saradc_div.hw }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, }; static const unsigned int axg_aoclk_reset[] = { [RESET_AO_REMOTE] = 16, [RESET_AO_I2C_MASTER] = 18, [RESET_AO_I2C_SLAVE] = 19, [RESET_AO_UART1] = 17, [RESET_AO_UART2] = 22, [RESET_AO_IR_BLASTER] = 23, }; static struct clk_regmap *axg_aoclk_regmap[] = { &axg_aoclk_remote, &axg_aoclk_i2c_master, &axg_aoclk_i2c_slave, &axg_aoclk_uart1, &axg_aoclk_uart2, &axg_aoclk_ir_blaster, &axg_aoclk_saradc, &axg_aoclk_cts_oscin, &axg_aoclk_32k_pre, &axg_aoclk_32k_div, &axg_aoclk_32k_sel, &axg_aoclk_32k, &axg_aoclk_cts_rtc_oscin, &axg_aoclk_clk81, &axg_aoclk_saradc_mux, &axg_aoclk_saradc_div, &axg_aoclk_saradc_gate, }; static struct clk_hw *axg_aoclk_hw_clks[] = { [CLKID_AO_REMOTE] = &axg_aoclk_remote.hw, [CLKID_AO_I2C_MASTER] = &axg_aoclk_i2c_master.hw, [CLKID_AO_I2C_SLAVE] = &axg_aoclk_i2c_slave.hw, [CLKID_AO_UART1] = &axg_aoclk_uart1.hw, [CLKID_AO_UART2] = &axg_aoclk_uart2.hw, [CLKID_AO_IR_BLASTER] = &axg_aoclk_ir_blaster.hw, [CLKID_AO_SAR_ADC] = &axg_aoclk_saradc.hw, [CLKID_AO_CLK81] = &axg_aoclk_clk81.hw, [CLKID_AO_SAR_ADC_SEL] = &axg_aoclk_saradc_mux.hw, [CLKID_AO_SAR_ADC_DIV] = &axg_aoclk_saradc_div.hw, [CLKID_AO_SAR_ADC_CLK] = &axg_aoclk_saradc_gate.hw, [CLKID_AO_CTS_OSCIN] = &axg_aoclk_cts_oscin.hw, [CLKID_AO_32K_PRE] = &axg_aoclk_32k_pre.hw, [CLKID_AO_32K_DIV] = &axg_aoclk_32k_div.hw, [CLKID_AO_32K_SEL] = &axg_aoclk_32k_sel.hw, [CLKID_AO_32K] = &axg_aoclk_32k.hw, [CLKID_AO_CTS_RTC_OSCIN] = &axg_aoclk_cts_rtc_oscin.hw, }; static const struct meson_aoclk_data axg_aoclkc_data = { .reset_reg = AO_RTI_GEN_CNTL_REG0, .num_reset = ARRAY_SIZE(axg_aoclk_reset), .reset = axg_aoclk_reset, .num_clks = ARRAY_SIZE(axg_aoclk_regmap), .clks = axg_aoclk_regmap, .hw_clks = { .hws = axg_aoclk_hw_clks, .num = ARRAY_SIZE(axg_aoclk_hw_clks), }, }; static const struct of_device_id axg_aoclkc_match_table[] = { { .compatible = "amlogic,meson-axg-aoclkc", .data = &axg_aoclkc_data, }, { } }; MODULE_DEVICE_TABLE(of, axg_aoclkc_match_table); static struct platform_driver axg_aoclkc_driver = { .probe = meson_aoclkc_probe, .driver = { .name = "axg-aoclkc", .of_match_table = axg_aoclkc_match_table, }, }; module_platform_driver(axg_aoclkc_driver); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/axg-aoclk.c
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) /* * Copyright (c) 2016 AmLogic, Inc. * Author: Michael Turquette <[email protected]> */ /* * MultiPhase Locked Loops are outputs from a PLL with additional frequency * scaling capabilities. MPLL rates are calculated as: * * f(N2_integer, SDM_IN ) = 2.0G/(N2_integer + SDM_IN/16384) */ #include <linux/clk-provider.h> #include <linux/module.h> #include <linux/spinlock.h> #include "clk-regmap.h" #include "clk-mpll.h" #define SDM_DEN 16384 #define N2_MIN 4 #define N2_MAX 511 static inline struct meson_clk_mpll_data * meson_clk_mpll_data(struct clk_regmap *clk) { return (struct meson_clk_mpll_data *)clk->data; } static long rate_from_params(unsigned long parent_rate, unsigned int sdm, unsigned int n2) { unsigned long divisor = (SDM_DEN * n2) + sdm; if (n2 < N2_MIN) return -EINVAL; return DIV_ROUND_UP_ULL((u64)parent_rate * SDM_DEN, divisor); } static void params_from_rate(unsigned long requested_rate, unsigned long parent_rate, unsigned int *sdm, unsigned int *n2, u8 flags) { uint64_t div = parent_rate; uint64_t frac = do_div(div, requested_rate); frac *= SDM_DEN; if (flags & CLK_MESON_MPLL_ROUND_CLOSEST) *sdm = DIV_ROUND_CLOSEST_ULL(frac, requested_rate); else *sdm = DIV_ROUND_UP_ULL(frac, requested_rate); if (*sdm == SDM_DEN) { *sdm = 0; div += 1; } if (div < N2_MIN) { *n2 = N2_MIN; *sdm = 0; } else if (div > N2_MAX) { *n2 = N2_MAX; *sdm = SDM_DEN - 1; } else { *n2 = div; } } static unsigned long mpll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_mpll_data *mpll = meson_clk_mpll_data(clk); unsigned int sdm, n2; long rate; sdm = meson_parm_read(clk->map, &mpll->sdm); n2 = meson_parm_read(clk->map, &mpll->n2); rate = rate_from_params(parent_rate, sdm, n2); return rate < 0 ? 0 : rate; } static int mpll_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_mpll_data *mpll = meson_clk_mpll_data(clk); unsigned int sdm, n2; long rate; params_from_rate(req->rate, req->best_parent_rate, &sdm, &n2, mpll->flags); rate = rate_from_params(req->best_parent_rate, sdm, n2); if (rate < 0) return rate; req->rate = rate; return 0; } static int mpll_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_mpll_data *mpll = meson_clk_mpll_data(clk); unsigned int sdm, n2; unsigned long flags = 0; params_from_rate(rate, parent_rate, &sdm, &n2, mpll->flags); if (mpll->lock) spin_lock_irqsave(mpll->lock, flags); else __acquire(mpll->lock); /* Set the fractional part */ meson_parm_write(clk->map, &mpll->sdm, sdm); /* Set the integer divider part */ meson_parm_write(clk->map, &mpll->n2, n2); if (mpll->lock) spin_unlock_irqrestore(mpll->lock, flags); else __release(mpll->lock); return 0; } static int mpll_init(struct clk_hw *hw) { struct clk_regmap *clk = to_clk_regmap(hw); struct meson_clk_mpll_data *mpll = meson_clk_mpll_data(clk); if (mpll->init_count) regmap_multi_reg_write(clk->map, mpll->init_regs, mpll->init_count); /* Enable the fractional part */ meson_parm_write(clk->map, &mpll->sdm_en, 1); /* Set spread spectrum if possible */ if (MESON_PARM_APPLICABLE(&mpll->ssen)) { unsigned int ss = mpll->flags & CLK_MESON_MPLL_SPREAD_SPECTRUM ? 1 : 0; meson_parm_write(clk->map, &mpll->ssen, ss); } /* Set the magic misc bit if required */ if (MESON_PARM_APPLICABLE(&mpll->misc)) meson_parm_write(clk->map, &mpll->misc, 1); return 0; } const struct clk_ops meson_clk_mpll_ro_ops = { .recalc_rate = mpll_recalc_rate, .determine_rate = mpll_determine_rate, }; EXPORT_SYMBOL_GPL(meson_clk_mpll_ro_ops); const struct clk_ops meson_clk_mpll_ops = { .recalc_rate = mpll_recalc_rate, .determine_rate = mpll_determine_rate, .set_rate = mpll_set_rate, .init = mpll_init, }; EXPORT_SYMBOL_GPL(meson_clk_mpll_ops); MODULE_DESCRIPTION("Amlogic MPLL driver"); MODULE_AUTHOR("Michael Turquette <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
drivers/clk/meson/clk-mpll.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) STMicroelectronics 2022 - All Rights Reserved * Author: Gabriel Fernandez <[email protected]> for STMicroelectronics. */ #include <linux/of.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/reset-controller.h> #include <linux/slab.h> #include <linux/spinlock.h> #include "clk-stm32-core.h" #define STM32_RESET_ID_MASK GENMASK(15, 0) struct stm32_reset_data { /* reset lock */ spinlock_t lock; struct reset_controller_dev rcdev; void __iomem *membase; u32 clear_offset; }; static inline struct stm32_reset_data * to_stm32_reset_data(struct reset_controller_dev *rcdev) { return container_of(rcdev, struct stm32_reset_data, rcdev); } static int stm32_reset_update(struct reset_controller_dev *rcdev, unsigned long id, bool assert) { struct stm32_reset_data *data = to_stm32_reset_data(rcdev); int reg_width = sizeof(u32); int bank = id / (reg_width * BITS_PER_BYTE); int offset = id % (reg_width * BITS_PER_BYTE); if (data->clear_offset) { void __iomem *addr; addr = data->membase + (bank * reg_width); if (!assert) addr += data->clear_offset; writel(BIT(offset), addr); } else { unsigned long flags; u32 reg; spin_lock_irqsave(&data->lock, flags); reg = readl(data->membase + (bank * reg_width)); if (assert) reg |= BIT(offset); else reg &= ~BIT(offset); writel(reg, data->membase + (bank * reg_width)); spin_unlock_irqrestore(&data->lock, flags); } return 0; } static int stm32_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) { return stm32_reset_update(rcdev, id, true); } static int stm32_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) { return stm32_reset_update(rcdev, id, false); } static int stm32_reset_status(struct reset_controller_dev *rcdev, unsigned long id) { struct stm32_reset_data *data = to_stm32_reset_data(rcdev); int reg_width = sizeof(u32); int bank = id / (reg_width * BITS_PER_BYTE); int offset = id % (reg_width * BITS_PER_BYTE); u32 reg; reg = readl(data->membase + (bank * reg_width)); return !!(reg & BIT(offset)); } static const struct reset_control_ops stm32_reset_ops = { .assert = stm32_reset_assert, .deassert = stm32_reset_deassert, .status = stm32_reset_status, }; int stm32_rcc_reset_init(struct device *dev, const struct of_device_id *match, void __iomem *base) { const struct stm32_rcc_match_data *data = match->data; struct stm32_reset_data *reset_data = NULL; data = match->data; reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL); if (!reset_data) return -ENOMEM; spin_lock_init(&reset_data->lock); reset_data->membase = base; reset_data->rcdev.owner = THIS_MODULE; reset_data->rcdev.ops = &stm32_reset_ops; reset_data->rcdev.of_node = dev_of_node(dev); reset_data->rcdev.nr_resets = STM32_RESET_ID_MASK; reset_data->clear_offset = data->clear_offset; return reset_controller_register(&reset_data->rcdev); }
linux-master
drivers/clk/stm32/reset-stm32.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) STMicroelectronics 2022 - All Rights Reserved * Author: Gabriel Fernandez <[email protected]> for STMicroelectronics. */ #include <linux/clk.h> #include <linux/delay.h> #include <linux/device.h> #include <linux/err.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/slab.h> #include <linux/spinlock.h> #include "clk-stm32-core.h" #include "reset-stm32.h" static DEFINE_SPINLOCK(rlock); static int stm32_rcc_clock_init(struct device *dev, const struct of_device_id *match, void __iomem *base) { const struct stm32_rcc_match_data *data = match->data; struct clk_hw_onecell_data *clk_data = data->hw_clks; struct device_node *np = dev_of_node(dev); struct clk_hw **hws; int n, max_binding; max_binding = data->maxbinding; clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, max_binding), GFP_KERNEL); if (!clk_data) return -ENOMEM; clk_data->num = max_binding; hws = clk_data->hws; for (n = 0; n < max_binding; n++) hws[n] = ERR_PTR(-ENOENT); for (n = 0; n < data->num_clocks; n++) { const struct clock_config *cfg_clock = &data->tab_clocks[n]; struct clk_hw *hw = ERR_PTR(-ENOENT); if (data->check_security && data->check_security(base, cfg_clock)) continue; if (cfg_clock->func) hw = (*cfg_clock->func)(dev, data, base, &rlock, cfg_clock); if (IS_ERR(hw)) { dev_err(dev, "Can't register clk %d: %ld\n", n, PTR_ERR(hw)); return PTR_ERR(hw); } if (cfg_clock->id != NO_ID) hws[cfg_clock->id] = hw; } return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data); } int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data, void __iomem *base) { const struct of_device_id *match; int err; match = of_match_node(match_data, dev_of_node(dev)); if (!match) { dev_err(dev, "match data not found\n"); return -ENODEV; } /* RCC Reset Configuration */ err = stm32_rcc_reset_init(dev, match, base); if (err) { pr_err("stm32 reset failed to initialize\n"); return err; } /* RCC Clock Configuration */ err = stm32_rcc_clock_init(dev, match, base); if (err) { pr_err("stm32 clock failed to initialize\n"); return err; } return 0; } static u8 stm32_mux_get_parent(void __iomem *base, struct clk_stm32_clock_data *data, u16 mux_id) { const struct stm32_mux_cfg *mux = &data->muxes[mux_id]; u32 mask = BIT(mux->width) - 1; u32 val; val = readl(base + mux->offset) >> mux->shift; val &= mask; return val; } static int stm32_mux_set_parent(void __iomem *base, struct clk_stm32_clock_data *data, u16 mux_id, u8 index) { const struct stm32_mux_cfg *mux = &data->muxes[mux_id]; u32 mask = BIT(mux->width) - 1; u32 reg = readl(base + mux->offset); u32 val = index << mux->shift; reg &= ~(mask << mux->shift); reg |= val; writel(reg, base + mux->offset); return 0; } static void stm32_gate_endisable(void __iomem *base, struct clk_stm32_clock_data *data, u16 gate_id, int enable) { const struct stm32_gate_cfg *gate = &data->gates[gate_id]; void __iomem *addr = base + gate->offset; if (enable) { if (data->gate_cpt[gate_id]++ > 0) return; if (gate->set_clr != 0) writel(BIT(gate->bit_idx), addr); else writel(readl(addr) | BIT(gate->bit_idx), addr); } else { if (--data->gate_cpt[gate_id] > 0) return; if (gate->set_clr != 0) writel(BIT(gate->bit_idx), addr + gate->set_clr); else writel(readl(addr) & ~BIT(gate->bit_idx), addr); } } static void stm32_gate_disable_unused(void __iomem *base, struct clk_stm32_clock_data *data, u16 gate_id) { const struct stm32_gate_cfg *gate = &data->gates[gate_id]; void __iomem *addr = base + gate->offset; if (data->gate_cpt[gate_id] > 0) return; if (gate->set_clr != 0) writel(BIT(gate->bit_idx), addr + gate->set_clr); else writel(readl(addr) & ~BIT(gate->bit_idx), addr); } static int stm32_gate_is_enabled(void __iomem *base, struct clk_stm32_clock_data *data, u16 gate_id) { const struct stm32_gate_cfg *gate = &data->gates[gate_id]; return (readl(base + gate->offset) & BIT(gate->bit_idx)) != 0; } static unsigned int _get_table_div(const struct clk_div_table *table, unsigned int val) { const struct clk_div_table *clkt; for (clkt = table; clkt->div; clkt++) if (clkt->val == val) return clkt->div; return 0; } static unsigned int _get_div(const struct clk_div_table *table, unsigned int val, unsigned long flags, u8 width) { if (flags & CLK_DIVIDER_ONE_BASED) return val; if (flags & CLK_DIVIDER_POWER_OF_TWO) return 1 << val; if (table) return _get_table_div(table, val); return val + 1; } static unsigned long stm32_divider_get_rate(void __iomem *base, struct clk_stm32_clock_data *data, u16 div_id, unsigned long parent_rate) { const struct stm32_div_cfg *divider = &data->dividers[div_id]; unsigned int val; unsigned int div; val = readl(base + divider->offset) >> divider->shift; val &= clk_div_mask(divider->width); div = _get_div(divider->table, val, divider->flags, divider->width); if (!div) { WARN(!(divider->flags & CLK_DIVIDER_ALLOW_ZERO), "%d: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n", div_id); return parent_rate; } return DIV_ROUND_UP_ULL((u64)parent_rate, div); } static int stm32_divider_set_rate(void __iomem *base, struct clk_stm32_clock_data *data, u16 div_id, unsigned long rate, unsigned long parent_rate) { const struct stm32_div_cfg *divider = &data->dividers[div_id]; int value; u32 val; value = divider_get_val(rate, parent_rate, divider->table, divider->width, divider->flags); if (value < 0) return value; if (divider->flags & CLK_DIVIDER_HIWORD_MASK) { val = clk_div_mask(divider->width) << (divider->shift + 16); } else { val = readl(base + divider->offset); val &= ~(clk_div_mask(divider->width) << divider->shift); } val |= (u32)value << divider->shift; writel(val, base + divider->offset); return 0; } static u8 clk_stm32_mux_get_parent(struct clk_hw *hw) { struct clk_stm32_mux *mux = to_clk_stm32_mux(hw); return stm32_mux_get_parent(mux->base, mux->clock_data, mux->mux_id); } static int clk_stm32_mux_set_parent(struct clk_hw *hw, u8 index) { struct clk_stm32_mux *mux = to_clk_stm32_mux(hw); unsigned long flags = 0; spin_lock_irqsave(mux->lock, flags); stm32_mux_set_parent(mux->base, mux->clock_data, mux->mux_id, index); spin_unlock_irqrestore(mux->lock, flags); return 0; } const struct clk_ops clk_stm32_mux_ops = { .determine_rate = __clk_mux_determine_rate, .get_parent = clk_stm32_mux_get_parent, .set_parent = clk_stm32_mux_set_parent, }; static void clk_stm32_gate_endisable(struct clk_hw *hw, int enable) { struct clk_stm32_gate *gate = to_clk_stm32_gate(hw); unsigned long flags = 0; spin_lock_irqsave(gate->lock, flags); stm32_gate_endisable(gate->base, gate->clock_data, gate->gate_id, enable); spin_unlock_irqrestore(gate->lock, flags); } static int clk_stm32_gate_enable(struct clk_hw *hw) { clk_stm32_gate_endisable(hw, 1); return 0; } static void clk_stm32_gate_disable(struct clk_hw *hw) { clk_stm32_gate_endisable(hw, 0); } static int clk_stm32_gate_is_enabled(struct clk_hw *hw) { struct clk_stm32_gate *gate = to_clk_stm32_gate(hw); return stm32_gate_is_enabled(gate->base, gate->clock_data, gate->gate_id); } static void clk_stm32_gate_disable_unused(struct clk_hw *hw) { struct clk_stm32_gate *gate = to_clk_stm32_gate(hw); unsigned long flags = 0; spin_lock_irqsave(gate->lock, flags); stm32_gate_disable_unused(gate->base, gate->clock_data, gate->gate_id); spin_unlock_irqrestore(gate->lock, flags); } const struct clk_ops clk_stm32_gate_ops = { .enable = clk_stm32_gate_enable, .disable = clk_stm32_gate_disable, .is_enabled = clk_stm32_gate_is_enabled, .disable_unused = clk_stm32_gate_disable_unused, }; static int clk_stm32_divider_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clk_stm32_div *div = to_clk_stm32_divider(hw); unsigned long flags = 0; int ret; if (div->div_id == NO_STM32_DIV) return rate; spin_lock_irqsave(div->lock, flags); ret = stm32_divider_set_rate(div->base, div->clock_data, div->div_id, rate, parent_rate); spin_unlock_irqrestore(div->lock, flags); return ret; } static long clk_stm32_divider_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct clk_stm32_div *div = to_clk_stm32_divider(hw); const struct stm32_div_cfg *divider; if (div->div_id == NO_STM32_DIV) return rate; divider = &div->clock_data->dividers[div->div_id]; /* if read only, just return current value */ if (divider->flags & CLK_DIVIDER_READ_ONLY) { u32 val; val = readl(div->base + divider->offset) >> divider->shift; val &= clk_div_mask(divider->width); return divider_ro_round_rate(hw, rate, prate, divider->table, divider->width, divider->flags, val); } return divider_round_rate_parent(hw, clk_hw_get_parent(hw), rate, prate, divider->table, divider->width, divider->flags); } static unsigned long clk_stm32_divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct clk_stm32_div *div = to_clk_stm32_divider(hw); if (div->div_id == NO_STM32_DIV) return parent_rate; return stm32_divider_get_rate(div->base, div->clock_data, div->div_id, parent_rate); } const struct clk_ops clk_stm32_divider_ops = { .recalc_rate = clk_stm32_divider_recalc_rate, .round_rate = clk_stm32_divider_round_rate, .set_rate = clk_stm32_divider_set_rate, }; static int clk_stm32_composite_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); unsigned long flags = 0; int ret; if (composite->div_id == NO_STM32_DIV) return rate; spin_lock_irqsave(composite->lock, flags); ret = stm32_divider_set_rate(composite->base, composite->clock_data, composite->div_id, rate, parent_rate); spin_unlock_irqrestore(composite->lock, flags); return ret; } static unsigned long clk_stm32_composite_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); if (composite->div_id == NO_STM32_DIV) return parent_rate; return stm32_divider_get_rate(composite->base, composite->clock_data, composite->div_id, parent_rate); } static int clk_stm32_composite_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); const struct stm32_div_cfg *divider; unsigned long rate; if (composite->div_id == NO_STM32_DIV) return 0; divider = &composite->clock_data->dividers[composite->div_id]; /* if read only, just return current value */ if (divider->flags & CLK_DIVIDER_READ_ONLY) { u32 val; val = readl(composite->base + divider->offset) >> divider->shift; val &= clk_div_mask(divider->width); rate = divider_ro_round_rate(hw, req->rate, &req->best_parent_rate, divider->table, divider->width, divider->flags, val); if (rate < 0) return rate; req->rate = rate; return 0; } rate = divider_round_rate_parent(hw, clk_hw_get_parent(hw), req->rate, &req->best_parent_rate, divider->table, divider->width, divider->flags); if (rate < 0) return rate; req->rate = rate; return 0; } static u8 clk_stm32_composite_get_parent(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); return stm32_mux_get_parent(composite->base, composite->clock_data, composite->mux_id); } static int clk_stm32_composite_set_parent(struct clk_hw *hw, u8 index) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); unsigned long flags = 0; spin_lock_irqsave(composite->lock, flags); stm32_mux_set_parent(composite->base, composite->clock_data, composite->mux_id, index); spin_unlock_irqrestore(composite->lock, flags); if (composite->clock_data->is_multi_mux) { struct clk_hw *other_mux_hw = composite->clock_data->is_multi_mux(hw); if (other_mux_hw) { struct clk_hw *hwp = clk_hw_get_parent_by_index(hw, index); clk_hw_reparent(other_mux_hw, hwp); } } return 0; } static int clk_stm32_composite_is_enabled(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); if (composite->gate_id == NO_STM32_GATE) return (__clk_get_enable_count(hw->clk) > 0); return stm32_gate_is_enabled(composite->base, composite->clock_data, composite->gate_id); } #define MUX_SAFE_POSITION 0 static int clk_stm32_has_safe_mux(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); const struct stm32_mux_cfg *mux = &composite->clock_data->muxes[composite->mux_id]; return !!(mux->flags & MUX_SAFE); } static void clk_stm32_set_safe_position_mux(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); if (!clk_stm32_composite_is_enabled(hw)) { unsigned long flags = 0; if (composite->clock_data->is_multi_mux) { struct clk_hw *other_mux_hw = NULL; other_mux_hw = composite->clock_data->is_multi_mux(hw); if (!other_mux_hw || clk_stm32_composite_is_enabled(other_mux_hw)) return; } spin_lock_irqsave(composite->lock, flags); stm32_mux_set_parent(composite->base, composite->clock_data, composite->mux_id, MUX_SAFE_POSITION); spin_unlock_irqrestore(composite->lock, flags); } } static void clk_stm32_safe_restore_position_mux(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); int sel = clk_hw_get_parent_index(hw); unsigned long flags = 0; spin_lock_irqsave(composite->lock, flags); stm32_mux_set_parent(composite->base, composite->clock_data, composite->mux_id, sel); spin_unlock_irqrestore(composite->lock, flags); } static void clk_stm32_composite_gate_endisable(struct clk_hw *hw, int enable) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); unsigned long flags = 0; spin_lock_irqsave(composite->lock, flags); stm32_gate_endisable(composite->base, composite->clock_data, composite->gate_id, enable); spin_unlock_irqrestore(composite->lock, flags); } static int clk_stm32_composite_gate_enable(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); if (composite->gate_id == NO_STM32_GATE) return 0; clk_stm32_composite_gate_endisable(hw, 1); if (composite->mux_id != NO_STM32_MUX && clk_stm32_has_safe_mux(hw)) clk_stm32_safe_restore_position_mux(hw); return 0; } static void clk_stm32_composite_gate_disable(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); if (composite->gate_id == NO_STM32_GATE) return; clk_stm32_composite_gate_endisable(hw, 0); if (composite->mux_id != NO_STM32_MUX && clk_stm32_has_safe_mux(hw)) clk_stm32_set_safe_position_mux(hw); } static void clk_stm32_composite_disable_unused(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); unsigned long flags = 0; if (composite->gate_id == NO_STM32_GATE) return; spin_lock_irqsave(composite->lock, flags); stm32_gate_disable_unused(composite->base, composite->clock_data, composite->gate_id); spin_unlock_irqrestore(composite->lock, flags); } const struct clk_ops clk_stm32_composite_ops = { .set_rate = clk_stm32_composite_set_rate, .recalc_rate = clk_stm32_composite_recalc_rate, .determine_rate = clk_stm32_composite_determine_rate, .get_parent = clk_stm32_composite_get_parent, .set_parent = clk_stm32_composite_set_parent, .enable = clk_stm32_composite_gate_enable, .disable = clk_stm32_composite_gate_disable, .is_enabled = clk_stm32_composite_is_enabled, .disable_unused = clk_stm32_composite_disable_unused, }; struct clk_hw *clk_stm32_mux_register(struct device *dev, const struct stm32_rcc_match_data *data, void __iomem *base, spinlock_t *lock, const struct clock_config *cfg) { struct clk_stm32_mux *mux = cfg->clock_cfg; struct clk_hw *hw = &mux->hw; int err; mux->base = base; mux->lock = lock; mux->clock_data = data->clock_data; err = clk_hw_register(dev, hw); if (err) return ERR_PTR(err); return hw; } struct clk_hw *clk_stm32_gate_register(struct device *dev, const struct stm32_rcc_match_data *data, void __iomem *base, spinlock_t *lock, const struct clock_config *cfg) { struct clk_stm32_gate *gate = cfg->clock_cfg; struct clk_hw *hw = &gate->hw; int err; gate->base = base; gate->lock = lock; gate->clock_data = data->clock_data; err = clk_hw_register(dev, hw); if (err) return ERR_PTR(err); return hw; } struct clk_hw *clk_stm32_div_register(struct device *dev, const struct stm32_rcc_match_data *data, void __iomem *base, spinlock_t *lock, const struct clock_config *cfg) { struct clk_stm32_div *div = cfg->clock_cfg; struct clk_hw *hw = &div->hw; int err; div->base = base; div->lock = lock; div->clock_data = data->clock_data; err = clk_hw_register(dev, hw); if (err) return ERR_PTR(err); return hw; } struct clk_hw *clk_stm32_composite_register(struct device *dev, const struct stm32_rcc_match_data *data, void __iomem *base, spinlock_t *lock, const struct clock_config *cfg) { struct clk_stm32_composite *composite = cfg->clock_cfg; struct clk_hw *hw = &composite->hw; int err; composite->base = base; composite->lock = lock; composite->clock_data = data->clock_data; err = clk_hw_register(dev, hw); if (err) return ERR_PTR(err); return hw; }
linux-master
drivers/clk/stm32/clk-stm32-core.c
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) STMicroelectronics 2022 - All Rights Reserved * Author: Gabriel Fernandez <[email protected]> for STMicroelectronics. */ #include <linux/clk.h> #include <linux/module.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <dt-bindings/clock/stm32mp13-clks.h> #include "clk-stm32-core.h" #include "stm32mp13_rcc.h" #define RCC_CLR_OFFSET 0x4 /* STM32 Gates definition */ enum enum_gate_cfg { GATE_MCO1, GATE_MCO2, GATE_DBGCK, GATE_TRACECK, GATE_DDRC1, GATE_DDRC1LP, GATE_DDRPHYC, GATE_DDRPHYCLP, GATE_DDRCAPB, GATE_DDRCAPBLP, GATE_AXIDCG, GATE_DDRPHYCAPB, GATE_DDRPHYCAPBLP, GATE_TIM2, GATE_TIM3, GATE_TIM4, GATE_TIM5, GATE_TIM6, GATE_TIM7, GATE_LPTIM1, GATE_SPI2, GATE_SPI3, GATE_USART3, GATE_UART4, GATE_UART5, GATE_UART7, GATE_UART8, GATE_I2C1, GATE_I2C2, GATE_SPDIF, GATE_TIM1, GATE_TIM8, GATE_SPI1, GATE_USART6, GATE_SAI1, GATE_SAI2, GATE_DFSDM, GATE_ADFSDM, GATE_FDCAN, GATE_LPTIM2, GATE_LPTIM3, GATE_LPTIM4, GATE_LPTIM5, GATE_VREF, GATE_DTS, GATE_PMBCTRL, GATE_HDP, GATE_SYSCFG, GATE_DCMIPP, GATE_DDRPERFM, GATE_IWDG2APB, GATE_USBPHY, GATE_STGENRO, GATE_LTDC, GATE_RTCAPB, GATE_TZC, GATE_ETZPC, GATE_IWDG1APB, GATE_BSEC, GATE_STGENC, GATE_USART1, GATE_USART2, GATE_SPI4, GATE_SPI5, GATE_I2C3, GATE_I2C4, GATE_I2C5, GATE_TIM12, GATE_TIM13, GATE_TIM14, GATE_TIM15, GATE_TIM16, GATE_TIM17, GATE_DMA1, GATE_DMA2, GATE_DMAMUX1, GATE_DMA3, GATE_DMAMUX2, GATE_ADC1, GATE_ADC2, GATE_USBO, GATE_TSC, GATE_GPIOA, GATE_GPIOB, GATE_GPIOC, GATE_GPIOD, GATE_GPIOE, GATE_GPIOF, GATE_GPIOG, GATE_GPIOH, GATE_GPIOI, GATE_PKA, GATE_SAES, GATE_CRYP1, GATE_HASH1, GATE_RNG1, GATE_BKPSRAM, GATE_AXIMC, GATE_MCE, GATE_ETH1CK, GATE_ETH1TX, GATE_ETH1RX, GATE_ETH1MAC, GATE_FMC, GATE_QSPI, GATE_SDMMC1, GATE_SDMMC2, GATE_CRC1, GATE_USBH, GATE_ETH2CK, GATE_ETH2TX, GATE_ETH2RX, GATE_ETH2MAC, GATE_ETH1STP, GATE_ETH2STP, GATE_MDMA, GATE_NB }; #define _CFG_GATE(_id, _offset, _bit_idx, _offset_clr)\ [(_id)] = {\ .offset = (_offset),\ .bit_idx = (_bit_idx),\ .set_clr = (_offset_clr),\ } #define CFG_GATE(_id, _offset, _bit_idx)\ _CFG_GATE(_id, _offset, _bit_idx, 0) #define CFG_GATE_SETCLR(_id, _offset, _bit_idx)\ _CFG_GATE(_id, _offset, _bit_idx, RCC_CLR_OFFSET) static struct stm32_gate_cfg stm32mp13_gates[] = { CFG_GATE(GATE_MCO1, RCC_MCO1CFGR, 12), CFG_GATE(GATE_MCO2, RCC_MCO2CFGR, 12), CFG_GATE(GATE_DBGCK, RCC_DBGCFGR, 8), CFG_GATE(GATE_TRACECK, RCC_DBGCFGR, 9), CFG_GATE(GATE_DDRC1, RCC_DDRITFCR, 0), CFG_GATE(GATE_DDRC1LP, RCC_DDRITFCR, 1), CFG_GATE(GATE_DDRPHYC, RCC_DDRITFCR, 4), CFG_GATE(GATE_DDRPHYCLP, RCC_DDRITFCR, 5), CFG_GATE(GATE_DDRCAPB, RCC_DDRITFCR, 6), CFG_GATE(GATE_DDRCAPBLP, RCC_DDRITFCR, 7), CFG_GATE(GATE_AXIDCG, RCC_DDRITFCR, 8), CFG_GATE(GATE_DDRPHYCAPB, RCC_DDRITFCR, 9), CFG_GATE(GATE_DDRPHYCAPBLP, RCC_DDRITFCR, 10), CFG_GATE_SETCLR(GATE_TIM2, RCC_MP_APB1ENSETR, 0), CFG_GATE_SETCLR(GATE_TIM3, RCC_MP_APB1ENSETR, 1), CFG_GATE_SETCLR(GATE_TIM4, RCC_MP_APB1ENSETR, 2), CFG_GATE_SETCLR(GATE_TIM5, RCC_MP_APB1ENSETR, 3), CFG_GATE_SETCLR(GATE_TIM6, RCC_MP_APB1ENSETR, 4), CFG_GATE_SETCLR(GATE_TIM7, RCC_MP_APB1ENSETR, 5), CFG_GATE_SETCLR(GATE_LPTIM1, RCC_MP_APB1ENSETR, 9), CFG_GATE_SETCLR(GATE_SPI2, RCC_MP_APB1ENSETR, 11), CFG_GATE_SETCLR(GATE_SPI3, RCC_MP_APB1ENSETR, 12), CFG_GATE_SETCLR(GATE_USART3, RCC_MP_APB1ENSETR, 15), CFG_GATE_SETCLR(GATE_UART4, RCC_MP_APB1ENSETR, 16), CFG_GATE_SETCLR(GATE_UART5, RCC_MP_APB1ENSETR, 17), CFG_GATE_SETCLR(GATE_UART7, RCC_MP_APB1ENSETR, 18), CFG_GATE_SETCLR(GATE_UART8, RCC_MP_APB1ENSETR, 19), CFG_GATE_SETCLR(GATE_I2C1, RCC_MP_APB1ENSETR, 21), CFG_GATE_SETCLR(GATE_I2C2, RCC_MP_APB1ENSETR, 22), CFG_GATE_SETCLR(GATE_SPDIF, RCC_MP_APB1ENSETR, 26), CFG_GATE_SETCLR(GATE_TIM1, RCC_MP_APB2ENSETR, 0), CFG_GATE_SETCLR(GATE_TIM8, RCC_MP_APB2ENSETR, 1), CFG_GATE_SETCLR(GATE_SPI1, RCC_MP_APB2ENSETR, 8), CFG_GATE_SETCLR(GATE_USART6, RCC_MP_APB2ENSETR, 13), CFG_GATE_SETCLR(GATE_SAI1, RCC_MP_APB2ENSETR, 16), CFG_GATE_SETCLR(GATE_SAI2, RCC_MP_APB2ENSETR, 17), CFG_GATE_SETCLR(GATE_DFSDM, RCC_MP_APB2ENSETR, 20), CFG_GATE_SETCLR(GATE_ADFSDM, RCC_MP_APB2ENSETR, 21), CFG_GATE_SETCLR(GATE_FDCAN, RCC_MP_APB2ENSETR, 24), CFG_GATE_SETCLR(GATE_LPTIM2, RCC_MP_APB3ENSETR, 0), CFG_GATE_SETCLR(GATE_LPTIM3, RCC_MP_APB3ENSETR, 1), CFG_GATE_SETCLR(GATE_LPTIM4, RCC_MP_APB3ENSETR, 2), CFG_GATE_SETCLR(GATE_LPTIM5, RCC_MP_APB3ENSETR, 3), CFG_GATE_SETCLR(GATE_VREF, RCC_MP_APB3ENSETR, 13), CFG_GATE_SETCLR(GATE_DTS, RCC_MP_APB3ENSETR, 16), CFG_GATE_SETCLR(GATE_PMBCTRL, RCC_MP_APB3ENSETR, 17), CFG_GATE_SETCLR(GATE_HDP, RCC_MP_APB3ENSETR, 20), CFG_GATE_SETCLR(GATE_SYSCFG, RCC_MP_NS_APB3ENSETR, 0), CFG_GATE_SETCLR(GATE_DCMIPP, RCC_MP_APB4ENSETR, 1), CFG_GATE_SETCLR(GATE_DDRPERFM, RCC_MP_APB4ENSETR, 8), CFG_GATE_SETCLR(GATE_IWDG2APB, RCC_MP_APB4ENSETR, 15), CFG_GATE_SETCLR(GATE_USBPHY, RCC_MP_APB4ENSETR, 16), CFG_GATE_SETCLR(GATE_STGENRO, RCC_MP_APB4ENSETR, 20), CFG_GATE_SETCLR(GATE_LTDC, RCC_MP_NS_APB4ENSETR, 0), CFG_GATE_SETCLR(GATE_RTCAPB, RCC_MP_APB5ENSETR, 8), CFG_GATE_SETCLR(GATE_TZC, RCC_MP_APB5ENSETR, 11), CFG_GATE_SETCLR(GATE_ETZPC, RCC_MP_APB5ENSETR, 13), CFG_GATE_SETCLR(GATE_IWDG1APB, RCC_MP_APB5ENSETR, 15), CFG_GATE_SETCLR(GATE_BSEC, RCC_MP_APB5ENSETR, 16), CFG_GATE_SETCLR(GATE_STGENC, RCC_MP_APB5ENSETR, 20), CFG_GATE_SETCLR(GATE_USART1, RCC_MP_APB6ENSETR, 0), CFG_GATE_SETCLR(GATE_USART2, RCC_MP_APB6ENSETR, 1), CFG_GATE_SETCLR(GATE_SPI4, RCC_MP_APB6ENSETR, 2), CFG_GATE_SETCLR(GATE_SPI5, RCC_MP_APB6ENSETR, 3), CFG_GATE_SETCLR(GATE_I2C3, RCC_MP_APB6ENSETR, 4), CFG_GATE_SETCLR(GATE_I2C4, RCC_MP_APB6ENSETR, 5), CFG_GATE_SETCLR(GATE_I2C5, RCC_MP_APB6ENSETR, 6), CFG_GATE_SETCLR(GATE_TIM12, RCC_MP_APB6ENSETR, 7), CFG_GATE_SETCLR(GATE_TIM13, RCC_MP_APB6ENSETR, 8), CFG_GATE_SETCLR(GATE_TIM14, RCC_MP_APB6ENSETR, 9), CFG_GATE_SETCLR(GATE_TIM15, RCC_MP_APB6ENSETR, 10), CFG_GATE_SETCLR(GATE_TIM16, RCC_MP_APB6ENSETR, 11), CFG_GATE_SETCLR(GATE_TIM17, RCC_MP_APB6ENSETR, 12), CFG_GATE_SETCLR(GATE_DMA1, RCC_MP_AHB2ENSETR, 0), CFG_GATE_SETCLR(GATE_DMA2, RCC_MP_AHB2ENSETR, 1), CFG_GATE_SETCLR(GATE_DMAMUX1, RCC_MP_AHB2ENSETR, 2), CFG_GATE_SETCLR(GATE_DMA3, RCC_MP_AHB2ENSETR, 3), CFG_GATE_SETCLR(GATE_DMAMUX2, RCC_MP_AHB2ENSETR, 4), CFG_GATE_SETCLR(GATE_ADC1, RCC_MP_AHB2ENSETR, 5), CFG_GATE_SETCLR(GATE_ADC2, RCC_MP_AHB2ENSETR, 6), CFG_GATE_SETCLR(GATE_USBO, RCC_MP_AHB2ENSETR, 8), CFG_GATE_SETCLR(GATE_TSC, RCC_MP_AHB4ENSETR, 15), CFG_GATE_SETCLR(GATE_GPIOA, RCC_MP_NS_AHB4ENSETR, 0), CFG_GATE_SETCLR(GATE_GPIOB, RCC_MP_NS_AHB4ENSETR, 1), CFG_GATE_SETCLR(GATE_GPIOC, RCC_MP_NS_AHB4ENSETR, 2), CFG_GATE_SETCLR(GATE_GPIOD, RCC_MP_NS_AHB4ENSETR, 3), CFG_GATE_SETCLR(GATE_GPIOE, RCC_MP_NS_AHB4ENSETR, 4), CFG_GATE_SETCLR(GATE_GPIOF, RCC_MP_NS_AHB4ENSETR, 5), CFG_GATE_SETCLR(GATE_GPIOG, RCC_MP_NS_AHB4ENSETR, 6), CFG_GATE_SETCLR(GATE_GPIOH, RCC_MP_NS_AHB4ENSETR, 7), CFG_GATE_SETCLR(GATE_GPIOI, RCC_MP_NS_AHB4ENSETR, 8), CFG_GATE_SETCLR(GATE_PKA, RCC_MP_AHB5ENSETR, 2), CFG_GATE_SETCLR(GATE_SAES, RCC_MP_AHB5ENSETR, 3), CFG_GATE_SETCLR(GATE_CRYP1, RCC_MP_AHB5ENSETR, 4), CFG_GATE_SETCLR(GATE_HASH1, RCC_MP_AHB5ENSETR, 5), CFG_GATE_SETCLR(GATE_RNG1, RCC_MP_AHB5ENSETR, 6), CFG_GATE_SETCLR(GATE_BKPSRAM, RCC_MP_AHB5ENSETR, 8), CFG_GATE_SETCLR(GATE_AXIMC, RCC_MP_AHB5ENSETR, 16), CFG_GATE_SETCLR(GATE_MCE, RCC_MP_AHB6ENSETR, 1), CFG_GATE_SETCLR(GATE_ETH1CK, RCC_MP_AHB6ENSETR, 7), CFG_GATE_SETCLR(GATE_ETH1TX, RCC_MP_AHB6ENSETR, 8), CFG_GATE_SETCLR(GATE_ETH1RX, RCC_MP_AHB6ENSETR, 9), CFG_GATE_SETCLR(GATE_ETH1MAC, RCC_MP_AHB6ENSETR, 10), CFG_GATE_SETCLR(GATE_FMC, RCC_MP_AHB6ENSETR, 12), CFG_GATE_SETCLR(GATE_QSPI, RCC_MP_AHB6ENSETR, 14), CFG_GATE_SETCLR(GATE_SDMMC1, RCC_MP_AHB6ENSETR, 16), CFG_GATE_SETCLR(GATE_SDMMC2, RCC_MP_AHB6ENSETR, 17), CFG_GATE_SETCLR(GATE_CRC1, RCC_MP_AHB6ENSETR, 20), CFG_GATE_SETCLR(GATE_USBH, RCC_MP_AHB6ENSETR, 24), CFG_GATE_SETCLR(GATE_ETH2CK, RCC_MP_AHB6ENSETR, 27), CFG_GATE_SETCLR(GATE_ETH2TX, RCC_MP_AHB6ENSETR, 28), CFG_GATE_SETCLR(GATE_ETH2RX, RCC_MP_AHB6ENSETR, 29), CFG_GATE_SETCLR(GATE_ETH2MAC, RCC_MP_AHB6ENSETR, 30), CFG_GATE_SETCLR(GATE_ETH1STP, RCC_MP_AHB6LPENSETR, 11), CFG_GATE_SETCLR(GATE_ETH2STP, RCC_MP_AHB6LPENSETR, 31), CFG_GATE_SETCLR(GATE_MDMA, RCC_MP_NS_AHB6ENSETR, 0), }; /* STM32 Divivers definition */ enum enum_div_cfg { DIV_RTC, DIV_HSI, DIV_MCO1, DIV_MCO2, DIV_TRACE, DIV_ETH1PTP, DIV_ETH2PTP, DIV_NB }; static const struct clk_div_table ck_trace_div_table[] = { { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 }, { 4, 16 }, { 5, 16 }, { 6, 16 }, { 7, 16 }, { 0 }, }; #define CFG_DIV(_id, _offset, _shift, _width, _flags, _table, _ready)\ [(_id)] = {\ .offset = (_offset),\ .shift = (_shift),\ .width = (_width),\ .flags = (_flags),\ .table = (_table),\ .ready = (_ready),\ } static const struct stm32_div_cfg stm32mp13_dividers[DIV_NB] = { CFG_DIV(DIV_RTC, RCC_RTCDIVR, 0, 6, 0, NULL, DIV_NO_RDY), CFG_DIV(DIV_MCO1, RCC_MCO1CFGR, 4, 4, 0, NULL, DIV_NO_RDY), CFG_DIV(DIV_MCO2, RCC_MCO2CFGR, 4, 4, 0, NULL, DIV_NO_RDY), CFG_DIV(DIV_TRACE, RCC_DBGCFGR, 0, 3, 0, ck_trace_div_table, DIV_NO_RDY), CFG_DIV(DIV_ETH1PTP, RCC_ETH12CKSELR, 4, 4, 0, NULL, DIV_NO_RDY), CFG_DIV(DIV_ETH2PTP, RCC_ETH12CKSELR, 12, 4, 0, NULL, DIV_NO_RDY), }; /* STM32 Muxes definition */ enum enum_mux_cfg { MUX_ADC1, MUX_ADC2, MUX_DCMIPP, MUX_ETH1, MUX_ETH2, MUX_FDCAN, MUX_FMC, MUX_I2C12, MUX_I2C3, MUX_I2C4, MUX_I2C5, MUX_LPTIM1, MUX_LPTIM2, MUX_LPTIM3, MUX_LPTIM45, MUX_MCO1, MUX_MCO2, MUX_QSPI, MUX_RNG1, MUX_SAES, MUX_SAI1, MUX_SAI2, MUX_SDMMC1, MUX_SDMMC2, MUX_SPDIF, MUX_SPI1, MUX_SPI23, MUX_SPI4, MUX_SPI5, MUX_STGEN, MUX_UART1, MUX_UART2, MUX_UART4, MUX_UART6, MUX_UART35, MUX_UART78, MUX_USBO, MUX_USBPHY, MUX_NB }; #define _CFG_MUX(_id, _offset, _shift, _witdh, _ready, _flags)\ [_id] = {\ .offset = (_offset),\ .shift = (_shift),\ .width = (_witdh),\ .ready = (_ready),\ .flags = (_flags),\ } #define CFG_MUX(_id, _offset, _shift, _witdh)\ _CFG_MUX(_id, _offset, _shift, _witdh, MUX_NO_RDY, 0) #define CFG_MUX_SAFE(_id, _offset, _shift, _witdh)\ _CFG_MUX(_id, _offset, _shift, _witdh, MUX_NO_RDY, MUX_SAFE) static const struct stm32_mux_cfg stm32mp13_muxes[] = { CFG_MUX(MUX_I2C12, RCC_I2C12CKSELR, 0, 3), CFG_MUX(MUX_LPTIM45, RCC_LPTIM45CKSELR, 0, 3), CFG_MUX(MUX_SPI23, RCC_SPI2S23CKSELR, 0, 3), CFG_MUX(MUX_UART35, RCC_UART35CKSELR, 0, 3), CFG_MUX(MUX_UART78, RCC_UART78CKSELR, 0, 3), CFG_MUX(MUX_ADC1, RCC_ADC12CKSELR, 0, 2), CFG_MUX(MUX_ADC2, RCC_ADC12CKSELR, 2, 2), CFG_MUX(MUX_DCMIPP, RCC_DCMIPPCKSELR, 0, 2), CFG_MUX(MUX_ETH1, RCC_ETH12CKSELR, 0, 2), CFG_MUX(MUX_ETH2, RCC_ETH12CKSELR, 8, 2), CFG_MUX(MUX_FDCAN, RCC_FDCANCKSELR, 0, 2), CFG_MUX(MUX_I2C3, RCC_I2C345CKSELR, 0, 3), CFG_MUX(MUX_I2C4, RCC_I2C345CKSELR, 3, 3), CFG_MUX(MUX_I2C5, RCC_I2C345CKSELR, 6, 3), CFG_MUX(MUX_LPTIM1, RCC_LPTIM1CKSELR, 0, 3), CFG_MUX(MUX_LPTIM2, RCC_LPTIM23CKSELR, 0, 3), CFG_MUX(MUX_LPTIM3, RCC_LPTIM23CKSELR, 3, 3), CFG_MUX(MUX_MCO1, RCC_MCO1CFGR, 0, 3), CFG_MUX(MUX_MCO2, RCC_MCO2CFGR, 0, 3), CFG_MUX(MUX_RNG1, RCC_RNG1CKSELR, 0, 2), CFG_MUX(MUX_SAES, RCC_SAESCKSELR, 0, 2), CFG_MUX(MUX_SAI1, RCC_SAI1CKSELR, 0, 3), CFG_MUX(MUX_SAI2, RCC_SAI2CKSELR, 0, 3), CFG_MUX(MUX_SPDIF, RCC_SPDIFCKSELR, 0, 2), CFG_MUX(MUX_SPI1, RCC_SPI2S1CKSELR, 0, 3), CFG_MUX(MUX_SPI4, RCC_SPI45CKSELR, 0, 3), CFG_MUX(MUX_SPI5, RCC_SPI45CKSELR, 3, 3), CFG_MUX(MUX_STGEN, RCC_STGENCKSELR, 0, 2), CFG_MUX(MUX_UART1, RCC_UART12CKSELR, 0, 3), CFG_MUX(MUX_UART2, RCC_UART12CKSELR, 3, 3), CFG_MUX(MUX_UART4, RCC_UART4CKSELR, 0, 3), CFG_MUX(MUX_UART6, RCC_UART6CKSELR, 0, 3), CFG_MUX(MUX_USBO, RCC_USBCKSELR, 4, 1), CFG_MUX(MUX_USBPHY, RCC_USBCKSELR, 0, 2), CFG_MUX_SAFE(MUX_FMC, RCC_FMCCKSELR, 0, 2), CFG_MUX_SAFE(MUX_QSPI, RCC_QSPICKSELR, 0, 2), CFG_MUX_SAFE(MUX_SDMMC1, RCC_SDMMC12CKSELR, 0, 3), CFG_MUX_SAFE(MUX_SDMMC2, RCC_SDMMC12CKSELR, 3, 3), }; struct clk_stm32_securiy { u32 offset; u8 bit_idx; unsigned long scmi_id; }; enum security_clk { SECF_NONE, SECF_LPTIM2, SECF_LPTIM3, SECF_VREF, SECF_DCMIPP, SECF_USBPHY, SECF_TZC, SECF_ETZPC, SECF_IWDG1, SECF_BSEC, SECF_STGENC, SECF_STGENRO, SECF_USART1, SECF_USART2, SECF_SPI4, SECF_SPI5, SECF_I2C3, SECF_I2C4, SECF_I2C5, SECF_TIM12, SECF_TIM13, SECF_TIM14, SECF_TIM15, SECF_TIM16, SECF_TIM17, SECF_DMA3, SECF_DMAMUX2, SECF_ADC1, SECF_ADC2, SECF_USBO, SECF_TSC, SECF_PKA, SECF_SAES, SECF_CRYP1, SECF_HASH1, SECF_RNG1, SECF_BKPSRAM, SECF_MCE, SECF_FMC, SECF_QSPI, SECF_SDMMC1, SECF_SDMMC2, SECF_ETH1CK, SECF_ETH1TX, SECF_ETH1RX, SECF_ETH1MAC, SECF_ETH1STP, SECF_ETH2CK, SECF_ETH2TX, SECF_ETH2RX, SECF_ETH2MAC, SECF_ETH2STP, SECF_MCO1, SECF_MCO2 }; #define SECF(_sec_id, _offset, _bit_idx)[_sec_id] = {\ .offset = _offset,\ .bit_idx = _bit_idx,\ .scmi_id = -1,\ } static const struct clk_stm32_securiy stm32mp13_security[] = { SECF(SECF_LPTIM2, RCC_APB3SECSR, RCC_APB3SECSR_LPTIM2SECF), SECF(SECF_LPTIM3, RCC_APB3SECSR, RCC_APB3SECSR_LPTIM3SECF), SECF(SECF_VREF, RCC_APB3SECSR, RCC_APB3SECSR_VREFSECF), SECF(SECF_DCMIPP, RCC_APB4SECSR, RCC_APB4SECSR_DCMIPPSECF), SECF(SECF_USBPHY, RCC_APB4SECSR, RCC_APB4SECSR_USBPHYSECF), SECF(SECF_TZC, RCC_APB5SECSR, RCC_APB5SECSR_TZCSECF), SECF(SECF_ETZPC, RCC_APB5SECSR, RCC_APB5SECSR_ETZPCSECF), SECF(SECF_IWDG1, RCC_APB5SECSR, RCC_APB5SECSR_IWDG1SECF), SECF(SECF_BSEC, RCC_APB5SECSR, RCC_APB5SECSR_BSECSECF), SECF(SECF_STGENC, RCC_APB5SECSR, RCC_APB5SECSR_STGENCSECF), SECF(SECF_STGENRO, RCC_APB5SECSR, RCC_APB5SECSR_STGENROSECF), SECF(SECF_USART1, RCC_APB6SECSR, RCC_APB6SECSR_USART1SECF), SECF(SECF_USART2, RCC_APB6SECSR, RCC_APB6SECSR_USART2SECF), SECF(SECF_SPI4, RCC_APB6SECSR, RCC_APB6SECSR_SPI4SECF), SECF(SECF_SPI5, RCC_APB6SECSR, RCC_APB6SECSR_SPI5SECF), SECF(SECF_I2C3, RCC_APB6SECSR, RCC_APB6SECSR_I2C3SECF), SECF(SECF_I2C4, RCC_APB6SECSR, RCC_APB6SECSR_I2C4SECF), SECF(SECF_I2C5, RCC_APB6SECSR, RCC_APB6SECSR_I2C5SECF), SECF(SECF_TIM12, RCC_APB6SECSR, RCC_APB6SECSR_TIM12SECF), SECF(SECF_TIM13, RCC_APB6SECSR, RCC_APB6SECSR_TIM13SECF), SECF(SECF_TIM14, RCC_APB6SECSR, RCC_APB6SECSR_TIM14SECF), SECF(SECF_TIM15, RCC_APB6SECSR, RCC_APB6SECSR_TIM15SECF), SECF(SECF_TIM16, RCC_APB6SECSR, RCC_APB6SECSR_TIM16SECF), SECF(SECF_TIM17, RCC_APB6SECSR, RCC_APB6SECSR_TIM17SECF), SECF(SECF_DMA3, RCC_AHB2SECSR, RCC_AHB2SECSR_DMA3SECF), SECF(SECF_DMAMUX2, RCC_AHB2SECSR, RCC_AHB2SECSR_DMAMUX2SECF), SECF(SECF_ADC1, RCC_AHB2SECSR, RCC_AHB2SECSR_ADC1SECF), SECF(SECF_ADC2, RCC_AHB2SECSR, RCC_AHB2SECSR_ADC2SECF), SECF(SECF_USBO, RCC_AHB2SECSR, RCC_AHB2SECSR_USBOSECF), SECF(SECF_TSC, RCC_AHB4SECSR, RCC_AHB4SECSR_TSCSECF), SECF(SECF_PKA, RCC_AHB5SECSR, RCC_AHB5SECSR_PKASECF), SECF(SECF_SAES, RCC_AHB5SECSR, RCC_AHB5SECSR_SAESSECF), SECF(SECF_CRYP1, RCC_AHB5SECSR, RCC_AHB5SECSR_CRYP1SECF), SECF(SECF_HASH1, RCC_AHB5SECSR, RCC_AHB5SECSR_HASH1SECF), SECF(SECF_RNG1, RCC_AHB5SECSR, RCC_AHB5SECSR_RNG1SECF), SECF(SECF_BKPSRAM, RCC_AHB5SECSR, RCC_AHB5SECSR_BKPSRAMSECF), SECF(SECF_MCE, RCC_AHB6SECSR, RCC_AHB6SECSR_MCESECF), SECF(SECF_FMC, RCC_AHB6SECSR, RCC_AHB6SECSR_FMCSECF), SECF(SECF_QSPI, RCC_AHB6SECSR, RCC_AHB6SECSR_QSPISECF), SECF(SECF_SDMMC1, RCC_AHB6SECSR, RCC_AHB6SECSR_SDMMC1SECF), SECF(SECF_SDMMC2, RCC_AHB6SECSR, RCC_AHB6SECSR_SDMMC2SECF), SECF(SECF_ETH1CK, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH1CKSECF), SECF(SECF_ETH1TX, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH1TXSECF), SECF(SECF_ETH1RX, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH1RXSECF), SECF(SECF_ETH1MAC, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH1MACSECF), SECF(SECF_ETH1STP, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH1STPSECF), SECF(SECF_ETH2CK, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH2CKSECF), SECF(SECF_ETH2TX, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH2TXSECF), SECF(SECF_ETH2RX, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH2RXSECF), SECF(SECF_ETH2MAC, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH2MACSECF), SECF(SECF_ETH2STP, RCC_AHB6SECSR, RCC_AHB6SECSR_ETH2STPSECF), SECF(SECF_MCO1, RCC_SECCFGR, RCC_SECCFGR_MCO1SEC), SECF(SECF_MCO2, RCC_SECCFGR, RCC_SECCFGR_MCO2SEC), }; static const char * const adc12_src[] = { "pll4_r", "ck_per", "pll3_q" }; static const char * const dcmipp_src[] = { "ck_axi", "pll2_q", "pll4_p", "ck_per", }; static const char * const eth12_src[] = { "pll4_p", "pll3_q" }; static const char * const fdcan_src[] = { "ck_hse", "pll3_q", "pll4_q", "pll4_r" }; static const char * const fmc_src[] = { "ck_axi", "pll3_r", "pll4_p", "ck_per" }; static const char * const i2c12_src[] = { "pclk1", "pll4_r", "ck_hsi", "ck_csi" }; static const char * const i2c345_src[] = { "pclk6", "pll4_r", "ck_hsi", "ck_csi" }; static const char * const lptim1_src[] = { "pclk1", "pll4_p", "pll3_q", "ck_lse", "ck_lsi", "ck_per" }; static const char * const lptim23_src[] = { "pclk3", "pll4_q", "ck_per", "ck_lse", "ck_lsi" }; static const char * const lptim45_src[] = { "pclk3", "pll4_p", "pll3_q", "ck_lse", "ck_lsi", "ck_per" }; static const char * const mco1_src[] = { "ck_hsi", "ck_hse", "ck_csi", "ck_lsi", "ck_lse" }; static const char * const mco2_src[] = { "ck_mpu", "ck_axi", "ck_mlahb", "pll4_p", "ck_hse", "ck_hsi" }; static const char * const qspi_src[] = { "ck_axi", "pll3_r", "pll4_p", "ck_per" }; static const char * const rng1_src[] = { "ck_csi", "pll4_r", "ck_lse", "ck_lsi" }; static const char * const saes_src[] = { "ck_axi", "ck_per", "pll4_r", "ck_lsi" }; static const char * const sai1_src[] = { "pll4_q", "pll3_q", "i2s_ckin", "ck_per", "pll3_r" }; static const char * const sai2_src[] = { "pll4_q", "pll3_q", "i2s_ckin", "ck_per", "spdif_ck_symb", "pll3_r" }; static const char * const sdmmc12_src[] = { "ck_axi", "pll3_r", "pll4_p", "ck_hsi" }; static const char * const spdif_src[] = { "pll4_p", "pll3_q", "ck_hsi" }; static const char * const spi123_src[] = { "pll4_p", "pll3_q", "i2s_ckin", "ck_per", "pll3_r" }; static const char * const spi4_src[] = { "pclk6", "pll4_q", "ck_hsi", "ck_csi", "ck_hse", "i2s_ckin" }; static const char * const spi5_src[] = { "pclk6", "pll4_q", "ck_hsi", "ck_csi", "ck_hse" }; static const char * const stgen_src[] = { "ck_hsi", "ck_hse" }; static const char * const usart12_src[] = { "pclk6", "pll3_q", "ck_hsi", "ck_csi", "pll4_q", "ck_hse" }; static const char * const usart34578_src[] = { "pclk1", "pll4_q", "ck_hsi", "ck_csi", "ck_hse" }; static const char * const usart6_src[] = { "pclk2", "pll4_q", "ck_hsi", "ck_csi", "ck_hse" }; static const char * const usbo_src[] = { "pll4_r", "ck_usbo_48m" }; static const char * const usbphy_src[] = { "ck_hse", "pll4_r", "clk-hse-div2" }; /* Timer clocks */ static struct clk_stm32_gate tim2_k = { .gate_id = GATE_TIM2, .hw.init = CLK_HW_INIT("tim2_k", "timg1_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim3_k = { .gate_id = GATE_TIM3, .hw.init = CLK_HW_INIT("tim3_k", "timg1_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim4_k = { .gate_id = GATE_TIM4, .hw.init = CLK_HW_INIT("tim4_k", "timg1_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim5_k = { .gate_id = GATE_TIM5, .hw.init = CLK_HW_INIT("tim5_k", "timg1_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim6_k = { .gate_id = GATE_TIM6, .hw.init = CLK_HW_INIT("tim6_k", "timg1_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim7_k = { .gate_id = GATE_TIM7, .hw.init = CLK_HW_INIT("tim7_k", "timg1_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim1_k = { .gate_id = GATE_TIM1, .hw.init = CLK_HW_INIT("tim1_k", "timg2_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim8_k = { .gate_id = GATE_TIM8, .hw.init = CLK_HW_INIT("tim8_k", "timg2_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim12_k = { .gate_id = GATE_TIM12, .hw.init = CLK_HW_INIT("tim12_k", "timg3_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim13_k = { .gate_id = GATE_TIM13, .hw.init = CLK_HW_INIT("tim13_k", "timg3_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim14_k = { .gate_id = GATE_TIM14, .hw.init = CLK_HW_INIT("tim14_k", "timg3_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim15_k = { .gate_id = GATE_TIM15, .hw.init = CLK_HW_INIT("tim15_k", "timg3_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim16_k = { .gate_id = GATE_TIM16, .hw.init = CLK_HW_INIT("tim16_k", "timg3_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_gate tim17_k = { .gate_id = GATE_TIM17, .hw.init = CLK_HW_INIT("tim17_k", "timg3_ck", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; /* Peripheral clocks */ static struct clk_stm32_gate sai1 = { .gate_id = GATE_SAI1, .hw.init = CLK_HW_INIT("sai1", "pclk2", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate sai2 = { .gate_id = GATE_SAI2, .hw.init = CLK_HW_INIT("sai2", "pclk2", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate syscfg = { .gate_id = GATE_SYSCFG, .hw.init = CLK_HW_INIT("syscfg", "pclk3", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate vref = { .gate_id = GATE_VREF, .hw.init = CLK_HW_INIT("vref", "pclk3", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate dts = { .gate_id = GATE_DTS, .hw.init = CLK_HW_INIT("dts", "pclk3", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate pmbctrl = { .gate_id = GATE_PMBCTRL, .hw.init = CLK_HW_INIT("pmbctrl", "pclk3", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate hdp = { .gate_id = GATE_HDP, .hw.init = CLK_HW_INIT("hdp", "pclk3", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate iwdg2 = { .gate_id = GATE_IWDG2APB, .hw.init = CLK_HW_INIT("iwdg2", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate stgenro = { .gate_id = GATE_STGENRO, .hw.init = CLK_HW_INIT("stgenro", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpioa = { .gate_id = GATE_GPIOA, .hw.init = CLK_HW_INIT("gpioa", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpiob = { .gate_id = GATE_GPIOB, .hw.init = CLK_HW_INIT("gpiob", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpioc = { .gate_id = GATE_GPIOC, .hw.init = CLK_HW_INIT("gpioc", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpiod = { .gate_id = GATE_GPIOD, .hw.init = CLK_HW_INIT("gpiod", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpioe = { .gate_id = GATE_GPIOE, .hw.init = CLK_HW_INIT("gpioe", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpiof = { .gate_id = GATE_GPIOF, .hw.init = CLK_HW_INIT("gpiof", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpiog = { .gate_id = GATE_GPIOG, .hw.init = CLK_HW_INIT("gpiog", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpioh = { .gate_id = GATE_GPIOH, .hw.init = CLK_HW_INIT("gpioh", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate gpioi = { .gate_id = GATE_GPIOI, .hw.init = CLK_HW_INIT("gpioi", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate tsc = { .gate_id = GATE_TSC, .hw.init = CLK_HW_INIT("tsc", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate ddrperfm = { .gate_id = GATE_DDRPERFM, .hw.init = CLK_HW_INIT("ddrperfm", "pclk4", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate tzpc = { .gate_id = GATE_TZC, .hw.init = CLK_HW_INIT("tzpc", "pclk5", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate iwdg1 = { .gate_id = GATE_IWDG1APB, .hw.init = CLK_HW_INIT("iwdg1", "pclk5", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate bsec = { .gate_id = GATE_BSEC, .hw.init = CLK_HW_INIT("bsec", "pclk5", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate dma1 = { .gate_id = GATE_DMA1, .hw.init = CLK_HW_INIT("dma1", "ck_mlahb", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate dma2 = { .gate_id = GATE_DMA2, .hw.init = CLK_HW_INIT("dma2", "ck_mlahb", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate dmamux1 = { .gate_id = GATE_DMAMUX1, .hw.init = CLK_HW_INIT("dmamux1", "ck_mlahb", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate dma3 = { .gate_id = GATE_DMA3, .hw.init = CLK_HW_INIT("dma3", "ck_mlahb", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate dmamux2 = { .gate_id = GATE_DMAMUX2, .hw.init = CLK_HW_INIT("dmamux2", "ck_mlahb", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate adc1 = { .gate_id = GATE_ADC1, .hw.init = CLK_HW_INIT("adc1", "ck_mlahb", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate adc2 = { .gate_id = GATE_ADC2, .hw.init = CLK_HW_INIT("adc2", "ck_mlahb", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate pka = { .gate_id = GATE_PKA, .hw.init = CLK_HW_INIT("pka", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate cryp1 = { .gate_id = GATE_CRYP1, .hw.init = CLK_HW_INIT("cryp1", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate hash1 = { .gate_id = GATE_HASH1, .hw.init = CLK_HW_INIT("hash1", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate bkpsram = { .gate_id = GATE_BKPSRAM, .hw.init = CLK_HW_INIT("bkpsram", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate mdma = { .gate_id = GATE_MDMA, .hw.init = CLK_HW_INIT("mdma", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate eth1tx = { .gate_id = GATE_ETH1TX, .hw.init = CLK_HW_INIT("eth1tx", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate eth1rx = { .gate_id = GATE_ETH1RX, .hw.init = CLK_HW_INIT("eth1rx", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate eth1mac = { .gate_id = GATE_ETH1MAC, .hw.init = CLK_HW_INIT("eth1mac", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate eth2tx = { .gate_id = GATE_ETH2TX, .hw.init = CLK_HW_INIT("eth2tx", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate eth2rx = { .gate_id = GATE_ETH2RX, .hw.init = CLK_HW_INIT("eth2rx", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate eth2mac = { .gate_id = GATE_ETH2MAC, .hw.init = CLK_HW_INIT("eth2mac", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate crc1 = { .gate_id = GATE_CRC1, .hw.init = CLK_HW_INIT("crc1", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate usbh = { .gate_id = GATE_USBH, .hw.init = CLK_HW_INIT("usbh", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate eth1stp = { .gate_id = GATE_ETH1STP, .hw.init = CLK_HW_INIT("eth1stp", "ck_axi", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate eth2stp = { .gate_id = GATE_ETH2STP, .hw.init = CLK_HW_INIT("eth2stp", "ck_axi", &clk_stm32_gate_ops, 0), }; /* Kernel clocks */ static struct clk_stm32_composite sdmmc1_k = { .gate_id = GATE_SDMMC1, .mux_id = MUX_SDMMC1, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("sdmmc1_k", sdmmc12_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite sdmmc2_k = { .gate_id = GATE_SDMMC2, .mux_id = MUX_SDMMC2, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("sdmmc2_k", sdmmc12_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite fmc_k = { .gate_id = GATE_FMC, .mux_id = MUX_FMC, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("fmc_k", fmc_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite qspi_k = { .gate_id = GATE_QSPI, .mux_id = MUX_QSPI, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("qspi_k", qspi_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite spi2_k = { .gate_id = GATE_SPI2, .mux_id = MUX_SPI23, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("spi2_k", spi123_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite spi3_k = { .gate_id = GATE_SPI3, .mux_id = MUX_SPI23, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("spi3_k", spi123_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite i2c1_k = { .gate_id = GATE_I2C1, .mux_id = MUX_I2C12, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("i2c1_k", i2c12_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite i2c2_k = { .gate_id = GATE_I2C2, .mux_id = MUX_I2C12, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("i2c2_k", i2c12_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite lptim4_k = { .gate_id = GATE_LPTIM4, .mux_id = MUX_LPTIM45, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("lptim4_k", lptim45_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite lptim5_k = { .gate_id = GATE_LPTIM5, .mux_id = MUX_LPTIM45, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("lptim5_k", lptim45_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite usart3_k = { .gate_id = GATE_USART3, .mux_id = MUX_UART35, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("usart3_k", usart34578_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite uart5_k = { .gate_id = GATE_UART5, .mux_id = MUX_UART35, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("uart5_k", usart34578_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite uart7_k = { .gate_id = GATE_UART7, .mux_id = MUX_UART78, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("uart7_k", usart34578_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite uart8_k = { .gate_id = GATE_UART8, .mux_id = MUX_UART78, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("uart8_k", usart34578_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite sai1_k = { .gate_id = GATE_SAI1, .mux_id = MUX_SAI1, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("sai1_k", sai1_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite adfsdm_k = { .gate_id = GATE_ADFSDM, .mux_id = MUX_SAI1, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("adfsdm_k", sai1_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite sai2_k = { .gate_id = GATE_SAI2, .mux_id = MUX_SAI2, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("sai2_k", sai2_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite adc1_k = { .gate_id = GATE_ADC1, .mux_id = MUX_ADC1, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("adc1_k", adc12_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite adc2_k = { .gate_id = GATE_ADC2, .mux_id = MUX_ADC2, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("adc2_k", adc12_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite rng1_k = { .gate_id = GATE_RNG1, .mux_id = MUX_RNG1, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("rng1_k", rng1_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite usbphy_k = { .gate_id = GATE_USBPHY, .mux_id = MUX_USBPHY, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("usbphy_k", usbphy_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite stgen_k = { .gate_id = GATE_STGENC, .mux_id = MUX_STGEN, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("stgen_k", stgen_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite spdif_k = { .gate_id = GATE_SPDIF, .mux_id = MUX_SPDIF, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("spdif_k", spdif_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite spi1_k = { .gate_id = GATE_SPI1, .mux_id = MUX_SPI1, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("spi1_k", spi123_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite spi4_k = { .gate_id = GATE_SPI4, .mux_id = MUX_SPI4, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("spi4_k", spi4_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite spi5_k = { .gate_id = GATE_SPI5, .mux_id = MUX_SPI5, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("spi5_k", spi5_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite i2c3_k = { .gate_id = GATE_I2C3, .mux_id = MUX_I2C3, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("i2c3_k", i2c345_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite i2c4_k = { .gate_id = GATE_I2C4, .mux_id = MUX_I2C4, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("i2c4_k", i2c345_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite i2c5_k = { .gate_id = GATE_I2C5, .mux_id = MUX_I2C5, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("i2c5_k", i2c345_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite lptim1_k = { .gate_id = GATE_LPTIM1, .mux_id = MUX_LPTIM1, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("lptim1_k", lptim1_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite lptim2_k = { .gate_id = GATE_LPTIM2, .mux_id = MUX_LPTIM2, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("lptim2_k", lptim23_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite lptim3_k = { .gate_id = GATE_LPTIM3, .mux_id = MUX_LPTIM3, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("lptim3_k", lptim23_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite usart1_k = { .gate_id = GATE_USART1, .mux_id = MUX_UART1, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("usart1_k", usart12_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite usart2_k = { .gate_id = GATE_USART2, .mux_id = MUX_UART2, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("usart2_k", usart12_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite uart4_k = { .gate_id = GATE_UART4, .mux_id = MUX_UART4, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("uart4_k", usart34578_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite uart6_k = { .gate_id = GATE_USART6, .mux_id = MUX_UART6, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("uart6_k", usart6_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite fdcan_k = { .gate_id = GATE_FDCAN, .mux_id = MUX_FDCAN, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("fdcan_k", fdcan_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite dcmipp_k = { .gate_id = GATE_DCMIPP, .mux_id = MUX_DCMIPP, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("dcmipp_k", dcmipp_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite usbo_k = { .gate_id = GATE_USBO, .mux_id = MUX_USBO, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("usbo_k", usbo_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite saes_k = { .gate_id = GATE_SAES, .mux_id = MUX_SAES, .div_id = NO_STM32_DIV, .hw.init = CLK_HW_INIT_PARENTS("saes_k", saes_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_gate dfsdm_k = { .gate_id = GATE_DFSDM, .hw.init = CLK_HW_INIT("dfsdm_k", "ck_mlahb", &clk_stm32_gate_ops, 0), }; static struct clk_stm32_gate ltdc_px = { .gate_id = GATE_LTDC, .hw.init = CLK_HW_INIT("ltdc_px", "pll4_q", &clk_stm32_gate_ops, CLK_SET_RATE_PARENT), }; static struct clk_stm32_mux ck_ker_eth1 = { .mux_id = MUX_ETH1, .hw.init = CLK_HW_INIT_PARENTS("ck_ker_eth1", eth12_src, &clk_stm32_mux_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_gate eth1ck_k = { .gate_id = GATE_ETH1CK, .hw.init = CLK_HW_INIT_HW("eth1ck_k", &ck_ker_eth1.hw, &clk_stm32_gate_ops, 0), }; static struct clk_stm32_div eth1ptp_k = { .div_id = DIV_ETH1PTP, .hw.init = CLK_HW_INIT_HW("eth1ptp_k", &ck_ker_eth1.hw, &clk_stm32_divider_ops, CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_mux ck_ker_eth2 = { .mux_id = MUX_ETH2, .hw.init = CLK_HW_INIT_PARENTS("ck_ker_eth2", eth12_src, &clk_stm32_mux_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_gate eth2ck_k = { .gate_id = GATE_ETH2CK, .hw.init = CLK_HW_INIT_HW("eth2ck_k", &ck_ker_eth2.hw, &clk_stm32_gate_ops, 0), }; static struct clk_stm32_div eth2ptp_k = { .div_id = DIV_ETH2PTP, .hw.init = CLK_HW_INIT_HW("eth2ptp_k", &ck_ker_eth2.hw, &clk_stm32_divider_ops, CLK_SET_RATE_NO_REPARENT), }; static struct clk_stm32_composite ck_mco1 = { .gate_id = GATE_MCO1, .mux_id = MUX_MCO1, .div_id = DIV_MCO1, .hw.init = CLK_HW_INIT_PARENTS("ck_mco1", mco1_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT | CLK_IGNORE_UNUSED), }; static struct clk_stm32_composite ck_mco2 = { .gate_id = GATE_MCO2, .mux_id = MUX_MCO2, .div_id = DIV_MCO2, .hw.init = CLK_HW_INIT_PARENTS("ck_mco2", mco2_src, &clk_stm32_composite_ops, CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_NO_REPARENT | CLK_IGNORE_UNUSED), }; /* Debug clocks */ static struct clk_stm32_gate ck_sys_dbg = { .gate_id = GATE_DBGCK, .hw.init = CLK_HW_INIT("ck_sys_dbg", "ck_axi", &clk_stm32_gate_ops, CLK_IS_CRITICAL), }; static struct clk_stm32_composite ck_trace = { .gate_id = GATE_TRACECK, .mux_id = NO_STM32_MUX, .div_id = DIV_TRACE, .hw.init = CLK_HW_INIT("ck_trace", "ck_axi", &clk_stm32_composite_ops, CLK_IGNORE_UNUSED), }; static const struct clock_config stm32mp13_clock_cfg[] = { /* Timer clocks */ STM32_GATE_CFG(TIM2_K, tim2_k, SECF_NONE), STM32_GATE_CFG(TIM3_K, tim3_k, SECF_NONE), STM32_GATE_CFG(TIM4_K, tim4_k, SECF_NONE), STM32_GATE_CFG(TIM5_K, tim5_k, SECF_NONE), STM32_GATE_CFG(TIM6_K, tim6_k, SECF_NONE), STM32_GATE_CFG(TIM7_K, tim7_k, SECF_NONE), STM32_GATE_CFG(TIM1_K, tim1_k, SECF_NONE), STM32_GATE_CFG(TIM8_K, tim8_k, SECF_NONE), STM32_GATE_CFG(TIM12_K, tim12_k, SECF_TIM12), STM32_GATE_CFG(TIM13_K, tim13_k, SECF_TIM13), STM32_GATE_CFG(TIM14_K, tim14_k, SECF_TIM14), STM32_GATE_CFG(TIM15_K, tim15_k, SECF_TIM15), STM32_GATE_CFG(TIM16_K, tim16_k, SECF_TIM16), STM32_GATE_CFG(TIM17_K, tim17_k, SECF_TIM17), /* Peripheral clocks */ STM32_GATE_CFG(SAI1, sai1, SECF_NONE), STM32_GATE_CFG(SAI2, sai2, SECF_NONE), STM32_GATE_CFG(SYSCFG, syscfg, SECF_NONE), STM32_GATE_CFG(VREF, vref, SECF_VREF), STM32_GATE_CFG(DTS, dts, SECF_NONE), STM32_GATE_CFG(PMBCTRL, pmbctrl, SECF_NONE), STM32_GATE_CFG(HDP, hdp, SECF_NONE), STM32_GATE_CFG(IWDG2, iwdg2, SECF_NONE), STM32_GATE_CFG(STGENRO, stgenro, SECF_STGENRO), STM32_GATE_CFG(TZPC, tzpc, SECF_TZC), STM32_GATE_CFG(IWDG1, iwdg1, SECF_IWDG1), STM32_GATE_CFG(BSEC, bsec, SECF_BSEC), STM32_GATE_CFG(DMA1, dma1, SECF_NONE), STM32_GATE_CFG(DMA2, dma2, SECF_NONE), STM32_GATE_CFG(DMAMUX1, dmamux1, SECF_NONE), STM32_GATE_CFG(DMA3, dma3, SECF_DMA3), STM32_GATE_CFG(DMAMUX2, dmamux2, SECF_DMAMUX2), STM32_GATE_CFG(ADC1, adc1, SECF_ADC1), STM32_GATE_CFG(ADC2, adc2, SECF_ADC2), STM32_GATE_CFG(GPIOA, gpioa, SECF_NONE), STM32_GATE_CFG(GPIOB, gpiob, SECF_NONE), STM32_GATE_CFG(GPIOC, gpioc, SECF_NONE), STM32_GATE_CFG(GPIOD, gpiod, SECF_NONE), STM32_GATE_CFG(GPIOE, gpioe, SECF_NONE), STM32_GATE_CFG(GPIOF, gpiof, SECF_NONE), STM32_GATE_CFG(GPIOG, gpiog, SECF_NONE), STM32_GATE_CFG(GPIOH, gpioh, SECF_NONE), STM32_GATE_CFG(GPIOI, gpioi, SECF_NONE), STM32_GATE_CFG(TSC, tsc, SECF_TZC), STM32_GATE_CFG(PKA, pka, SECF_PKA), STM32_GATE_CFG(CRYP1, cryp1, SECF_CRYP1), STM32_GATE_CFG(HASH1, hash1, SECF_HASH1), STM32_GATE_CFG(BKPSRAM, bkpsram, SECF_BKPSRAM), STM32_GATE_CFG(MDMA, mdma, SECF_NONE), STM32_GATE_CFG(ETH1TX, eth1tx, SECF_ETH1TX), STM32_GATE_CFG(ETH1RX, eth1rx, SECF_ETH1RX), STM32_GATE_CFG(ETH1MAC, eth1mac, SECF_ETH1MAC), STM32_GATE_CFG(ETH2TX, eth2tx, SECF_ETH2TX), STM32_GATE_CFG(ETH2RX, eth2rx, SECF_ETH2RX), STM32_GATE_CFG(ETH2MAC, eth2mac, SECF_ETH2MAC), STM32_GATE_CFG(CRC1, crc1, SECF_NONE), STM32_GATE_CFG(USBH, usbh, SECF_NONE), STM32_GATE_CFG(DDRPERFM, ddrperfm, SECF_NONE), STM32_GATE_CFG(ETH1STP, eth1stp, SECF_ETH1STP), STM32_GATE_CFG(ETH2STP, eth2stp, SECF_ETH2STP), /* Kernel clocks */ STM32_COMPOSITE_CFG(SDMMC1_K, sdmmc1_k, SECF_SDMMC1), STM32_COMPOSITE_CFG(SDMMC2_K, sdmmc2_k, SECF_SDMMC2), STM32_COMPOSITE_CFG(FMC_K, fmc_k, SECF_FMC), STM32_COMPOSITE_CFG(QSPI_K, qspi_k, SECF_QSPI), STM32_COMPOSITE_CFG(SPI2_K, spi2_k, SECF_NONE), STM32_COMPOSITE_CFG(SPI3_K, spi3_k, SECF_NONE), STM32_COMPOSITE_CFG(I2C1_K, i2c1_k, SECF_NONE), STM32_COMPOSITE_CFG(I2C2_K, i2c2_k, SECF_NONE), STM32_COMPOSITE_CFG(LPTIM4_K, lptim4_k, SECF_NONE), STM32_COMPOSITE_CFG(LPTIM5_K, lptim5_k, SECF_NONE), STM32_COMPOSITE_CFG(USART3_K, usart3_k, SECF_NONE), STM32_COMPOSITE_CFG(UART5_K, uart5_k, SECF_NONE), STM32_COMPOSITE_CFG(UART7_K, uart7_k, SECF_NONE), STM32_COMPOSITE_CFG(UART8_K, uart8_k, SECF_NONE), STM32_COMPOSITE_CFG(SAI1_K, sai1_k, SECF_NONE), STM32_COMPOSITE_CFG(SAI2_K, sai2_k, SECF_NONE), STM32_COMPOSITE_CFG(ADFSDM_K, adfsdm_k, SECF_NONE), STM32_COMPOSITE_CFG(ADC1_K, adc1_k, SECF_ADC1), STM32_COMPOSITE_CFG(ADC2_K, adc2_k, SECF_ADC2), STM32_COMPOSITE_CFG(RNG1_K, rng1_k, SECF_RNG1), STM32_COMPOSITE_CFG(USBPHY_K, usbphy_k, SECF_USBPHY), STM32_COMPOSITE_CFG(STGEN_K, stgen_k, SECF_STGENC), STM32_COMPOSITE_CFG(SPDIF_K, spdif_k, SECF_NONE), STM32_COMPOSITE_CFG(SPI1_K, spi1_k, SECF_NONE), STM32_COMPOSITE_CFG(SPI4_K, spi4_k, SECF_SPI4), STM32_COMPOSITE_CFG(SPI5_K, spi5_k, SECF_SPI5), STM32_COMPOSITE_CFG(I2C3_K, i2c3_k, SECF_I2C3), STM32_COMPOSITE_CFG(I2C4_K, i2c4_k, SECF_I2C4), STM32_COMPOSITE_CFG(I2C5_K, i2c5_k, SECF_I2C5), STM32_COMPOSITE_CFG(LPTIM1_K, lptim1_k, SECF_NONE), STM32_COMPOSITE_CFG(LPTIM2_K, lptim2_k, SECF_LPTIM2), STM32_COMPOSITE_CFG(LPTIM3_K, lptim3_k, SECF_LPTIM3), STM32_COMPOSITE_CFG(USART1_K, usart1_k, SECF_USART1), STM32_COMPOSITE_CFG(USART2_K, usart2_k, SECF_USART2), STM32_COMPOSITE_CFG(UART4_K, uart4_k, SECF_NONE), STM32_COMPOSITE_CFG(USART6_K, uart6_k, SECF_NONE), STM32_COMPOSITE_CFG(FDCAN_K, fdcan_k, SECF_NONE), STM32_COMPOSITE_CFG(DCMIPP_K, dcmipp_k, SECF_DCMIPP), STM32_COMPOSITE_CFG(USBO_K, usbo_k, SECF_USBO), STM32_COMPOSITE_CFG(SAES_K, saes_k, SECF_SAES), STM32_GATE_CFG(DFSDM_K, dfsdm_k, SECF_NONE), STM32_GATE_CFG(LTDC_PX, ltdc_px, SECF_NONE), STM32_MUX_CFG(NO_ID, ck_ker_eth1, SECF_ETH1CK), STM32_GATE_CFG(ETH1CK_K, eth1ck_k, SECF_ETH1CK), STM32_DIV_CFG(ETH1PTP_K, eth1ptp_k, SECF_ETH1CK), STM32_MUX_CFG(NO_ID, ck_ker_eth2, SECF_ETH2CK), STM32_GATE_CFG(ETH2CK_K, eth2ck_k, SECF_ETH2CK), STM32_DIV_CFG(ETH2PTP_K, eth2ptp_k, SECF_ETH2CK), STM32_GATE_CFG(CK_DBG, ck_sys_dbg, SECF_NONE), STM32_COMPOSITE_CFG(CK_TRACE, ck_trace, SECF_NONE), STM32_COMPOSITE_CFG(CK_MCO1, ck_mco1, SECF_MCO1), STM32_COMPOSITE_CFG(CK_MCO2, ck_mco2, SECF_MCO2), }; static int stm32mp13_clock_is_provided_by_secure(void __iomem *base, const struct clock_config *cfg) { int sec_id = cfg->sec_id; if (sec_id != SECF_NONE) { const struct clk_stm32_securiy *secf; secf = &stm32mp13_security[sec_id]; return !!(readl(base + secf->offset) & BIT(secf->bit_idx)); } return 0; } struct multi_mux { struct clk_hw *hw1; struct clk_hw *hw2; }; static struct multi_mux *stm32_mp13_multi_mux[MUX_NB] = { [MUX_SPI23] = &(struct multi_mux){ &spi2_k.hw, &spi3_k.hw }, [MUX_I2C12] = &(struct multi_mux){ &i2c1_k.hw, &i2c2_k.hw }, [MUX_LPTIM45] = &(struct multi_mux){ &lptim4_k.hw, &lptim5_k.hw }, [MUX_UART35] = &(struct multi_mux){ &usart3_k.hw, &uart5_k.hw }, [MUX_UART78] = &(struct multi_mux){ &uart7_k.hw, &uart8_k.hw }, [MUX_SAI1] = &(struct multi_mux){ &sai1_k.hw, &adfsdm_k.hw }, }; static struct clk_hw *stm32mp13_is_multi_mux(struct clk_hw *hw) { struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); struct multi_mux *mmux = stm32_mp13_multi_mux[composite->mux_id]; if (mmux) { if (!(mmux->hw1 == hw)) return mmux->hw1; else return mmux->hw2; } return NULL; } static u16 stm32mp13_cpt_gate[GATE_NB]; static struct clk_stm32_clock_data stm32mp13_clock_data = { .gate_cpt = stm32mp13_cpt_gate, .gates = stm32mp13_gates, .muxes = stm32mp13_muxes, .dividers = stm32mp13_dividers, .is_multi_mux = stm32mp13_is_multi_mux, }; static const struct stm32_rcc_match_data stm32mp13_data = { .tab_clocks = stm32mp13_clock_cfg, .num_clocks = ARRAY_SIZE(stm32mp13_clock_cfg), .clock_data = &stm32mp13_clock_data, .check_security = &stm32mp13_clock_is_provided_by_secure, .maxbinding = STM32MP1_LAST_CLK, .clear_offset = RCC_CLR_OFFSET, }; static const struct of_device_id stm32mp13_match_data[] = { { .compatible = "st,stm32mp13-rcc", .data = &stm32mp13_data, }, { } }; MODULE_DEVICE_TABLE(of, stm32mp13_match_data); static int stm32mp1_rcc_init(struct device *dev) { void __iomem *rcc_base; int ret = -ENOMEM; rcc_base = of_iomap(dev_of_node(dev), 0); if (!rcc_base) { dev_err(dev, "%pOFn: unable to map resource", dev_of_node(dev)); goto out; } ret = stm32_rcc_init(dev, stm32mp13_match_data, rcc_base); out: if (ret) { if (rcc_base) iounmap(rcc_base); of_node_put(dev_of_node(dev)); } return ret; } static int get_clock_deps(struct device *dev) { static const char * const clock_deps_name[] = { "hsi", "hse", "csi", "lsi", "lse", }; size_t deps_size = sizeof(struct clk *) * ARRAY_SIZE(clock_deps_name); struct clk **clk_deps; int i; clk_deps = devm_kzalloc(dev, deps_size, GFP_KERNEL); if (!clk_deps) return -ENOMEM; for (i = 0; i < ARRAY_SIZE(clock_deps_name); i++) { struct clk *clk = of_clk_get_by_name(dev_of_node(dev), clock_deps_name[i]); if (IS_ERR(clk)) { if (PTR_ERR(clk) != -EINVAL && PTR_ERR(clk) != -ENOENT) return PTR_ERR(clk); } else { /* Device gets a reference count on the clock */ clk_deps[i] = devm_clk_get(dev, __clk_get_name(clk)); clk_put(clk); } } return 0; } static int stm32mp1_rcc_clocks_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; int ret = get_clock_deps(dev); if (!ret) ret = stm32mp1_rcc_init(dev); return ret; } static void stm32mp1_rcc_clocks_remove(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *child, *np = dev_of_node(dev); for_each_available_child_of_node(np, child) of_clk_del_provider(child); } static struct platform_driver stm32mp13_rcc_clocks_driver = { .driver = { .name = "stm32mp13_rcc", .of_match_table = stm32mp13_match_data, }, .probe = stm32mp1_rcc_clocks_probe, .remove_new = stm32mp1_rcc_clocks_remove, }; static int __init stm32mp13_clocks_init(void) { return platform_driver_register(&stm32mp13_rcc_clocks_driver); } core_initcall(stm32mp13_clocks_init);
linux-master
drivers/clk/stm32/clk-stm32mp13.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2013 Emilio López * Emilio López <[email protected]> * * Copyright 2013 Chen-Yu Tsai * Chen-Yu Tsai <[email protected]> */ #include <linux/clk-provider.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/slab.h> static DEFINE_SPINLOCK(gmac_lock); /** * sun7i_a20_gmac_clk_setup - Setup function for A20/A31 GMAC clock module * * This clock looks something like this * ________________________ * MII TX clock from PHY >-----|___________ _________|----> to GMAC core * GMAC Int. RGMII TX clk >----|___________\__/__gate---|----> to PHY * Ext. 125MHz RGMII TX clk >--|__divider__/ | * |________________________| * * The external 125 MHz reference is optional, i.e. GMAC can use its * internal TX clock just fine. The A31 GMAC clock module does not have * the divider controls for the external reference. * * To keep it simple, let the GMAC use either the MII TX clock for MII mode, * and its internal TX clock for GMII and RGMII modes. The GMAC driver should * select the appropriate source and gate/ungate the output to the PHY. * * Only the GMAC should use this clock. Altering the clock so that it doesn't * match the GMAC's operation parameters will result in the GMAC not being * able to send traffic out. The GMAC driver should set the clock rate and * enable/disable this clock to configure the required state. The clock * driver then responds by auto-reparenting the clock. */ #define SUN7I_A20_GMAC_GPIT 2 #define SUN7I_A20_GMAC_MASK 0x3 #define SUN7I_A20_GMAC_PARENTS 2 static u32 sun7i_a20_gmac_mux_table[SUN7I_A20_GMAC_PARENTS] = { 0x00, /* Select mii_phy_tx_clk */ 0x02, /* Select gmac_int_tx_clk */ }; static void __init sun7i_a20_gmac_clk_setup(struct device_node *node) { struct clk *clk; struct clk_mux *mux; struct clk_gate *gate; const char *clk_name = node->name; const char *parents[SUN7I_A20_GMAC_PARENTS]; void __iomem *reg; if (of_property_read_string(node, "clock-output-names", &clk_name)) return; /* allocate mux and gate clock structs */ mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL); if (!mux) return; gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL); if (!gate) goto free_mux; /* gmac clock requires exactly 2 parents */ if (of_clk_parent_fill(node, parents, 2) != 2) goto free_gate; reg = of_iomap(node, 0); if (!reg) goto free_gate; /* set up gate and fixed rate properties */ gate->reg = reg; gate->bit_idx = SUN7I_A20_GMAC_GPIT; gate->lock = &gmac_lock; mux->reg = reg; mux->mask = SUN7I_A20_GMAC_MASK; mux->table = sun7i_a20_gmac_mux_table; mux->lock = &gmac_lock; clk = clk_register_composite(NULL, clk_name, parents, SUN7I_A20_GMAC_PARENTS, &mux->hw, &clk_mux_ops, NULL, NULL, &gate->hw, &clk_gate_ops, 0); if (IS_ERR(clk)) goto iounmap_reg; of_clk_add_provider(node, of_clk_src_simple_get, clk); return; iounmap_reg: iounmap(reg); free_gate: kfree(gate); free_mux: kfree(mux); } CLK_OF_DECLARE(sun7i_a20_gmac, "allwinner,sun7i-a20-gmac-clk", sun7i_a20_gmac_clk_setup);
linux-master
drivers/clk/sunxi/clk-a20-gmac.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2013 Emilio López * * Emilio López <[email protected]> */ #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/io.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/slab.h> #include "clk-factors.h" /* * sun4i_a10_get_mod0_factors() - calculates m, n factors for MOD0-style clocks * MOD0 rate is calculated as follows * rate = (parent_rate >> p) / (m + 1); */ static void sun4i_a10_get_mod0_factors(struct factors_request *req) { u8 div, calcm, calcp; /* These clocks can only divide, so we will never be able to achieve * frequencies higher than the parent frequency */ if (req->rate > req->parent_rate) req->rate = req->parent_rate; div = DIV_ROUND_UP(req->parent_rate, req->rate); if (div < 16) calcp = 0; else if (div / 2 < 16) calcp = 1; else if (div / 4 < 16) calcp = 2; else calcp = 3; calcm = DIV_ROUND_UP(div, 1 << calcp); req->rate = (req->parent_rate >> calcp) / calcm; req->m = calcm - 1; req->p = calcp; } /* user manual says "n" but it's really "p" */ static const struct clk_factors_config sun4i_a10_mod0_config = { .mshift = 0, .mwidth = 4, .pshift = 16, .pwidth = 2, }; static const struct factors_data sun4i_a10_mod0_data = { .enable = 31, .mux = 24, .muxmask = BIT(1) | BIT(0), .table = &sun4i_a10_mod0_config, .getter = sun4i_a10_get_mod0_factors, }; static DEFINE_SPINLOCK(sun4i_a10_mod0_lock); static void __init sun4i_a10_mod0_setup(struct device_node *node) { void __iomem *reg; reg = of_iomap(node, 0); if (!reg) { /* * This happens with mod0 clk nodes instantiated through * mfd, as those do not have their resources assigned at * CLK_OF_DECLARE time yet, so do not print an error. */ return; } sunxi_factors_register(node, &sun4i_a10_mod0_data, &sun4i_a10_mod0_lock, reg); } CLK_OF_DECLARE_DRIVER(sun4i_a10_mod0, "allwinner,sun4i-a10-mod0-clk", sun4i_a10_mod0_setup); static int sun4i_a10_mod0_clk_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; void __iomem *reg; if (!np) return -ENODEV; reg = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(reg)) return PTR_ERR(reg); sunxi_factors_register(np, &sun4i_a10_mod0_data, &sun4i_a10_mod0_lock, reg); return 0; } static const struct of_device_id sun4i_a10_mod0_clk_dt_ids[] = { { .compatible = "allwinner,sun4i-a10-mod0-clk" }, { /* sentinel */ } }; static struct platform_driver sun4i_a10_mod0_clk_driver = { .driver = { .name = "sun4i-a10-mod0-clk", .of_match_table = sun4i_a10_mod0_clk_dt_ids, }, .probe = sun4i_a10_mod0_clk_probe, }; builtin_platform_driver(sun4i_a10_mod0_clk_driver); static const struct factors_data sun9i_a80_mod0_data __initconst = { .enable = 31, .mux = 24, .muxmask = BIT(3) | BIT(2) | BIT(1) | BIT(0), .table = &sun4i_a10_mod0_config, .getter = sun4i_a10_get_mod0_factors, }; static void __init sun9i_a80_mod0_setup(struct device_node *node) { void __iomem *reg; reg = of_io_request_and_map(node, 0, of_node_full_name(node)); if (IS_ERR(reg)) { pr_err("Could not get registers for mod0-clk: %pOFn\n", node); return; } sunxi_factors_register(node, &sun9i_a80_mod0_data, &sun4i_a10_mod0_lock, reg); } CLK_OF_DECLARE(sun9i_a80_mod0, "allwinner,sun9i-a80-mod0-clk", sun9i_a80_mod0_setup); static DEFINE_SPINLOCK(sun5i_a13_mbus_lock); static void __init sun5i_a13_mbus_setup(struct device_node *node) { void __iomem *reg; reg = of_iomap(node, 0); if (!reg) { pr_err("Could not get registers for a13-mbus-clk\n"); return; } /* The MBUS clocks needs to be always enabled */ sunxi_factors_register_critical(node, &sun4i_a10_mod0_data, &sun5i_a13_mbus_lock, reg); } CLK_OF_DECLARE(sun5i_a13_mbus, "allwinner,sun5i-a13-mbus-clk", sun5i_a13_mbus_setup); struct mmc_phase { struct clk_hw hw; u8 offset; void __iomem *reg; spinlock_t *lock; }; #define to_mmc_phase(_hw) container_of(_hw, struct mmc_phase, hw) static int mmc_get_phase(struct clk_hw *hw) { struct clk *mmc, *mmc_parent, *clk = hw->clk; struct mmc_phase *phase = to_mmc_phase(hw); unsigned int mmc_rate, mmc_parent_rate; u16 step, mmc_div; u32 value; u8 delay; value = readl(phase->reg); delay = (value >> phase->offset) & 0x3; if (!delay) return 180; /* Get the main MMC clock */ mmc = clk_get_parent(clk); if (!mmc) return -EINVAL; /* And its rate */ mmc_rate = clk_get_rate(mmc); if (!mmc_rate) return -EINVAL; /* Now, get the MMC parent (most likely some PLL) */ mmc_parent = clk_get_parent(mmc); if (!mmc_parent) return -EINVAL; /* And its rate */ mmc_parent_rate = clk_get_rate(mmc_parent); if (!mmc_parent_rate) return -EINVAL; /* Get MMC clock divider */ mmc_div = mmc_parent_rate / mmc_rate; step = DIV_ROUND_CLOSEST(360, mmc_div); return delay * step; } static int mmc_set_phase(struct clk_hw *hw, int degrees) { struct clk *mmc, *mmc_parent, *clk = hw->clk; struct mmc_phase *phase = to_mmc_phase(hw); unsigned int mmc_rate, mmc_parent_rate; unsigned long flags; u32 value; u8 delay; /* Get the main MMC clock */ mmc = clk_get_parent(clk); if (!mmc) return -EINVAL; /* And its rate */ mmc_rate = clk_get_rate(mmc); if (!mmc_rate) return -EINVAL; /* Now, get the MMC parent (most likely some PLL) */ mmc_parent = clk_get_parent(mmc); if (!mmc_parent) return -EINVAL; /* And its rate */ mmc_parent_rate = clk_get_rate(mmc_parent); if (!mmc_parent_rate) return -EINVAL; if (degrees != 180) { u16 step, mmc_div; /* Get MMC clock divider */ mmc_div = mmc_parent_rate / mmc_rate; /* * We can only outphase the clocks by multiple of the * PLL's period. * * Since the MMC clock in only a divider, and the * formula to get the outphasing in degrees is deg = * 360 * delta / period * * If we simplify this formula, we can see that the * only thing that we're concerned about is the number * of period we want to outphase our clock from, and * the divider set by the MMC clock. */ step = DIV_ROUND_CLOSEST(360, mmc_div); delay = DIV_ROUND_CLOSEST(degrees, step); } else { delay = 0; } spin_lock_irqsave(phase->lock, flags); value = readl(phase->reg); value &= ~GENMASK(phase->offset + 3, phase->offset); value |= delay << phase->offset; writel(value, phase->reg); spin_unlock_irqrestore(phase->lock, flags); return 0; } static const struct clk_ops mmc_clk_ops = { .get_phase = mmc_get_phase, .set_phase = mmc_set_phase, }; /* * sunxi_mmc_setup - Common setup function for mmc module clocks * * The only difference between module clocks on different platforms is the * width of the mux register bits and the valid values, which are passed in * through struct factors_data. The phase clocks parts are identical. */ static void __init sunxi_mmc_setup(struct device_node *node, const struct factors_data *data, spinlock_t *lock) { struct clk_onecell_data *clk_data; const char *parent; void __iomem *reg; int i; reg = of_io_request_and_map(node, 0, of_node_full_name(node)); if (IS_ERR(reg)) { pr_err("Couldn't map the %pOFn clock registers\n", node); return; } clk_data = kmalloc(sizeof(*clk_data), GFP_KERNEL); if (!clk_data) return; clk_data->clks = kcalloc(3, sizeof(*clk_data->clks), GFP_KERNEL); if (!clk_data->clks) goto err_free_data; clk_data->clk_num = 3; clk_data->clks[0] = sunxi_factors_register(node, data, lock, reg); if (!clk_data->clks[0]) goto err_free_clks; parent = __clk_get_name(clk_data->clks[0]); for (i = 1; i < 3; i++) { struct clk_init_data init = { .num_parents = 1, .parent_names = &parent, .ops = &mmc_clk_ops, }; struct mmc_phase *phase; phase = kmalloc(sizeof(*phase), GFP_KERNEL); if (!phase) continue; phase->hw.init = &init; phase->reg = reg; phase->lock = lock; if (i == 1) phase->offset = 8; else phase->offset = 20; if (of_property_read_string_index(node, "clock-output-names", i, &init.name)) init.name = node->name; clk_data->clks[i] = clk_register(NULL, &phase->hw); if (IS_ERR(clk_data->clks[i])) { kfree(phase); continue; } } of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); return; err_free_clks: kfree(clk_data->clks); err_free_data: kfree(clk_data); } static DEFINE_SPINLOCK(sun4i_a10_mmc_lock); static void __init sun4i_a10_mmc_setup(struct device_node *node) { sunxi_mmc_setup(node, &sun4i_a10_mod0_data, &sun4i_a10_mmc_lock); } CLK_OF_DECLARE(sun4i_a10_mmc, "allwinner,sun4i-a10-mmc-clk", sun4i_a10_mmc_setup); static DEFINE_SPINLOCK(sun9i_a80_mmc_lock); static void __init sun9i_a80_mmc_setup(struct device_node *node) { sunxi_mmc_setup(node, &sun9i_a80_mod0_data, &sun9i_a80_mmc_lock); } CLK_OF_DECLARE(sun9i_a80_mmc, "allwinner,sun9i-a80-mmc-clk", sun9i_a80_mmc_setup);
linux-master
drivers/clk/sunxi/clk-mod0.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2013 Emilio López * * Emilio López <[email protected]> */ #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/clkdev.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/reset-controller.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/log2.h> #include "clk-factors.h" static DEFINE_SPINLOCK(clk_lock); /* Maximum number of parents our clocks have */ #define SUNXI_MAX_PARENTS 5 /* * sun4i_get_pll1_factors() - calculates n, k, m, p factors for PLL1 * PLL1 rate is calculated as follows * rate = (parent_rate * n * (k + 1) >> p) / (m + 1); * parent_rate is always 24Mhz */ static void sun4i_get_pll1_factors(struct factors_request *req) { u8 div; /* Normalize value to a 6M multiple */ div = req->rate / 6000000; req->rate = 6000000 * div; /* m is always zero for pll1 */ req->m = 0; /* k is 1 only on these cases */ if (req->rate >= 768000000 || req->rate == 42000000 || req->rate == 54000000) req->k = 1; else req->k = 0; /* p will be 3 for divs under 10 */ if (div < 10) req->p = 3; /* p will be 2 for divs between 10 - 20 and odd divs under 32 */ else if (div < 20 || (div < 32 && (div & 1))) req->p = 2; /* p will be 1 for even divs under 32, divs under 40 and odd pairs * of divs between 40-62 */ else if (div < 40 || (div < 64 && (div & 2))) req->p = 1; /* any other entries have p = 0 */ else req->p = 0; /* calculate a suitable n based on k and p */ div <<= req->p; div /= (req->k + 1); req->n = div / 4; } /* * sun6i_a31_get_pll1_factors() - calculates n, k and m factors for PLL1 * PLL1 rate is calculated as follows * rate = parent_rate * (n + 1) * (k + 1) / (m + 1); * parent_rate should always be 24MHz */ static void sun6i_a31_get_pll1_factors(struct factors_request *req) { /* * We can operate only on MHz, this will make our life easier * later. */ u32 freq_mhz = req->rate / 1000000; u32 parent_freq_mhz = req->parent_rate / 1000000; /* * Round down the frequency to the closest multiple of either * 6 or 16 */ u32 round_freq_6 = rounddown(freq_mhz, 6); u32 round_freq_16 = round_down(freq_mhz, 16); if (round_freq_6 > round_freq_16) freq_mhz = round_freq_6; else freq_mhz = round_freq_16; req->rate = freq_mhz * 1000000; /* If the frequency is a multiple of 32 MHz, k is always 3 */ if (!(freq_mhz % 32)) req->k = 3; /* If the frequency is a multiple of 9 MHz, k is always 2 */ else if (!(freq_mhz % 9)) req->k = 2; /* If the frequency is a multiple of 8 MHz, k is always 1 */ else if (!(freq_mhz % 8)) req->k = 1; /* Otherwise, we don't use the k factor */ else req->k = 0; /* * If the frequency is a multiple of 2 but not a multiple of * 3, m is 3. This is the first time we use 6 here, yet we * will use it on several other places. * We use this number because it's the lowest frequency we can * generate (with n = 0, k = 0, m = 3), so every other frequency * somehow relates to this frequency. */ if ((freq_mhz % 6) == 2 || (freq_mhz % 6) == 4) req->m = 2; /* * If the frequency is a multiple of 6MHz, but the factor is * odd, m will be 3 */ else if ((freq_mhz / 6) & 1) req->m = 3; /* Otherwise, we end up with m = 1 */ else req->m = 1; /* Calculate n thanks to the above factors we already got */ req->n = freq_mhz * (req->m + 1) / ((req->k + 1) * parent_freq_mhz) - 1; /* * If n end up being outbound, and that we can still decrease * m, do it. */ if ((req->n + 1) > 31 && (req->m + 1) > 1) { req->n = (req->n + 1) / 2 - 1; req->m = (req->m + 1) / 2 - 1; } } /* * sun8i_a23_get_pll1_factors() - calculates n, k, m, p factors for PLL1 * PLL1 rate is calculated as follows * rate = (parent_rate * (n + 1) * (k + 1) >> p) / (m + 1); * parent_rate is always 24Mhz */ static void sun8i_a23_get_pll1_factors(struct factors_request *req) { u8 div; /* Normalize value to a 6M multiple */ div = req->rate / 6000000; req->rate = 6000000 * div; /* m is always zero for pll1 */ req->m = 0; /* k is 1 only on these cases */ if (req->rate >= 768000000 || req->rate == 42000000 || req->rate == 54000000) req->k = 1; else req->k = 0; /* p will be 2 for divs under 20 and odd divs under 32 */ if (div < 20 || (div < 32 && (div & 1))) req->p = 2; /* p will be 1 for even divs under 32, divs under 40 and odd pairs * of divs between 40-62 */ else if (div < 40 || (div < 64 && (div & 2))) req->p = 1; /* any other entries have p = 0 */ else req->p = 0; /* calculate a suitable n based on k and p */ div <<= req->p; div /= (req->k + 1); req->n = div / 4 - 1; } /* * sun4i_get_pll5_factors() - calculates n, k factors for PLL5 * PLL5 rate is calculated as follows * rate = parent_rate * n * (k + 1) * parent_rate is always 24Mhz */ static void sun4i_get_pll5_factors(struct factors_request *req) { u8 div; /* Normalize value to a parent_rate multiple (24M) */ div = req->rate / req->parent_rate; req->rate = req->parent_rate * div; if (div < 31) req->k = 0; else if (div / 2 < 31) req->k = 1; else if (div / 3 < 31) req->k = 2; else req->k = 3; req->n = DIV_ROUND_UP(div, (req->k + 1)); } /* * sun6i_a31_get_pll6_factors() - calculates n, k factors for A31 PLL6x2 * PLL6x2 rate is calculated as follows * rate = parent_rate * (n + 1) * (k + 1) * parent_rate is always 24Mhz */ static void sun6i_a31_get_pll6_factors(struct factors_request *req) { u8 div; /* Normalize value to a parent_rate multiple (24M) */ div = req->rate / req->parent_rate; req->rate = req->parent_rate * div; req->k = div / 32; if (req->k > 3) req->k = 3; req->n = DIV_ROUND_UP(div, (req->k + 1)) - 1; } /* * sun5i_a13_get_ahb_factors() - calculates m, p factors for AHB * AHB rate is calculated as follows * rate = parent_rate >> p */ static void sun5i_a13_get_ahb_factors(struct factors_request *req) { u32 div; /* divide only */ if (req->parent_rate < req->rate) req->rate = req->parent_rate; /* * user manual says valid speed is 8k ~ 276M, but tests show it * can work at speeds up to 300M, just after reparenting to pll6 */ if (req->rate < 8000) req->rate = 8000; if (req->rate > 300000000) req->rate = 300000000; div = order_base_2(DIV_ROUND_UP(req->parent_rate, req->rate)); /* p = 0 ~ 3 */ if (div > 3) div = 3; req->rate = req->parent_rate >> div; req->p = div; } #define SUN6I_AHB1_PARENT_PLL6 3 /* * sun6i_a31_get_ahb_factors() - calculates m, p factors for AHB * AHB rate is calculated as follows * rate = parent_rate >> p * * if parent is pll6, then * parent_rate = pll6 rate / (m + 1) */ static void sun6i_get_ahb1_factors(struct factors_request *req) { u8 div, calcp, calcm = 1; /* * clock can only divide, so we will never be able to achieve * frequencies higher than the parent frequency */ if (req->parent_rate && req->rate > req->parent_rate) req->rate = req->parent_rate; div = DIV_ROUND_UP(req->parent_rate, req->rate); /* calculate pre-divider if parent is pll6 */ if (req->parent_index == SUN6I_AHB1_PARENT_PLL6) { if (div < 4) calcp = 0; else if (div / 2 < 4) calcp = 1; else if (div / 4 < 4) calcp = 2; else calcp = 3; calcm = DIV_ROUND_UP(div, 1 << calcp); } else { calcp = __roundup_pow_of_two(div); calcp = calcp > 3 ? 3 : calcp; } req->rate = (req->parent_rate / calcm) >> calcp; req->p = calcp; req->m = calcm - 1; } /* * sun6i_ahb1_recalc() - calculates AHB clock rate from m, p factors and * parent index */ static void sun6i_ahb1_recalc(struct factors_request *req) { req->rate = req->parent_rate; /* apply pre-divider first if parent is pll6 */ if (req->parent_index == SUN6I_AHB1_PARENT_PLL6) req->rate /= req->m + 1; /* clk divider */ req->rate >>= req->p; } /* * sun4i_get_apb1_factors() - calculates m, p factors for APB1 * APB1 rate is calculated as follows * rate = (parent_rate >> p) / (m + 1); */ static void sun4i_get_apb1_factors(struct factors_request *req) { u8 calcm, calcp; int div; if (req->parent_rate < req->rate) req->rate = req->parent_rate; div = DIV_ROUND_UP(req->parent_rate, req->rate); /* Invalid rate! */ if (div > 32) return; if (div <= 4) calcp = 0; else if (div <= 8) calcp = 1; else if (div <= 16) calcp = 2; else calcp = 3; calcm = (div >> calcp) - 1; req->rate = (req->parent_rate >> calcp) / (calcm + 1); req->m = calcm; req->p = calcp; } /* * sun7i_a20_get_out_factors() - calculates m, p factors for CLK_OUT_A/B * CLK_OUT rate is calculated as follows * rate = (parent_rate >> p) / (m + 1); */ static void sun7i_a20_get_out_factors(struct factors_request *req) { u8 div, calcm, calcp; /* These clocks can only divide, so we will never be able to achieve * frequencies higher than the parent frequency */ if (req->rate > req->parent_rate) req->rate = req->parent_rate; div = DIV_ROUND_UP(req->parent_rate, req->rate); if (div < 32) calcp = 0; else if (div / 2 < 32) calcp = 1; else if (div / 4 < 32) calcp = 2; else calcp = 3; calcm = DIV_ROUND_UP(div, 1 << calcp); req->rate = (req->parent_rate >> calcp) / calcm; req->m = calcm - 1; req->p = calcp; } /* * sunxi_factors_clk_setup() - Setup function for factor clocks */ static const struct clk_factors_config sun4i_pll1_config = { .nshift = 8, .nwidth = 5, .kshift = 4, .kwidth = 2, .mshift = 0, .mwidth = 2, .pshift = 16, .pwidth = 2, }; static const struct clk_factors_config sun6i_a31_pll1_config = { .nshift = 8, .nwidth = 5, .kshift = 4, .kwidth = 2, .mshift = 0, .mwidth = 2, .n_start = 1, }; static const struct clk_factors_config sun8i_a23_pll1_config = { .nshift = 8, .nwidth = 5, .kshift = 4, .kwidth = 2, .mshift = 0, .mwidth = 2, .pshift = 16, .pwidth = 2, .n_start = 1, }; static const struct clk_factors_config sun4i_pll5_config = { .nshift = 8, .nwidth = 5, .kshift = 4, .kwidth = 2, }; static const struct clk_factors_config sun6i_a31_pll6_config = { .nshift = 8, .nwidth = 5, .kshift = 4, .kwidth = 2, .n_start = 1, }; static const struct clk_factors_config sun5i_a13_ahb_config = { .pshift = 4, .pwidth = 2, }; static const struct clk_factors_config sun6i_ahb1_config = { .mshift = 6, .mwidth = 2, .pshift = 4, .pwidth = 2, }; static const struct clk_factors_config sun4i_apb1_config = { .mshift = 0, .mwidth = 5, .pshift = 16, .pwidth = 2, }; /* user manual says "n" but it's really "p" */ static const struct clk_factors_config sun7i_a20_out_config = { .mshift = 8, .mwidth = 5, .pshift = 20, .pwidth = 2, }; static const struct factors_data sun4i_pll1_data __initconst = { .enable = 31, .table = &sun4i_pll1_config, .getter = sun4i_get_pll1_factors, }; static const struct factors_data sun6i_a31_pll1_data __initconst = { .enable = 31, .table = &sun6i_a31_pll1_config, .getter = sun6i_a31_get_pll1_factors, }; static const struct factors_data sun8i_a23_pll1_data __initconst = { .enable = 31, .table = &sun8i_a23_pll1_config, .getter = sun8i_a23_get_pll1_factors, }; static const struct factors_data sun7i_a20_pll4_data __initconst = { .enable = 31, .table = &sun4i_pll5_config, .getter = sun4i_get_pll5_factors, }; static const struct factors_data sun4i_pll5_data __initconst = { .enable = 31, .table = &sun4i_pll5_config, .getter = sun4i_get_pll5_factors, }; static const struct factors_data sun6i_a31_pll6_data __initconst = { .enable = 31, .table = &sun6i_a31_pll6_config, .getter = sun6i_a31_get_pll6_factors, }; static const struct factors_data sun5i_a13_ahb_data __initconst = { .mux = 6, .muxmask = BIT(1) | BIT(0), .table = &sun5i_a13_ahb_config, .getter = sun5i_a13_get_ahb_factors, }; static const struct factors_data sun6i_ahb1_data __initconst = { .mux = 12, .muxmask = BIT(1) | BIT(0), .table = &sun6i_ahb1_config, .getter = sun6i_get_ahb1_factors, .recalc = sun6i_ahb1_recalc, }; static const struct factors_data sun4i_apb1_data __initconst = { .mux = 24, .muxmask = BIT(1) | BIT(0), .table = &sun4i_apb1_config, .getter = sun4i_get_apb1_factors, }; static const struct factors_data sun7i_a20_out_data __initconst = { .enable = 31, .mux = 24, .muxmask = BIT(1) | BIT(0), .table = &sun7i_a20_out_config, .getter = sun7i_a20_get_out_factors, }; static struct clk * __init sunxi_factors_clk_setup(struct device_node *node, const struct factors_data *data) { void __iomem *reg; reg = of_iomap(node, 0); if (!reg) { pr_err("Could not get registers for factors-clk: %pOFn\n", node); return NULL; } return sunxi_factors_register(node, data, &clk_lock, reg); } static void __init sun4i_pll1_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun4i_pll1_data); } CLK_OF_DECLARE(sun4i_pll1, "allwinner,sun4i-a10-pll1-clk", sun4i_pll1_clk_setup); static void __init sun6i_pll1_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun6i_a31_pll1_data); } CLK_OF_DECLARE(sun6i_pll1, "allwinner,sun6i-a31-pll1-clk", sun6i_pll1_clk_setup); static void __init sun8i_pll1_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun8i_a23_pll1_data); } CLK_OF_DECLARE(sun8i_pll1, "allwinner,sun8i-a23-pll1-clk", sun8i_pll1_clk_setup); static void __init sun7i_pll4_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun7i_a20_pll4_data); } CLK_OF_DECLARE(sun7i_pll4, "allwinner,sun7i-a20-pll4-clk", sun7i_pll4_clk_setup); static void __init sun5i_ahb_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun5i_a13_ahb_data); } CLK_OF_DECLARE(sun5i_ahb, "allwinner,sun5i-a13-ahb-clk", sun5i_ahb_clk_setup); static void __init sun6i_ahb1_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun6i_ahb1_data); } CLK_OF_DECLARE(sun6i_a31_ahb1, "allwinner,sun6i-a31-ahb1-clk", sun6i_ahb1_clk_setup); static void __init sun4i_apb1_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun4i_apb1_data); } CLK_OF_DECLARE(sun4i_apb1, "allwinner,sun4i-a10-apb1-clk", sun4i_apb1_clk_setup); static void __init sun7i_out_clk_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun7i_a20_out_data); } CLK_OF_DECLARE(sun7i_out, "allwinner,sun7i-a20-out-clk", sun7i_out_clk_setup); /* * sunxi_mux_clk_setup() - Setup function for muxes */ #define SUNXI_MUX_GATE_WIDTH 2 struct mux_data { u8 shift; }; static const struct mux_data sun4i_cpu_mux_data __initconst = { .shift = 16, }; static const struct mux_data sun6i_a31_ahb1_mux_data __initconst = { .shift = 12, }; static const struct mux_data sun8i_h3_ahb2_mux_data __initconst = { .shift = 0, }; static struct clk * __init sunxi_mux_clk_setup(struct device_node *node, const struct mux_data *data, unsigned long flags) { struct clk *clk; const char *clk_name = node->name; const char *parents[SUNXI_MAX_PARENTS]; void __iomem *reg; int i; reg = of_iomap(node, 0); if (!reg) { pr_err("Could not map registers for mux-clk: %pOF\n", node); return NULL; } i = of_clk_parent_fill(node, parents, SUNXI_MAX_PARENTS); if (of_property_read_string(node, "clock-output-names", &clk_name)) { pr_err("%s: could not read clock-output-names from \"%pOF\"\n", __func__, node); goto out_unmap; } clk = clk_register_mux(NULL, clk_name, parents, i, CLK_SET_RATE_PARENT | flags, reg, data->shift, SUNXI_MUX_GATE_WIDTH, 0, &clk_lock); if (IS_ERR(clk)) { pr_err("%s: failed to register mux clock %s: %ld\n", __func__, clk_name, PTR_ERR(clk)); goto out_unmap; } if (of_clk_add_provider(node, of_clk_src_simple_get, clk)) { pr_err("%s: failed to add clock provider for %s\n", __func__, clk_name); clk_unregister_divider(clk); goto out_unmap; } return clk; out_unmap: iounmap(reg); return NULL; } static void __init sun4i_cpu_clk_setup(struct device_node *node) { /* Protect CPU clock */ sunxi_mux_clk_setup(node, &sun4i_cpu_mux_data, CLK_IS_CRITICAL); } CLK_OF_DECLARE(sun4i_cpu, "allwinner,sun4i-a10-cpu-clk", sun4i_cpu_clk_setup); static void __init sun6i_ahb1_mux_clk_setup(struct device_node *node) { sunxi_mux_clk_setup(node, &sun6i_a31_ahb1_mux_data, 0); } CLK_OF_DECLARE(sun6i_ahb1_mux, "allwinner,sun6i-a31-ahb1-mux-clk", sun6i_ahb1_mux_clk_setup); static void __init sun8i_ahb2_clk_setup(struct device_node *node) { sunxi_mux_clk_setup(node, &sun8i_h3_ahb2_mux_data, 0); } CLK_OF_DECLARE(sun8i_ahb2, "allwinner,sun8i-h3-ahb2-clk", sun8i_ahb2_clk_setup); /* * sunxi_divider_clk_setup() - Setup function for simple divider clocks */ struct div_data { u8 shift; u8 pow; u8 width; const struct clk_div_table *table; }; static const struct div_data sun4i_axi_data __initconst = { .shift = 0, .pow = 0, .width = 2, }; static const struct clk_div_table sun8i_a23_axi_table[] __initconst = { { .val = 0, .div = 1 }, { .val = 1, .div = 2 }, { .val = 2, .div = 3 }, { .val = 3, .div = 4 }, { .val = 4, .div = 4 }, { .val = 5, .div = 4 }, { .val = 6, .div = 4 }, { .val = 7, .div = 4 }, { } /* sentinel */ }; static const struct div_data sun8i_a23_axi_data __initconst = { .width = 3, .table = sun8i_a23_axi_table, }; static const struct div_data sun4i_ahb_data __initconst = { .shift = 4, .pow = 1, .width = 2, }; static const struct clk_div_table sun4i_apb0_table[] __initconst = { { .val = 0, .div = 2 }, { .val = 1, .div = 2 }, { .val = 2, .div = 4 }, { .val = 3, .div = 8 }, { } /* sentinel */ }; static const struct div_data sun4i_apb0_data __initconst = { .shift = 8, .pow = 1, .width = 2, .table = sun4i_apb0_table, }; static void __init sunxi_divider_clk_setup(struct device_node *node, const struct div_data *data) { struct clk *clk; const char *clk_name = node->name; const char *clk_parent; void __iomem *reg; reg = of_iomap(node, 0); if (!reg) { pr_err("Could not map registers for mux-clk: %pOF\n", node); return; } clk_parent = of_clk_get_parent_name(node, 0); if (of_property_read_string(node, "clock-output-names", &clk_name)) { pr_err("%s: could not read clock-output-names from \"%pOF\"\n", __func__, node); goto out_unmap; } clk = clk_register_divider_table(NULL, clk_name, clk_parent, 0, reg, data->shift, data->width, data->pow ? CLK_DIVIDER_POWER_OF_TWO : 0, data->table, &clk_lock); if (IS_ERR(clk)) { pr_err("%s: failed to register divider clock %s: %ld\n", __func__, clk_name, PTR_ERR(clk)); goto out_unmap; } if (of_clk_add_provider(node, of_clk_src_simple_get, clk)) { pr_err("%s: failed to add clock provider for %s\n", __func__, clk_name); goto out_unregister; } if (clk_register_clkdev(clk, clk_name, NULL)) { of_clk_del_provider(node); goto out_unregister; } return; out_unregister: clk_unregister_divider(clk); out_unmap: iounmap(reg); } static void __init sun4i_ahb_clk_setup(struct device_node *node) { sunxi_divider_clk_setup(node, &sun4i_ahb_data); } CLK_OF_DECLARE(sun4i_ahb, "allwinner,sun4i-a10-ahb-clk", sun4i_ahb_clk_setup); static void __init sun4i_apb0_clk_setup(struct device_node *node) { sunxi_divider_clk_setup(node, &sun4i_apb0_data); } CLK_OF_DECLARE(sun4i_apb0, "allwinner,sun4i-a10-apb0-clk", sun4i_apb0_clk_setup); static void __init sun4i_axi_clk_setup(struct device_node *node) { sunxi_divider_clk_setup(node, &sun4i_axi_data); } CLK_OF_DECLARE(sun4i_axi, "allwinner,sun4i-a10-axi-clk", sun4i_axi_clk_setup); static void __init sun8i_axi_clk_setup(struct device_node *node) { sunxi_divider_clk_setup(node, &sun8i_a23_axi_data); } CLK_OF_DECLARE(sun8i_axi, "allwinner,sun8i-a23-axi-clk", sun8i_axi_clk_setup); /* * sunxi_gates_clk_setup() - Setup function for leaf gates on clocks */ #define SUNXI_GATES_MAX_SIZE 64 struct gates_data { DECLARE_BITMAP(mask, SUNXI_GATES_MAX_SIZE); }; /* * sunxi_divs_clk_setup() helper data */ #define SUNXI_DIVS_MAX_QTY 4 #define SUNXI_DIVISOR_WIDTH 2 struct divs_data { const struct factors_data *factors; /* data for the factor clock */ int ndivs; /* number of outputs */ /* * List of outputs. Refer to the diagram for sunxi_divs_clk_setup(): * self or base factor clock refers to the output from the pll * itself. The remaining refer to fixed or configurable divider * outputs. */ struct { u8 self; /* is it the base factor clock? (only one) */ u8 fixed; /* is it a fixed divisor? if not... */ struct clk_div_table *table; /* is it a table based divisor? */ u8 shift; /* otherwise it's a normal divisor with this shift */ u8 pow; /* is it power-of-two based? */ u8 gate; /* is it independently gateable? */ bool critical; } div[SUNXI_DIVS_MAX_QTY]; }; static struct clk_div_table pll6_sata_tbl[] = { { .val = 0, .div = 6, }, { .val = 1, .div = 12, }, { .val = 2, .div = 18, }, { .val = 3, .div = 24, }, { } /* sentinel */ }; static const struct divs_data pll5_divs_data __initconst = { .factors = &sun4i_pll5_data, .ndivs = 2, .div = { /* Protect PLL5_DDR */ { .shift = 0, .pow = 0, .critical = true }, /* M, DDR */ { .shift = 16, .pow = 1, }, /* P, other */ /* No output for the base factor clock */ } }; static const struct divs_data pll6_divs_data __initconst = { .factors = &sun4i_pll5_data, .ndivs = 4, .div = { { .shift = 0, .table = pll6_sata_tbl, .gate = 14 }, /* M, SATA */ { .fixed = 2 }, /* P, other */ { .self = 1 }, /* base factor clock, 2x */ { .fixed = 4 }, /* pll6 / 4, used as ahb input */ } }; static const struct divs_data sun6i_a31_pll6_divs_data __initconst = { .factors = &sun6i_a31_pll6_data, .ndivs = 2, .div = { { .fixed = 2 }, /* normal output */ { .self = 1 }, /* base factor clock, 2x */ } }; /* * sunxi_divs_clk_setup() - Setup function for leaf divisors on clocks * * These clocks look something like this * ________________________ * | ___divisor 1---|----> to consumer * parent >--| pll___/___divisor 2---|----> to consumer * | \_______________|____> to consumer * |________________________| */ static struct clk ** __init sunxi_divs_clk_setup(struct device_node *node, const struct divs_data *data) { struct clk_onecell_data *clk_data; const char *parent; const char *clk_name; struct clk **clks, *pclk; struct clk_hw *gate_hw, *rate_hw; const struct clk_ops *rate_ops; struct clk_gate *gate = NULL; struct clk_fixed_factor *fix_factor; struct clk_divider *divider; struct factors_data factors = *data->factors; char *derived_name = NULL; void __iomem *reg; int ndivs = SUNXI_DIVS_MAX_QTY, i = 0; int flags, clkflags; /* if number of children known, use it */ if (data->ndivs) ndivs = data->ndivs; /* Try to find a name for base factor clock */ for (i = 0; i < ndivs; i++) { if (data->div[i].self) { of_property_read_string_index(node, "clock-output-names", i, &factors.name); break; } } /* If we don't have a .self clk use the first output-name up to '_' */ if (factors.name == NULL) { char *endp; of_property_read_string_index(node, "clock-output-names", 0, &clk_name); endp = strchr(clk_name, '_'); if (endp) { derived_name = kstrndup(clk_name, endp - clk_name, GFP_KERNEL); if (!derived_name) return NULL; factors.name = derived_name; } else { factors.name = clk_name; } } /* Set up factor clock that we will be dividing */ pclk = sunxi_factors_clk_setup(node, &factors); if (!pclk) return NULL; parent = __clk_get_name(pclk); kfree(derived_name); reg = of_iomap(node, 0); if (!reg) { pr_err("Could not map registers for divs-clk: %pOF\n", node); return NULL; } clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL); if (!clk_data) goto out_unmap; clks = kcalloc(ndivs, sizeof(*clks), GFP_KERNEL); if (!clks) goto free_clkdata; clk_data->clks = clks; /* It's not a good idea to have automatic reparenting changing * our RAM clock! */ clkflags = !strcmp("pll5", parent) ? 0 : CLK_SET_RATE_PARENT; for (i = 0; i < ndivs; i++) { if (of_property_read_string_index(node, "clock-output-names", i, &clk_name) != 0) break; /* If this is the base factor clock, only update clks */ if (data->div[i].self) { clk_data->clks[i] = pclk; continue; } gate_hw = NULL; rate_hw = NULL; rate_ops = NULL; /* If this leaf clock can be gated, create a gate */ if (data->div[i].gate) { gate = kzalloc(sizeof(*gate), GFP_KERNEL); if (!gate) goto free_clks; gate->reg = reg; gate->bit_idx = data->div[i].gate; gate->lock = &clk_lock; gate_hw = &gate->hw; } /* Leaves can be fixed or configurable divisors */ if (data->div[i].fixed) { fix_factor = kzalloc(sizeof(*fix_factor), GFP_KERNEL); if (!fix_factor) goto free_gate; fix_factor->mult = 1; fix_factor->div = data->div[i].fixed; rate_hw = &fix_factor->hw; rate_ops = &clk_fixed_factor_ops; } else { divider = kzalloc(sizeof(*divider), GFP_KERNEL); if (!divider) goto free_gate; flags = data->div[i].pow ? CLK_DIVIDER_POWER_OF_TWO : 0; divider->reg = reg; divider->shift = data->div[i].shift; divider->width = SUNXI_DIVISOR_WIDTH; divider->flags = flags; divider->lock = &clk_lock; divider->table = data->div[i].table; rate_hw = &divider->hw; rate_ops = &clk_divider_ops; } /* Wrap the (potential) gate and the divisor on a composite * clock to unify them */ clks[i] = clk_register_composite(NULL, clk_name, &parent, 1, NULL, NULL, rate_hw, rate_ops, gate_hw, &clk_gate_ops, clkflags | (data->div[i].critical ? CLK_IS_CRITICAL : 0)); WARN_ON(IS_ERR(clk_data->clks[i])); } /* Adjust to the real max */ clk_data->clk_num = i; if (of_clk_add_provider(node, of_clk_src_onecell_get, clk_data)) { pr_err("%s: failed to add clock provider for %s\n", __func__, clk_name); goto free_gate; } return clks; free_gate: kfree(gate); free_clks: kfree(clks); free_clkdata: kfree(clk_data); out_unmap: iounmap(reg); return NULL; } static void __init sun4i_pll5_clk_setup(struct device_node *node) { sunxi_divs_clk_setup(node, &pll5_divs_data); } CLK_OF_DECLARE(sun4i_pll5, "allwinner,sun4i-a10-pll5-clk", sun4i_pll5_clk_setup); static void __init sun4i_pll6_clk_setup(struct device_node *node) { sunxi_divs_clk_setup(node, &pll6_divs_data); } CLK_OF_DECLARE(sun4i_pll6, "allwinner,sun4i-a10-pll6-clk", sun4i_pll6_clk_setup); static void __init sun6i_pll6_clk_setup(struct device_node *node) { sunxi_divs_clk_setup(node, &sun6i_a31_pll6_divs_data); } CLK_OF_DECLARE(sun6i_pll6, "allwinner,sun6i-a31-pll6-clk", sun6i_pll6_clk_setup); /* * sun6i display * * rate = parent_rate / (m + 1); */ static void sun6i_display_factors(struct factors_request *req) { u8 m; if (req->rate > req->parent_rate) req->rate = req->parent_rate; m = DIV_ROUND_UP(req->parent_rate, req->rate); req->rate = req->parent_rate / m; req->m = m - 1; } static const struct clk_factors_config sun6i_display_config = { .mshift = 0, .mwidth = 4, }; static const struct factors_data sun6i_display_data __initconst = { .enable = 31, .mux = 24, .muxmask = BIT(2) | BIT(1) | BIT(0), .table = &sun6i_display_config, .getter = sun6i_display_factors, }; static void __init sun6i_display_setup(struct device_node *node) { sunxi_factors_clk_setup(node, &sun6i_display_data); } CLK_OF_DECLARE(sun6i_display, "allwinner,sun6i-a31-display-clk", sun6i_display_setup);
linux-master
drivers/clk/sunxi/clk-sunxi.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2013 Emilio López * * Emilio López <[email protected]> */ #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/of_address.h> #define SUN4I_CODEC_GATE 31 static void __init sun4i_codec_clk_setup(struct device_node *node) { struct clk *clk; const char *clk_name = node->name, *parent_name; void __iomem *reg; reg = of_io_request_and_map(node, 0, of_node_full_name(node)); if (IS_ERR(reg)) return; of_property_read_string(node, "clock-output-names", &clk_name); parent_name = of_clk_get_parent_name(node, 0); clk = clk_register_gate(NULL, clk_name, parent_name, CLK_SET_RATE_PARENT, reg, SUN4I_CODEC_GATE, 0, NULL); if (!IS_ERR(clk)) of_clk_add_provider(node, of_clk_src_simple_get, clk); } CLK_OF_DECLARE(sun4i_codec, "allwinner,sun4i-a10-codec-clk", sun4i_codec_clk_setup);
linux-master
drivers/clk/sunxi/clk-a10-codec.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2014 Chen-Yu Tsai * * Chen-Yu Tsai <[email protected]> */ #include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/io.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/of_address.h> #define SUN8I_MBUS_ENABLE 31 #define SUN8I_MBUS_MUX_SHIFT 24 #define SUN8I_MBUS_MUX_MASK 0x3 #define SUN8I_MBUS_DIV_SHIFT 0 #define SUN8I_MBUS_DIV_WIDTH 3 #define SUN8I_MBUS_MAX_PARENTS 4 static DEFINE_SPINLOCK(sun8i_a23_mbus_lock); static void __init sun8i_a23_mbus_setup(struct device_node *node) { int num_parents = of_clk_get_parent_count(node); const char **parents; const char *clk_name = node->name; struct resource res; struct clk_divider *div; struct clk_gate *gate; struct clk_mux *mux; struct clk *clk; void __iomem *reg; int err; parents = kcalloc(num_parents, sizeof(*parents), GFP_KERNEL); if (!parents) return; reg = of_io_request_and_map(node, 0, of_node_full_name(node)); if (IS_ERR(reg)) { pr_err("Could not get registers for sun8i-mbus-clk\n"); goto err_free_parents; } div = kzalloc(sizeof(*div), GFP_KERNEL); if (!div) goto err_unmap; mux = kzalloc(sizeof(*mux), GFP_KERNEL); if (!mux) goto err_free_div; gate = kzalloc(sizeof(*gate), GFP_KERNEL); if (!gate) goto err_free_mux; of_property_read_string(node, "clock-output-names", &clk_name); of_clk_parent_fill(node, parents, num_parents); gate->reg = reg; gate->bit_idx = SUN8I_MBUS_ENABLE; gate->lock = &sun8i_a23_mbus_lock; div->reg = reg; div->shift = SUN8I_MBUS_DIV_SHIFT; div->width = SUN8I_MBUS_DIV_WIDTH; div->lock = &sun8i_a23_mbus_lock; mux->reg = reg; mux->shift = SUN8I_MBUS_MUX_SHIFT; mux->mask = SUN8I_MBUS_MUX_MASK; mux->lock = &sun8i_a23_mbus_lock; /* The MBUS clocks needs to be always enabled */ clk = clk_register_composite(NULL, clk_name, parents, num_parents, &mux->hw, &clk_mux_ops, &div->hw, &clk_divider_ops, &gate->hw, &clk_gate_ops, CLK_IS_CRITICAL); if (IS_ERR(clk)) goto err_free_gate; err = of_clk_add_provider(node, of_clk_src_simple_get, clk); if (err) goto err_unregister_clk; kfree(parents); /* parents is deep copied */ return; err_unregister_clk: /* TODO: The composite clock stuff will leak a bit here. */ clk_unregister(clk); err_free_gate: kfree(gate); err_free_mux: kfree(mux); err_free_div: kfree(div); err_unmap: iounmap(reg); of_address_to_resource(node, 0, &res); release_mem_region(res.start, resource_size(&res)); err_free_parents: kfree(parents); } CLK_OF_DECLARE(sun8i_a23_mbus, "allwinner,sun8i-a23-mbus-clk", sun8i_a23_mbus_setup);
linux-master
drivers/clk/sunxi/clk-sun8i-mbus.c
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2014 Free Electrons * * Author: Boris BREZILLON <[email protected]> * * Allwinner A31 APB0 clock driver */ #include <linux/clk-provider.h> #include <linux/init.h> #include <linux/of.h> #include <linux/platform_device.h> /* * The APB0 clk has a configurable divisor. * * We must use a clk_div_table and not a regular power of 2 * divisor here, because the first 2 values divide the clock * by 2. */ static const struct clk_div_table sun6i_a31_apb0_divs[] = { { .val = 0, .div = 2, }, { .val = 1, .div = 2, }, { .val = 2, .div = 4, }, { .val = 3, .div = 8, }, { /* sentinel */ }, }; static int sun6i_a31_apb0_clk_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; const char *clk_name = np->name; const char *clk_parent; void __iomem *reg; struct clk *clk; reg = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(reg)) return PTR_ERR(reg); clk_parent = of_clk_get_parent_name(np, 0); if (!clk_parent) return -EINVAL; of_property_read_string(np, "clock-output-names", &clk_name); clk = clk_register_divider_table(&pdev->dev, clk_name, clk_parent, 0, reg, 0, 2, 0, sun6i_a31_apb0_divs, NULL); if (IS_ERR(clk)) return PTR_ERR(clk); return of_clk_add_provider(np, of_clk_src_simple_get, clk); } static const struct of_device_id sun6i_a31_apb0_clk_dt_ids[] = { { .compatible = "allwinner,sun6i-a31-apb0-clk" }, { /* sentinel */ } }; static struct platform_driver sun6i_a31_apb0_clk_driver = { .driver = { .name = "sun6i-a31-apb0-clk", .of_match_table = sun6i_a31_apb0_clk_dt_ids, }, .probe = sun6i_a31_apb0_clk_probe, }; builtin_platform_driver(sun6i_a31_apb0_clk_driver);
linux-master
drivers/clk/sunxi/clk-sun6i-apb0.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2015 Chen-Yu Tsai * * Chen-Yu Tsai <[email protected]> */ #include <linux/clk-provider.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/reset-controller.h> #include <linux/slab.h> #include <linux/spinlock.h> static DEFINE_SPINLOCK(ve_lock); #define SUN4I_VE_ENABLE 31 #define SUN4I_VE_DIVIDER_SHIFT 16 #define SUN4I_VE_DIVIDER_WIDTH 3 #define SUN4I_VE_RESET 0 /* * sunxi_ve_reset... - reset bit in ve clk registers handling */ struct ve_reset_data { void __iomem *reg; spinlock_t *lock; struct reset_controller_dev rcdev; }; static int sunxi_ve_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) { struct ve_reset_data *data = container_of(rcdev, struct ve_reset_data, rcdev); unsigned long flags; u32 reg; spin_lock_irqsave(data->lock, flags); reg = readl(data->reg); writel(reg & ~BIT(SUN4I_VE_RESET), data->reg); spin_unlock_irqrestore(data->lock, flags); return 0; } static int sunxi_ve_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) { struct ve_reset_data *data = container_of(rcdev, struct ve_reset_data, rcdev); unsigned long flags; u32 reg; spin_lock_irqsave(data->lock, flags); reg = readl(data->reg); writel(reg | BIT(SUN4I_VE_RESET), data->reg); spin_unlock_irqrestore(data->lock, flags); return 0; } static int sunxi_ve_of_xlate(struct reset_controller_dev *rcdev, const struct of_phandle_args *reset_spec) { if (WARN_ON(reset_spec->args_count != 0)) return -EINVAL; return 0; } static const struct reset_control_ops sunxi_ve_reset_ops = { .assert = sunxi_ve_reset_assert, .deassert = sunxi_ve_reset_deassert, }; static void __init sun4i_ve_clk_setup(struct device_node *node) { struct clk *clk; struct clk_divider *div; struct clk_gate *gate; struct ve_reset_data *reset_data; const char *parent; const char *clk_name = node->name; void __iomem *reg; int err; reg = of_io_request_and_map(node, 0, of_node_full_name(node)); if (IS_ERR(reg)) return; div = kzalloc(sizeof(*div), GFP_KERNEL); if (!div) goto err_unmap; gate = kzalloc(sizeof(*gate), GFP_KERNEL); if (!gate) goto err_free_div; of_property_read_string(node, "clock-output-names", &clk_name); parent = of_clk_get_parent_name(node, 0); gate->reg = reg; gate->bit_idx = SUN4I_VE_ENABLE; gate->lock = &ve_lock; div->reg = reg; div->shift = SUN4I_VE_DIVIDER_SHIFT; div->width = SUN4I_VE_DIVIDER_WIDTH; div->lock = &ve_lock; clk = clk_register_composite(NULL, clk_name, &parent, 1, NULL, NULL, &div->hw, &clk_divider_ops, &gate->hw, &clk_gate_ops, CLK_SET_RATE_PARENT); if (IS_ERR(clk)) goto err_free_gate; err = of_clk_add_provider(node, of_clk_src_simple_get, clk); if (err) goto err_unregister_clk; reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL); if (!reset_data) goto err_del_provider; reset_data->reg = reg; reset_data->lock = &ve_lock; reset_data->rcdev.nr_resets = 1; reset_data->rcdev.ops = &sunxi_ve_reset_ops; reset_data->rcdev.of_node = node; reset_data->rcdev.of_xlate = sunxi_ve_of_xlate; reset_data->rcdev.of_reset_n_cells = 0; err = reset_controller_register(&reset_data->rcdev); if (err) goto err_free_reset; return; err_free_reset: kfree(reset_data); err_del_provider: of_clk_del_provider(node); err_unregister_clk: clk_unregister(clk); err_free_gate: kfree(gate); err_free_div: kfree(div); err_unmap: iounmap(reg); } CLK_OF_DECLARE(sun4i_ve, "allwinner,sun4i-a10-ve-clk", sun4i_ve_clk_setup);
linux-master
drivers/clk/sunxi/clk-a10-ve.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2015 Maxime Ripard * * Maxime Ripard <[email protected]> */ #include <linux/clk-provider.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/slab.h> #include <linux/spinlock.h> #define SUN4I_A10_PLL3_GATE_BIT 31 #define SUN4I_A10_PLL3_DIV_WIDTH 7 #define SUN4I_A10_PLL3_DIV_SHIFT 0 static DEFINE_SPINLOCK(sun4i_a10_pll3_lock); static void __init sun4i_a10_pll3_setup(struct device_node *node) { const char *clk_name = node->name, *parent; struct clk_multiplier *mult; struct clk_gate *gate; struct resource res; void __iomem *reg; struct clk *clk; int ret; of_property_read_string(node, "clock-output-names", &clk_name); parent = of_clk_get_parent_name(node, 0); reg = of_io_request_and_map(node, 0, of_node_full_name(node)); if (IS_ERR(reg)) { pr_err("%s: Could not map the clock registers\n", clk_name); return; } gate = kzalloc(sizeof(*gate), GFP_KERNEL); if (!gate) goto err_unmap; gate->reg = reg; gate->bit_idx = SUN4I_A10_PLL3_GATE_BIT; gate->lock = &sun4i_a10_pll3_lock; mult = kzalloc(sizeof(*mult), GFP_KERNEL); if (!mult) goto err_free_gate; mult->reg = reg; mult->shift = SUN4I_A10_PLL3_DIV_SHIFT; mult->width = SUN4I_A10_PLL3_DIV_WIDTH; mult->lock = &sun4i_a10_pll3_lock; clk = clk_register_composite(NULL, clk_name, &parent, 1, NULL, NULL, &mult->hw, &clk_multiplier_ops, &gate->hw, &clk_gate_ops, 0); if (IS_ERR(clk)) { pr_err("%s: Couldn't register the clock\n", clk_name); goto err_free_mult; } ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); if (ret) { pr_err("%s: Couldn't register DT provider\n", clk_name); goto err_clk_unregister; } return; err_clk_unregister: clk_unregister_composite(clk); err_free_mult: kfree(mult); err_free_gate: kfree(gate); err_unmap: iounmap(reg); of_address_to_resource(node, 0, &res); release_mem_region(res.start, resource_size(&res)); } CLK_OF_DECLARE(sun4i_a10_pll3, "allwinner,sun4i-a10-pll3-clk", sun4i_a10_pll3_setup);
linux-master
drivers/clk/sunxi/clk-sun4i-pll3.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2015 Maxime Ripard * * Maxime Ripard <[email protected]> */ #include <linux/clk-provider.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/slab.h> #include <linux/spinlock.h> #define TCON_CH1_SCLK2_PARENTS 4 #define TCON_CH1_SCLK2_GATE_BIT BIT(31) #define TCON_CH1_SCLK2_MUX_MASK 3 #define TCON_CH1_SCLK2_MUX_SHIFT 24 #define TCON_CH1_SCLK2_DIV_MASK 0xf #define TCON_CH1_SCLK2_DIV_SHIFT 0 #define TCON_CH1_SCLK1_GATE_BIT BIT(15) #define TCON_CH1_SCLK1_HALF_BIT BIT(11) struct tcon_ch1_clk { struct clk_hw hw; spinlock_t lock; void __iomem *reg; }; #define hw_to_tclk(hw) container_of(hw, struct tcon_ch1_clk, hw) static void tcon_ch1_disable(struct clk_hw *hw) { struct tcon_ch1_clk *tclk = hw_to_tclk(hw); unsigned long flags; u32 reg; spin_lock_irqsave(&tclk->lock, flags); reg = readl(tclk->reg); reg &= ~(TCON_CH1_SCLK2_GATE_BIT | TCON_CH1_SCLK1_GATE_BIT); writel(reg, tclk->reg); spin_unlock_irqrestore(&tclk->lock, flags); } static int tcon_ch1_enable(struct clk_hw *hw) { struct tcon_ch1_clk *tclk = hw_to_tclk(hw); unsigned long flags; u32 reg; spin_lock_irqsave(&tclk->lock, flags); reg = readl(tclk->reg); reg |= TCON_CH1_SCLK2_GATE_BIT | TCON_CH1_SCLK1_GATE_BIT; writel(reg, tclk->reg); spin_unlock_irqrestore(&tclk->lock, flags); return 0; } static int tcon_ch1_is_enabled(struct clk_hw *hw) { struct tcon_ch1_clk *tclk = hw_to_tclk(hw); u32 reg; reg = readl(tclk->reg); return reg & (TCON_CH1_SCLK2_GATE_BIT | TCON_CH1_SCLK1_GATE_BIT); } static u8 tcon_ch1_get_parent(struct clk_hw *hw) { struct tcon_ch1_clk *tclk = hw_to_tclk(hw); u32 reg; reg = readl(tclk->reg) >> TCON_CH1_SCLK2_MUX_SHIFT; reg &= reg >> TCON_CH1_SCLK2_MUX_MASK; return reg; } static int tcon_ch1_set_parent(struct clk_hw *hw, u8 index) { struct tcon_ch1_clk *tclk = hw_to_tclk(hw); unsigned long flags; u32 reg; spin_lock_irqsave(&tclk->lock, flags); reg = readl(tclk->reg); reg &= ~(TCON_CH1_SCLK2_MUX_MASK << TCON_CH1_SCLK2_MUX_SHIFT); reg |= index << TCON_CH1_SCLK2_MUX_SHIFT; writel(reg, tclk->reg); spin_unlock_irqrestore(&tclk->lock, flags); return 0; }; static unsigned long tcon_ch1_calc_divider(unsigned long rate, unsigned long parent_rate, u8 *div, bool *half) { unsigned long best_rate = 0; u8 best_m = 0, m; bool is_double; for (m = 1; m < 16; m++) { u8 d; for (d = 1; d < 3; d++) { unsigned long tmp_rate; tmp_rate = parent_rate / m / d; if (tmp_rate > rate) continue; if (!best_rate || (rate - tmp_rate) < (rate - best_rate)) { best_rate = tmp_rate; best_m = m; is_double = d; } } } if (div && half) { *div = best_m; *half = is_double; } return best_rate; } static int tcon_ch1_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { long best_rate = -EINVAL; int i; for (i = 0; i < clk_hw_get_num_parents(hw); i++) { unsigned long parent_rate; unsigned long tmp_rate; struct clk_hw *parent; parent = clk_hw_get_parent_by_index(hw, i); if (!parent) continue; parent_rate = clk_hw_get_rate(parent); tmp_rate = tcon_ch1_calc_divider(req->rate, parent_rate, NULL, NULL); if (best_rate < 0 || (req->rate - tmp_rate) < (req->rate - best_rate)) { best_rate = tmp_rate; req->best_parent_rate = parent_rate; req->best_parent_hw = parent; } } if (best_rate < 0) return best_rate; req->rate = best_rate; return 0; } static unsigned long tcon_ch1_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct tcon_ch1_clk *tclk = hw_to_tclk(hw); u32 reg; reg = readl(tclk->reg); parent_rate /= (reg & TCON_CH1_SCLK2_DIV_MASK) + 1; if (reg & TCON_CH1_SCLK1_HALF_BIT) parent_rate /= 2; return parent_rate; } static int tcon_ch1_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct tcon_ch1_clk *tclk = hw_to_tclk(hw); unsigned long flags; bool half; u8 div_m; u32 reg; tcon_ch1_calc_divider(rate, parent_rate, &div_m, &half); spin_lock_irqsave(&tclk->lock, flags); reg = readl(tclk->reg); reg &= ~(TCON_CH1_SCLK2_DIV_MASK | TCON_CH1_SCLK1_HALF_BIT); reg |= (div_m - 1) & TCON_CH1_SCLK2_DIV_MASK; if (half) reg |= TCON_CH1_SCLK1_HALF_BIT; writel(reg, tclk->reg); spin_unlock_irqrestore(&tclk->lock, flags); return 0; } static const struct clk_ops tcon_ch1_ops = { .disable = tcon_ch1_disable, .enable = tcon_ch1_enable, .is_enabled = tcon_ch1_is_enabled, .get_parent = tcon_ch1_get_parent, .set_parent = tcon_ch1_set_parent, .determine_rate = tcon_ch1_determine_rate, .recalc_rate = tcon_ch1_recalc_rate, .set_rate = tcon_ch1_set_rate, }; static void __init tcon_ch1_setup(struct device_node *node) { const char *parents[TCON_CH1_SCLK2_PARENTS]; const char *clk_name = node->name; struct clk_init_data init; struct tcon_ch1_clk *tclk; struct resource res; struct clk *clk; void __iomem *reg; int ret; of_property_read_string(node, "clock-output-names", &clk_name); reg = of_io_request_and_map(node, 0, of_node_full_name(node)); if (IS_ERR(reg)) { pr_err("%s: Could not map the clock registers\n", clk_name); return; } ret = of_clk_parent_fill(node, parents, TCON_CH1_SCLK2_PARENTS); if (ret != TCON_CH1_SCLK2_PARENTS) { pr_err("%s Could not retrieve the parents\n", clk_name); goto err_unmap; } tclk = kzalloc(sizeof(*tclk), GFP_KERNEL); if (!tclk) goto err_unmap; init.name = clk_name; init.ops = &tcon_ch1_ops; init.parent_names = parents; init.num_parents = TCON_CH1_SCLK2_PARENTS; init.flags = CLK_SET_RATE_PARENT; tclk->reg = reg; tclk->hw.init = &init; spin_lock_init(&tclk->lock); clk = clk_register(NULL, &tclk->hw); if (IS_ERR(clk)) { pr_err("%s: Couldn't register the clock\n", clk_name); goto err_free_data; } ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); if (ret) { pr_err("%s: Couldn't register our clock provider\n", clk_name); goto err_unregister_clk; } return; err_unregister_clk: clk_unregister(clk); err_free_data: kfree(tclk); err_unmap: iounmap(reg); of_address_to_resource(node, 0, &res); release_mem_region(res.start, resource_size(&res)); } CLK_OF_DECLARE(tcon_ch1, "allwinner,sun4i-a10-tcon-ch1-clk", tcon_ch1_setup);
linux-master
drivers/clk/sunxi/clk-sun4i-tcon-ch1.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2015 Jens Kuske <[email protected]> * * Based on clk-simple-gates.c, which is: * Copyright 2015 Maxime Ripard * * Maxime Ripard <[email protected]> */ #include <linux/clk-provider.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/slab.h> #include <linux/spinlock.h> static DEFINE_SPINLOCK(gates_lock); static void __init sun8i_h3_bus_gates_init(struct device_node *node) { static const char * const names[] = { "ahb1", "ahb2", "apb1", "apb2" }; enum { AHB1, AHB2, APB1, APB2, PARENT_MAX } clk_parent; const char *parents[PARENT_MAX]; struct clk_onecell_data *clk_data; const char *clk_name; struct property *prop; struct resource res; void __iomem *clk_reg; void __iomem *reg; const __be32 *p; int number, i; u8 clk_bit; int index; reg = of_io_request_and_map(node, 0, of_node_full_name(node)); if (IS_ERR(reg)) return; for (i = 0; i < ARRAY_SIZE(names); i++) { int idx = of_property_match_string(node, "clock-names", names[i]); if (idx < 0) return; parents[i] = of_clk_get_parent_name(node, idx); } clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL); if (!clk_data) goto err_unmap; number = of_property_count_u32_elems(node, "clock-indices"); of_property_read_u32_index(node, "clock-indices", number - 1, &number); clk_data->clks = kcalloc(number + 1, sizeof(struct clk *), GFP_KERNEL); if (!clk_data->clks) goto err_free_data; i = 0; of_property_for_each_u32(node, "clock-indices", prop, p, index) { of_property_read_string_index(node, "clock-output-names", i, &clk_name); if (index == 17 || (index >= 29 && index <= 31)) clk_parent = AHB2; else if (index <= 63 || index >= 128) clk_parent = AHB1; else if (index >= 64 && index <= 95) clk_parent = APB1; else if (index >= 96 && index <= 127) clk_parent = APB2; else { WARN_ON(true); continue; } clk_reg = reg + 4 * (index / 32); clk_bit = index % 32; clk_data->clks[index] = clk_register_gate(NULL, clk_name, parents[clk_parent], 0, clk_reg, clk_bit, 0, &gates_lock); i++; if (IS_ERR(clk_data->clks[index])) { WARN_ON(true); continue; } } clk_data->clk_num = number + 1; of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); return; err_free_data: kfree(clk_data); err_unmap: iounmap(reg); of_address_to_resource(node, 0, &res); release_mem_region(res.start, resource_size(&res)); } CLK_OF_DECLARE(sun8i_h3_bus_gates, "allwinner,sun8i-h3-bus-gates-clk", sun8i_h3_bus_gates_init); CLK_OF_DECLARE(sun8i_a83t_bus_gates, "allwinner,sun8i-a83t-bus-gates-clk", sun8i_h3_bus_gates_init);
linux-master
drivers/clk/sunxi/clk-sun8i-bus-gates.c