2 * Copyright (c) 2017 MediaTek Inc.
3 * Author: Weiyi Lu <weiyi.lu@mediatek.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/clk.h>
16 #include <linux/delay.h>
17 #include <linux/mfd/syscon.h>
19 #include <linux/of_address.h>
20 #include <linux/of_device.h>
21 #include <linux/platform_device.h>
22 #include <linux/slab.h>
27 #include <dt-bindings/clock/mt2712-clk.h>
29 static DEFINE_SPINLOCK(mt2712_clk_lock);
31 static const struct mtk_fixed_clk top_fixed_clks[] = {
32 FIXED_CLK(CLK_TOP_VPLL3_DPIX, "vpll3_dpix", NULL, 200000000),
33 FIXED_CLK(CLK_TOP_VPLL_DPIX, "vpll_dpix", NULL, 200000000),
34 FIXED_CLK(CLK_TOP_LTEPLL_FS26M, "ltepll_fs26m", NULL, 26000000),
35 FIXED_CLK(CLK_TOP_DMPLL, "dmpll_ck", NULL, 350000000),
36 FIXED_CLK(CLK_TOP_DSI0_LNTC, "dsi0_lntc", NULL, 143000000),
37 FIXED_CLK(CLK_TOP_DSI1_LNTC, "dsi1_lntc", NULL, 143000000),
38 FIXED_CLK(CLK_TOP_LVDSTX3_CLKDIG_CTS, "lvdstx3", NULL, 140000000),
39 FIXED_CLK(CLK_TOP_LVDSTX_CLKDIG_CTS, "lvdstx", NULL, 140000000),
40 FIXED_CLK(CLK_TOP_CLKRTC_EXT, "clkrtc_ext", NULL, 32768),
41 FIXED_CLK(CLK_TOP_CLKRTC_INT, "clkrtc_int", NULL, 32747),
42 FIXED_CLK(CLK_TOP_CSI0, "csi0", NULL, 26000000),
43 FIXED_CLK(CLK_TOP_CVBSPLL, "cvbspll", NULL, 108000000),
46 static const struct mtk_fixed_factor top_early_divs[] = {
47 FACTOR(CLK_TOP_SYS_26M, "sys_26m", "clk26m", 1,
49 FACTOR(CLK_TOP_CLK26M_D2, "clk26m_d2", "sys_26m", 1,
53 static const struct mtk_fixed_factor top_divs[] = {
54 FACTOR(CLK_TOP_ARMCA35PLL, "armca35pll_ck", "armca35pll", 1,
56 FACTOR(CLK_TOP_ARMCA35PLL_600M, "armca35pll_600m", "armca35pll_ck", 1,
58 FACTOR(CLK_TOP_ARMCA35PLL_400M, "armca35pll_400m", "armca35pll_ck", 1,
60 FACTOR(CLK_TOP_ARMCA72PLL, "armca72pll_ck", "armca72pll", 1,
62 FACTOR(CLK_TOP_SYSPLL, "syspll_ck", "mainpll", 1,
64 FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "syspll_ck", 1,
66 FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1,
68 FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1,
70 FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1,
72 FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1,
74 FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "syspll_ck", 1,
76 FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1,
78 FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1,
80 FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "syspll_ck", 1,
82 FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1,
84 FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1,
86 FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "syspll_ck", 1,
88 FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1,
90 FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1,
92 FACTOR(CLK_TOP_UNIVPLL, "univpll_ck", "univpll", 1,
94 FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll_ck", 1,
96 FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll_ck", 1,
98 FACTOR(CLK_TOP_UNIVPLL_D52, "univpll_d52", "univpll_ck", 1,
100 FACTOR(CLK_TOP_UNIVPLL_D104, "univpll_d104", "univpll_ck", 1,
102 FACTOR(CLK_TOP_UNIVPLL_D208, "univpll_d208", "univpll_ck", 1,
104 FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll_ck", 1,
106 FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1,
108 FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1,
110 FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1,
112 FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll_ck", 1,
114 FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll_d3", 1,
116 FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll_d3", 1,
118 FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll_d3", 1,
120 FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll_ck", 1,
122 FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1,
124 FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1,
126 FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1,
128 FACTOR(CLK_TOP_F_MP0_PLL1, "f_mp0_pll1_ck", "univpll_d2", 1,
130 FACTOR(CLK_TOP_F_MP0_PLL2, "f_mp0_pll2_ck", "univpll1_d2", 1,
132 FACTOR(CLK_TOP_F_BIG_PLL1, "f_big_pll1_ck", "univpll_d2", 1,
134 FACTOR(CLK_TOP_F_BIG_PLL2, "f_big_pll2_ck", "univpll1_d2", 1,
136 FACTOR(CLK_TOP_F_BUS_PLL1, "f_bus_pll1_ck", "univpll_d2", 1,
138 FACTOR(CLK_TOP_F_BUS_PLL2, "f_bus_pll2_ck", "univpll1_d2", 1,
140 FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1,
142 FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1,
144 FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1_ck", 1,
146 FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1_ck", 1,
148 FACTOR(CLK_TOP_APLL1_D16, "apll1_d16", "apll1_ck", 1,
150 FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1,
152 FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2_ck", 1,
154 FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2_ck", 1,
156 FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2_ck", 1,
158 FACTOR(CLK_TOP_APLL2_D16, "apll2_d16", "apll2_ck", 1,
160 FACTOR(CLK_TOP_LVDSPLL, "lvdspll_ck", "lvdspll", 1,
162 FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll_ck", 1,
164 FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll_ck", 1,
166 FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll_ck", 1,
168 FACTOR(CLK_TOP_LVDSPLL2, "lvdspll2_ck", "lvdspll2", 1,
170 FACTOR(CLK_TOP_LVDSPLL2_D2, "lvdspll2_d2", "lvdspll2_ck", 1,
172 FACTOR(CLK_TOP_LVDSPLL2_D4, "lvdspll2_d4", "lvdspll2_ck", 1,
174 FACTOR(CLK_TOP_LVDSPLL2_D8, "lvdspll2_d8", "lvdspll2_ck", 1,
176 FACTOR(CLK_TOP_ETHERPLL_125M, "etherpll_125m", "etherpll", 1,
178 FACTOR(CLK_TOP_ETHERPLL_50M, "etherpll_50m", "etherpll", 1,
180 FACTOR(CLK_TOP_CVBS, "cvbs", "cvbspll", 1,
182 FACTOR(CLK_TOP_CVBS_D2, "cvbs_d2", "cvbs", 1,
184 FACTOR(CLK_TOP_MMPLL, "mmpll_ck", "mmpll", 1,
186 FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll_ck", 1,
188 FACTOR(CLK_TOP_VENCPLL, "vencpll_ck", "vencpll", 1,
190 FACTOR(CLK_TOP_VENCPLL_D2, "vencpll_d2", "vencpll_ck", 1,
192 FACTOR(CLK_TOP_VCODECPLL, "vcodecpll_ck", "vcodecpll", 1,
194 FACTOR(CLK_TOP_VCODECPLL_D2, "vcodecpll_d2", "vcodecpll_ck", 1,
196 FACTOR(CLK_TOP_TVDPLL, "tvdpll_ck", "tvdpll", 1,
198 FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1,
200 FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1,
202 FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1,
204 FACTOR(CLK_TOP_TVDPLL_429M, "tvdpll_429m", "tvdpll", 1,
206 FACTOR(CLK_TOP_TVDPLL_429M_D2, "tvdpll_429m_d2", "tvdpll_429m", 1,
208 FACTOR(CLK_TOP_TVDPLL_429M_D4, "tvdpll_429m_d4", "tvdpll_429m", 1,
210 FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1,
212 FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1,
214 FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll_ck", 1,
216 FACTOR(CLK_TOP_MSDCPLL2, "msdcpll2_ck", "msdcpll2", 1,
218 FACTOR(CLK_TOP_MSDCPLL2_D2, "msdcpll2_d2", "msdcpll2_ck", 1,
220 FACTOR(CLK_TOP_MSDCPLL2_D4, "msdcpll2_d4", "msdcpll2_ck", 1,
222 FACTOR(CLK_TOP_D2A_ULCLK_6P5M, "d2a_ulclk_6p5m", "clk26m", 1,
226 static const char * const axi_parents[] = {
236 static const char * const mem_parents[] = {
241 static const char * const mm_parents[] = {
252 static const char * const pwm_parents[] = {
259 static const char * const vdec_parents[] = {
272 static const char * const venc_parents[] = {
284 static const char * const mfg_parents[] = {
303 static const char * const camtg_parents[] = {
317 static const char * const uart_parents[] = {
322 static const char * const spi_parents[] = {
331 static const char * const usb20_parents[] = {
337 static const char * const usb30_parents[] = {
344 static const char * const msdc50_0_h_parents[] = {
353 static const char * const msdc50_0_parents[] = {
367 static const char * const msdc30_1_parents[] = {
377 static const char * const msdc30_3_parents[] = {
393 static const char * const audio_parents[] = {
400 static const char * const aud_intbus_parents[] = {
410 static const char * const pmicspi_parents[] = {
420 static const char * const dpilvds1_parents[] = {
429 static const char * const atb_parents[] = {
436 static const char * const nr_parents[] = {
447 static const char * const nfi2x_parents[] = {
461 static const char * const irda_parents[] = {
468 static const char * const cci400_parents[] = {
479 static const char * const aud_1_parents[] = {
486 static const char * const aud_2_parents[] = {
493 static const char * const mem_mfg_parents[] = {
499 static const char * const axi_mfg_parents[] = {
505 static const char * const scam_parents[] = {
512 static const char * const nfiecc_parents[] = {
522 static const char * const pe2_mac_p0_parents[] = {
531 static const char * const dpilvds_parents[] = {
540 static const char * const hdcp_parents[] = {
547 static const char * const hdcp_24m_parents[] = {
554 static const char * const rtc_parents[] = {
561 static const char * const spinor_parents[] = {
574 static const char * const apll_parents[] = {
590 static const char * const a1sys_hp_parents[] = {
598 static const char * const a2sys_hp_parents[] = {
606 static const char * const asm_l_parents[] = {
613 static const char * const i2so1_parents[] = {
619 static const char * const ether_125m_parents[] = {
625 static const char * const ether_50m_parents[] = {
632 static const char * const jpgdec_parents[] = {
645 static const char * const spislv_parents[] = {
656 static const char * const ether_parents[] = {
662 static const char * const di_parents[] = {
673 static const char * const tvd_parents[] = {
679 static const char * const i2c_parents[] = {
687 static const char * const msdc0p_aes_parents[] = {
694 static const char * const cmsys_parents[] = {
702 static const char * const gcpu_parents[] = {
712 static const char * const aud_apll1_parents[] = {
717 static const char * const aud_apll2_parents[] = {
722 static const char * const audull_vtx_parents[] = {
727 static struct mtk_composite top_muxes[] = {
729 MUX_GATE_FLAGS(CLK_TOP_AXI_SEL, "axi_sel", axi_parents, 0x040, 0, 3,
731 MUX_GATE_FLAGS(CLK_TOP_MEM_SEL, "mem_sel", mem_parents, 0x040, 8, 1,
732 15, CLK_IS_CRITICAL),
733 MUX_GATE(CLK_TOP_MM_SEL, "mm_sel",
734 mm_parents, 0x040, 24, 3, 31),
736 MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel",
737 pwm_parents, 0x050, 0, 2, 7),
738 MUX_GATE(CLK_TOP_VDEC_SEL, "vdec_sel",
739 vdec_parents, 0x050, 8, 4, 15),
740 MUX_GATE(CLK_TOP_VENC_SEL, "venc_sel",
741 venc_parents, 0x050, 16, 4, 23),
742 MUX_GATE(CLK_TOP_MFG_SEL, "mfg_sel",
743 mfg_parents, 0x050, 24, 4, 31),
745 MUX_GATE(CLK_TOP_CAMTG_SEL, "camtg_sel",
746 camtg_parents, 0x060, 0, 4, 7),
747 MUX_GATE(CLK_TOP_UART_SEL, "uart_sel",
748 uart_parents, 0x060, 8, 1, 15),
749 MUX_GATE(CLK_TOP_SPI_SEL, "spi_sel",
750 spi_parents, 0x060, 16, 3, 23),
751 MUX_GATE(CLK_TOP_USB20_SEL, "usb20_sel",
752 usb20_parents, 0x060, 24, 2, 31),
754 MUX_GATE(CLK_TOP_USB30_SEL, "usb30_sel",
755 usb30_parents, 0x070, 0, 2, 7),
756 MUX_GATE(CLK_TOP_MSDC50_0_HCLK_SEL, "msdc50_0_h_sel",
757 msdc50_0_h_parents, 0x070, 8, 3, 15),
758 MUX_GATE(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel",
759 msdc50_0_parents, 0x070, 16, 4, 23),
760 MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel",
761 msdc30_1_parents, 0x070, 24, 3, 31),
763 MUX_GATE(CLK_TOP_MSDC30_2_SEL, "msdc30_2_sel",
764 msdc30_1_parents, 0x080, 0, 3, 7),
765 MUX_GATE(CLK_TOP_MSDC30_3_SEL, "msdc30_3_sel",
766 msdc30_3_parents, 0x080, 8, 4, 15),
767 MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel",
768 audio_parents, 0x080, 16, 2, 23),
769 MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel",
770 aud_intbus_parents, 0x080, 24, 3, 31),
772 MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel",
773 pmicspi_parents, 0x090, 0, 3, 7),
774 MUX_GATE(CLK_TOP_DPILVDS1_SEL, "dpilvds1_sel",
775 dpilvds1_parents, 0x090, 8, 3, 15),
776 MUX_GATE(CLK_TOP_ATB_SEL, "atb_sel",
777 atb_parents, 0x090, 16, 2, 23),
778 MUX_GATE(CLK_TOP_NR_SEL, "nr_sel",
779 nr_parents, 0x090, 24, 3, 31),
781 MUX_GATE(CLK_TOP_NFI2X_SEL, "nfi2x_sel",
782 nfi2x_parents, 0x0a0, 0, 4, 7),
783 MUX_GATE(CLK_TOP_IRDA_SEL, "irda_sel",
784 irda_parents, 0x0a0, 8, 2, 15),
785 MUX_GATE(CLK_TOP_CCI400_SEL, "cci400_sel",
786 cci400_parents, 0x0a0, 16, 3, 23),
787 MUX_GATE(CLK_TOP_AUD_1_SEL, "aud_1_sel",
788 aud_1_parents, 0x0a0, 24, 2, 31),
790 MUX_GATE(CLK_TOP_AUD_2_SEL, "aud_2_sel",
791 aud_2_parents, 0x0b0, 0, 2, 7),
792 MUX_GATE(CLK_TOP_MEM_MFG_IN_AS_SEL, "mem_mfg_sel",
793 mem_mfg_parents, 0x0b0, 8, 2, 15),
794 MUX_GATE(CLK_TOP_AXI_MFG_IN_AS_SEL, "axi_mfg_sel",
795 axi_mfg_parents, 0x0b0, 16, 2, 23),
796 MUX_GATE(CLK_TOP_SCAM_SEL, "scam_sel",
797 scam_parents, 0x0b0, 24, 2, 31),
799 MUX_GATE(CLK_TOP_NFIECC_SEL, "nfiecc_sel",
800 nfiecc_parents, 0x0c0, 0, 3, 7),
801 MUX_GATE(CLK_TOP_PE2_MAC_P0_SEL, "pe2_mac_p0_sel",
802 pe2_mac_p0_parents, 0x0c0, 8, 3, 15),
803 MUX_GATE(CLK_TOP_PE2_MAC_P1_SEL, "pe2_mac_p1_sel",
804 pe2_mac_p0_parents, 0x0c0, 16, 3, 23),
805 MUX_GATE(CLK_TOP_DPILVDS_SEL, "dpilvds_sel",
806 dpilvds_parents, 0x0c0, 24, 3, 31),
808 MUX_GATE(CLK_TOP_MSDC50_3_HCLK_SEL, "msdc50_3_h_sel",
809 msdc50_0_h_parents, 0x0d0, 0, 3, 7),
810 MUX_GATE(CLK_TOP_HDCP_SEL, "hdcp_sel",
811 hdcp_parents, 0x0d0, 8, 2, 15),
812 MUX_GATE(CLK_TOP_HDCP_24M_SEL, "hdcp_24m_sel",
813 hdcp_24m_parents, 0x0d0, 16, 2, 23),
814 MUX_GATE_FLAGS(CLK_TOP_RTC_SEL, "rtc_sel", rtc_parents, 0x0d0, 24, 2,
815 31, CLK_IS_CRITICAL),
817 MUX_GATE(CLK_TOP_SPINOR_SEL, "spinor_sel",
818 spinor_parents, 0x500, 0, 4, 7),
819 MUX_GATE(CLK_TOP_APLL_SEL, "apll_sel",
820 apll_parents, 0x500, 8, 4, 15),
821 MUX_GATE(CLK_TOP_APLL2_SEL, "apll2_sel",
822 apll_parents, 0x500, 16, 4, 23),
823 MUX_GATE(CLK_TOP_A1SYS_HP_SEL, "a1sys_hp_sel",
824 a1sys_hp_parents, 0x500, 24, 3, 31),
826 MUX_GATE(CLK_TOP_A2SYS_HP_SEL, "a2sys_hp_sel",
827 a2sys_hp_parents, 0x510, 0, 3, 7),
828 MUX_GATE(CLK_TOP_ASM_L_SEL, "asm_l_sel",
829 asm_l_parents, 0x510, 8, 2, 15),
830 MUX_GATE(CLK_TOP_ASM_M_SEL, "asm_m_sel",
831 asm_l_parents, 0x510, 16, 2, 23),
832 MUX_GATE(CLK_TOP_ASM_H_SEL, "asm_h_sel",
833 asm_l_parents, 0x510, 24, 2, 31),
835 MUX_GATE(CLK_TOP_I2SO1_SEL, "i2so1_sel",
836 i2so1_parents, 0x520, 0, 2, 7),
837 MUX_GATE(CLK_TOP_I2SO2_SEL, "i2so2_sel",
838 i2so1_parents, 0x520, 8, 2, 15),
839 MUX_GATE(CLK_TOP_I2SO3_SEL, "i2so3_sel",
840 i2so1_parents, 0x520, 16, 2, 23),
841 MUX_GATE(CLK_TOP_TDMO0_SEL, "tdmo0_sel",
842 i2so1_parents, 0x520, 24, 2, 31),
844 MUX_GATE(CLK_TOP_TDMO1_SEL, "tdmo1_sel",
845 i2so1_parents, 0x530, 0, 2, 7),
846 MUX_GATE(CLK_TOP_I2SI1_SEL, "i2si1_sel",
847 i2so1_parents, 0x530, 8, 2, 15),
848 MUX_GATE(CLK_TOP_I2SI2_SEL, "i2si2_sel",
849 i2so1_parents, 0x530, 16, 2, 23),
850 MUX_GATE(CLK_TOP_I2SI3_SEL, "i2si3_sel",
851 i2so1_parents, 0x530, 24, 2, 31),
853 MUX_GATE(CLK_TOP_ETHER_125M_SEL, "ether_125m_sel",
854 ether_125m_parents, 0x540, 0, 2, 7),
855 MUX_GATE(CLK_TOP_ETHER_50M_SEL, "ether_50m_sel",
856 ether_50m_parents, 0x540, 8, 2, 15),
857 MUX_GATE(CLK_TOP_JPGDEC_SEL, "jpgdec_sel",
858 jpgdec_parents, 0x540, 16, 4, 23),
859 MUX_GATE(CLK_TOP_SPISLV_SEL, "spislv_sel",
860 spislv_parents, 0x540, 24, 3, 31),
862 MUX_GATE(CLK_TOP_ETHER_50M_RMII_SEL, "ether_sel",
863 ether_parents, 0x550, 0, 2, 7),
864 MUX_GATE(CLK_TOP_CAM2TG_SEL, "cam2tg_sel",
865 camtg_parents, 0x550, 8, 4, 15),
866 MUX_GATE(CLK_TOP_DI_SEL, "di_sel",
867 di_parents, 0x550, 16, 3, 23),
868 MUX_GATE(CLK_TOP_TVD_SEL, "tvd_sel",
869 tvd_parents, 0x550, 24, 2, 31),
871 MUX_GATE(CLK_TOP_I2C_SEL, "i2c_sel",
872 i2c_parents, 0x560, 0, 3, 7),
873 MUX_GATE(CLK_TOP_PWM_INFRA_SEL, "pwm_infra_sel",
874 pwm_parents, 0x560, 8, 2, 15),
875 MUX_GATE(CLK_TOP_MSDC0P_AES_SEL, "msdc0p_aes_sel",
876 msdc0p_aes_parents, 0x560, 16, 2, 23),
877 MUX_GATE(CLK_TOP_CMSYS_SEL, "cmsys_sel",
878 cmsys_parents, 0x560, 24, 3, 31),
880 MUX_GATE(CLK_TOP_GCPU_SEL, "gcpu_sel",
881 gcpu_parents, 0x570, 0, 3, 7),
883 MUX(CLK_TOP_AUD_APLL1_SEL, "aud_apll1_sel",
884 aud_apll1_parents, 0x134, 0, 1),
885 MUX(CLK_TOP_AUD_APLL2_SEL, "aud_apll2_sel",
886 aud_apll2_parents, 0x134, 1, 1),
887 MUX(CLK_TOP_DA_AUDULL_VTX_6P5M_SEL, "audull_vtx_sel",
888 audull_vtx_parents, 0x134, 31, 1),
891 static const char * const mcu_mp0_parents[] = {
898 static const char * const mcu_mp2_parents[] = {
905 static const char * const mcu_bus_parents[] = {
912 static struct mtk_composite mcu_muxes[] = {
913 /* mp0_pll_divider_cfg */
914 MUX_GATE_FLAGS(CLK_MCU_MP0_SEL, "mcu_mp0_sel", mcu_mp0_parents, 0x7A0,
915 9, 2, -1, CLK_IS_CRITICAL),
916 /* mp2_pll_divider_cfg */
917 MUX_GATE_FLAGS(CLK_MCU_MP2_SEL, "mcu_mp2_sel", mcu_mp2_parents, 0x7A8,
918 9, 2, -1, CLK_IS_CRITICAL),
919 /* bus_pll_divider_cfg */
920 MUX_GATE_FLAGS(CLK_MCU_BUS_SEL, "mcu_bus_sel", mcu_bus_parents, 0x7C0,
921 9, 2, -1, CLK_IS_CRITICAL),
924 static const struct mtk_clk_divider top_adj_divs[] = {
925 DIV_ADJ(CLK_TOP_APLL_DIV0, "apll_div0", "i2so1_sel", 0x124, 0, 8),
926 DIV_ADJ(CLK_TOP_APLL_DIV1, "apll_div1", "i2so2_sel", 0x124, 8, 8),
927 DIV_ADJ(CLK_TOP_APLL_DIV2, "apll_div2", "i2so3_sel", 0x124, 16, 8),
928 DIV_ADJ(CLK_TOP_APLL_DIV3, "apll_div3", "tdmo0_sel", 0x124, 24, 8),
929 DIV_ADJ(CLK_TOP_APLL_DIV4, "apll_div4", "tdmo1_sel", 0x128, 0, 8),
930 DIV_ADJ(CLK_TOP_APLL_DIV5, "apll_div5", "i2si1_sel", 0x128, 8, 8),
931 DIV_ADJ(CLK_TOP_APLL_DIV6, "apll_div6", "i2si2_sel", 0x128, 16, 8),
932 DIV_ADJ(CLK_TOP_APLL_DIV7, "apll_div7", "i2si3_sel", 0x128, 24, 8),
935 static const struct mtk_gate_regs top_cg_regs = {
941 #define GATE_TOP(_id, _name, _parent, _shift) { \
944 .parent_name = _parent, \
945 .regs = &top_cg_regs, \
947 .ops = &mtk_clk_gate_ops_no_setclr, \
950 static const struct mtk_gate top_clks[] = {
951 GATE_TOP(CLK_TOP_APLL_DIV_PDN0, "apll_div_pdn0", "i2so1_sel", 0),
952 GATE_TOP(CLK_TOP_APLL_DIV_PDN1, "apll_div_pdn1", "i2so2_sel", 1),
953 GATE_TOP(CLK_TOP_APLL_DIV_PDN2, "apll_div_pdn2", "i2so3_sel", 2),
954 GATE_TOP(CLK_TOP_APLL_DIV_PDN3, "apll_div_pdn3", "tdmo0_sel", 3),
955 GATE_TOP(CLK_TOP_APLL_DIV_PDN4, "apll_div_pdn4", "tdmo1_sel", 4),
956 GATE_TOP(CLK_TOP_APLL_DIV_PDN5, "apll_div_pdn5", "i2si1_sel", 5),
957 GATE_TOP(CLK_TOP_APLL_DIV_PDN6, "apll_div_pdn6", "i2si2_sel", 6),
958 GATE_TOP(CLK_TOP_APLL_DIV_PDN7, "apll_div_pdn7", "i2si3_sel", 7),
961 static const struct mtk_gate_regs infra_cg_regs = {
967 #define GATE_INFRA(_id, _name, _parent, _shift) { \
970 .parent_name = _parent, \
971 .regs = &infra_cg_regs, \
973 .ops = &mtk_clk_gate_ops_setclr, \
976 static const struct mtk_gate infra_clks[] = {
977 GATE_INFRA(CLK_INFRA_DBGCLK, "infra_dbgclk", "axi_sel", 0),
978 GATE_INFRA(CLK_INFRA_GCE, "infra_gce", "axi_sel", 6),
979 GATE_INFRA(CLK_INFRA_M4U, "infra_m4u", "mem_sel", 8),
980 GATE_INFRA(CLK_INFRA_KP, "infra_kp", "axi_sel", 16),
981 GATE_INFRA(CLK_INFRA_AO_SPI0, "infra_ao_spi0", "spi_sel", 24),
982 GATE_INFRA(CLK_INFRA_AO_SPI1, "infra_ao_spi1", "spislv_sel", 25),
983 GATE_INFRA(CLK_INFRA_AO_UART5, "infra_ao_uart5", "axi_sel", 26),
986 static const struct mtk_gate_regs peri0_cg_regs = {
992 static const struct mtk_gate_regs peri1_cg_regs = {
998 static const struct mtk_gate_regs peri2_cg_regs = {
1004 #define GATE_PERI0(_id, _name, _parent, _shift) { \
1007 .parent_name = _parent, \
1008 .regs = &peri0_cg_regs, \
1010 .ops = &mtk_clk_gate_ops_setclr, \
1013 #define GATE_PERI1(_id, _name, _parent, _shift) { \
1016 .parent_name = _parent, \
1017 .regs = &peri1_cg_regs, \
1019 .ops = &mtk_clk_gate_ops_setclr, \
1022 #define GATE_PERI2(_id, _name, _parent, _shift) { \
1025 .parent_name = _parent, \
1026 .regs = &peri2_cg_regs, \
1028 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
1031 static const struct mtk_gate peri_clks[] = {
1033 GATE_PERI0(CLK_PERI_NFI, "per_nfi",
1035 GATE_PERI0(CLK_PERI_THERM, "per_therm",
1037 GATE_PERI0(CLK_PERI_PWM0, "per_pwm0",
1039 GATE_PERI0(CLK_PERI_PWM1, "per_pwm1",
1041 GATE_PERI0(CLK_PERI_PWM2, "per_pwm2",
1043 GATE_PERI0(CLK_PERI_PWM3, "per_pwm3",
1045 GATE_PERI0(CLK_PERI_PWM4, "per_pwm4",
1047 GATE_PERI0(CLK_PERI_PWM5, "per_pwm5",
1049 GATE_PERI0(CLK_PERI_PWM6, "per_pwm6",
1051 GATE_PERI0(CLK_PERI_PWM7, "per_pwm7",
1053 GATE_PERI0(CLK_PERI_PWM, "per_pwm",
1055 GATE_PERI0(CLK_PERI_AP_DMA, "per_ap_dma",
1057 GATE_PERI0(CLK_PERI_MSDC30_0, "per_msdc30_0",
1058 "msdc50_0_sel", 14),
1059 GATE_PERI0(CLK_PERI_MSDC30_1, "per_msdc30_1",
1060 "msdc30_1_sel", 15),
1061 GATE_PERI0(CLK_PERI_MSDC30_2, "per_msdc30_2",
1062 "msdc30_2_sel", 16),
1063 GATE_PERI0(CLK_PERI_MSDC30_3, "per_msdc30_3",
1064 "msdc30_3_sel", 17),
1065 GATE_PERI0(CLK_PERI_UART0, "per_uart0",
1067 GATE_PERI0(CLK_PERI_UART1, "per_uart1",
1069 GATE_PERI0(CLK_PERI_UART2, "per_uart2",
1071 GATE_PERI0(CLK_PERI_UART3, "per_uart3",
1073 GATE_PERI0(CLK_PERI_I2C0, "per_i2c0",
1075 GATE_PERI0(CLK_PERI_I2C1, "per_i2c1",
1077 GATE_PERI0(CLK_PERI_I2C2, "per_i2c2",
1079 GATE_PERI0(CLK_PERI_I2C3, "per_i2c3",
1081 GATE_PERI0(CLK_PERI_I2C4, "per_i2c4",
1083 GATE_PERI0(CLK_PERI_AUXADC, "per_auxadc",
1084 "ltepll_fs26m", 29),
1085 GATE_PERI0(CLK_PERI_SPI0, "per_spi0",
1088 GATE_PERI1(CLK_PERI_SPI, "per_spi",
1090 GATE_PERI1(CLK_PERI_I2C5, "per_i2c5",
1092 GATE_PERI1(CLK_PERI_SPI2, "per_spi2",
1094 GATE_PERI1(CLK_PERI_SPI3, "per_spi3",
1096 GATE_PERI1(CLK_PERI_SPI5, "per_spi5",
1098 GATE_PERI1(CLK_PERI_UART4, "per_uart4",
1100 GATE_PERI1(CLK_PERI_SFLASH, "per_sflash",
1102 GATE_PERI1(CLK_PERI_GMAC, "per_gmac",
1104 GATE_PERI1(CLK_PERI_PCIE0, "per_pcie0",
1106 GATE_PERI1(CLK_PERI_PCIE1, "per_pcie1",
1108 GATE_PERI1(CLK_PERI_GMAC_PCLK, "per_gmac_pclk",
1111 GATE_PERI2(CLK_PERI_MSDC50_0_EN, "per_msdc50_0_en",
1113 GATE_PERI2(CLK_PERI_MSDC30_1_EN, "per_msdc30_1_en",
1115 GATE_PERI2(CLK_PERI_MSDC30_2_EN, "per_msdc30_2_en",
1117 GATE_PERI2(CLK_PERI_MSDC30_3_EN, "per_msdc30_3_en",
1119 GATE_PERI2(CLK_PERI_MSDC50_0_HCLK_EN, "per_msdc50_0_h",
1120 "msdc50_0_h_sel", 4),
1121 GATE_PERI2(CLK_PERI_MSDC50_3_HCLK_EN, "per_msdc50_3_h",
1122 "msdc50_3_h_sel", 5),
1125 #define MT2712_PLL_FMAX (3000UL * MHZ)
1127 #define CON0_MT2712_RST_BAR BIT(24)
1129 #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
1130 _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
1131 _tuner_en_bit, _pcw_reg, _pcw_shift, \
1136 .pwr_reg = _pwr_reg, \
1137 .en_mask = _en_mask, \
1139 .rst_bar_mask = CON0_MT2712_RST_BAR, \
1140 .fmax = MT2712_PLL_FMAX, \
1141 .pcwbits = _pcwbits, \
1142 .pd_reg = _pd_reg, \
1143 .pd_shift = _pd_shift, \
1144 .tuner_reg = _tuner_reg, \
1145 .tuner_en_reg = _tuner_en_reg, \
1146 .tuner_en_bit = _tuner_en_bit, \
1147 .pcw_reg = _pcw_reg, \
1148 .pcw_shift = _pcw_shift, \
1149 .div_table = _div_table, \
1152 #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
1153 _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
1154 _tuner_en_bit, _pcw_reg, _pcw_shift) \
1155 PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
1156 _pcwbits, _pd_reg, _pd_shift, _tuner_reg, \
1157 _tuner_en_reg, _tuner_en_bit, _pcw_reg, \
1160 static const struct mtk_pll_div_table armca35pll_div_table[] = {
1161 { .div = 0, .freq = MT2712_PLL_FMAX },
1162 { .div = 1, .freq = 1202500000 },
1163 { .div = 2, .freq = 500500000 },
1164 { .div = 3, .freq = 315250000 },
1165 { .div = 4, .freq = 157625000 },
1169 static const struct mtk_pll_div_table armca72pll_div_table[] = {
1170 { .div = 0, .freq = MT2712_PLL_FMAX },
1171 { .div = 1, .freq = 994500000 },
1172 { .div = 2, .freq = 520000000 },
1173 { .div = 3, .freq = 315250000 },
1174 { .div = 4, .freq = 157625000 },
1178 static const struct mtk_pll_div_table mmpll_div_table[] = {
1179 { .div = 0, .freq = MT2712_PLL_FMAX },
1180 { .div = 1, .freq = 1001000000 },
1181 { .div = 2, .freq = 601250000 },
1182 { .div = 3, .freq = 250250000 },
1183 { .div = 4, .freq = 125125000 },
1187 static const struct mtk_pll_data plls[] = {
1188 PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0230, 0x023C, 0xf0000101,
1189 HAVE_RST_BAR, 31, 0x0230, 4, 0, 0, 0, 0x0234, 0),
1190 PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0240, 0x024C, 0xfe000101,
1191 HAVE_RST_BAR, 31, 0x0240, 4, 0, 0, 0, 0x0244, 0),
1192 PLL(CLK_APMIXED_VCODECPLL, "vcodecpll", 0x0320, 0x032C, 0xc0000101,
1193 0, 31, 0x0320, 4, 0, 0, 0, 0x0324, 0),
1194 PLL(CLK_APMIXED_VENCPLL, "vencpll", 0x0280, 0x028C, 0x00000101,
1195 0, 31, 0x0280, 4, 0, 0, 0, 0x0284, 0),
1196 PLL(CLK_APMIXED_APLL1, "apll1", 0x0330, 0x0340, 0x00000101,
1197 0, 31, 0x0330, 4, 0x0338, 0x0014, 0, 0x0334, 0),
1198 PLL(CLK_APMIXED_APLL2, "apll2", 0x0350, 0x0360, 0x00000101,
1199 0, 31, 0x0350, 4, 0x0358, 0x0014, 1, 0x0354, 0),
1200 PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x0370, 0x037c, 0x00000101,
1201 0, 31, 0x0370, 4, 0, 0, 0, 0x0374, 0),
1202 PLL(CLK_APMIXED_LVDSPLL2, "lvdspll2", 0x0390, 0x039C, 0x00000101,
1203 0, 31, 0x0390, 4, 0, 0, 0, 0x0394, 0),
1204 PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0270, 0x027C, 0x00000101,
1205 0, 31, 0x0270, 4, 0, 0, 0, 0x0274, 0),
1206 PLL(CLK_APMIXED_MSDCPLL2, "msdcpll2", 0x0410, 0x041C, 0x00000101,
1207 0, 31, 0x0410, 4, 0, 0, 0, 0x0414, 0),
1208 PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0290, 0x029C, 0xc0000101,
1209 0, 31, 0x0290, 4, 0, 0, 0, 0x0294, 0),
1210 PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0250, 0x0260, 0x00000101,
1211 0, 31, 0x0250, 4, 0, 0, 0, 0x0254, 0,
1213 PLL_B(CLK_APMIXED_ARMCA35PLL, "armca35pll", 0x0100, 0x0110, 0xf0000101,
1214 HAVE_RST_BAR, 31, 0x0100, 4, 0, 0, 0, 0x0104, 0,
1215 armca35pll_div_table),
1216 PLL_B(CLK_APMIXED_ARMCA72PLL, "armca72pll", 0x0210, 0x0220, 0x00000101,
1217 0, 31, 0x0210, 4, 0, 0, 0, 0x0214, 0,
1218 armca72pll_div_table),
1219 PLL(CLK_APMIXED_ETHERPLL, "etherpll", 0x0300, 0x030C, 0xc0000101,
1220 0, 31, 0x0300, 4, 0, 0, 0, 0x0304, 0),
1223 static int clk_mt2712_apmixed_probe(struct platform_device *pdev)
1225 struct clk_onecell_data *clk_data;
1227 struct device_node *node = pdev->dev.of_node;
1229 clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
1231 mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
1233 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1236 pr_err("%s(): could not register clock provider: %d\n",
1242 static struct clk_onecell_data *top_clk_data;
1244 static void clk_mt2712_top_init_early(struct device_node *node)
1248 if (!top_clk_data) {
1249 top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
1251 for (i = 0; i < CLK_TOP_NR_CLK; i++)
1252 top_clk_data->clks[i] = ERR_PTR(-EPROBE_DEFER);
1255 mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
1258 r = of_clk_add_provider(node, of_clk_src_onecell_get, top_clk_data);
1260 pr_err("%s(): could not register clock provider: %d\n",
1264 CLK_OF_DECLARE_DRIVER(mt2712_topckgen, "mediatek,mt2712-topckgen",
1265 clk_mt2712_top_init_early);
1267 static int clk_mt2712_top_probe(struct platform_device *pdev)
1270 struct device_node *node = pdev->dev.of_node;
1272 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1274 base = devm_ioremap_resource(&pdev->dev, res);
1276 pr_err("%s(): ioremap failed\n", __func__);
1277 return PTR_ERR(base);
1280 if (!top_clk_data) {
1281 top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
1283 for (i = 0; i < CLK_TOP_NR_CLK; i++) {
1284 if (top_clk_data->clks[i] == ERR_PTR(-EPROBE_DEFER))
1285 top_clk_data->clks[i] = ERR_PTR(-ENOENT);
1289 mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
1291 mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
1293 mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data);
1294 mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
1295 &mt2712_clk_lock, top_clk_data);
1296 mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs), base,
1297 &mt2712_clk_lock, top_clk_data);
1298 mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
1301 r = of_clk_add_provider(node, of_clk_src_onecell_get, top_clk_data);
1304 pr_err("%s(): could not register clock provider: %d\n",
1310 static int clk_mt2712_infra_probe(struct platform_device *pdev)
1312 struct clk_onecell_data *clk_data;
1314 struct device_node *node = pdev->dev.of_node;
1316 clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
1318 mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
1321 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1324 pr_err("%s(): could not register clock provider: %d\n",
1327 mtk_register_reset_controller(node, 2, 0x30);
1332 static int clk_mt2712_peri_probe(struct platform_device *pdev)
1334 struct clk_onecell_data *clk_data;
1336 struct device_node *node = pdev->dev.of_node;
1338 clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
1340 mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
1343 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1346 pr_err("%s(): could not register clock provider: %d\n",
1349 mtk_register_reset_controller(node, 2, 0);
1354 static int clk_mt2712_mcu_probe(struct platform_device *pdev)
1356 struct clk_onecell_data *clk_data;
1358 struct device_node *node = pdev->dev.of_node;
1360 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1362 base = devm_ioremap_resource(&pdev->dev, res);
1364 pr_err("%s(): ioremap failed\n", __func__);
1365 return PTR_ERR(base);
1368 clk_data = mtk_alloc_clk_data(CLK_MCU_NR_CLK);
1370 mtk_clk_register_composites(mcu_muxes, ARRAY_SIZE(mcu_muxes), base,
1371 &mt2712_clk_lock, clk_data);
1373 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1376 pr_err("%s(): could not register clock provider: %d\n",
1382 static const struct of_device_id of_match_clk_mt2712[] = {
1384 .compatible = "mediatek,mt2712-apmixedsys",
1385 .data = clk_mt2712_apmixed_probe,
1387 .compatible = "mediatek,mt2712-topckgen",
1388 .data = clk_mt2712_top_probe,
1390 .compatible = "mediatek,mt2712-infracfg",
1391 .data = clk_mt2712_infra_probe,
1393 .compatible = "mediatek,mt2712-pericfg",
1394 .data = clk_mt2712_peri_probe,
1396 .compatible = "mediatek,mt2712-mcucfg",
1397 .data = clk_mt2712_mcu_probe,
1403 static int clk_mt2712_probe(struct platform_device *pdev)
1405 int (*clk_probe)(struct platform_device *);
1408 clk_probe = of_device_get_match_data(&pdev->dev);
1412 r = clk_probe(pdev);
1415 "could not register clock provider: %s: %d\n",
1421 static struct platform_driver clk_mt2712_drv = {
1422 .probe = clk_mt2712_probe,
1424 .name = "clk-mt2712",
1425 .owner = THIS_MODULE,
1426 .of_match_table = of_match_clk_mt2712,
1430 static int __init clk_mt2712_init(void)
1432 return platform_driver_register(&clk_mt2712_drv);
1435 arch_initcall(clk_mt2712_init);