Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 NXP |
| 4 | */ |
| 5 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 6 | #include <div64.h> |
| 7 | #include <asm/io.h> |
| 8 | #include <errno.h> |
| 9 | #include <asm/arch/imx-regs.h> |
| 10 | #include <asm/arch/pcc.h> |
| 11 | #include <asm/arch/cgc.h> |
| 12 | #include <asm/arch/sys_proto.h> |
| 13 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 14 | #define cgc_clk_TYPES 2 |
| 15 | #define cgc_clk_NUM 8 |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 16 | |
Alice Guo | 23ee0e1 | 2021-10-29 09:46:29 +0800 | [diff] [blame] | 17 | static enum cgc_clk pcc1_clksrc[][8] = { |
| 18 | { |
| 19 | }, |
| 20 | { |
| 21 | DUMMY0_CLK, |
| 22 | LPOSC, |
| 23 | SOSC_DIV2, |
| 24 | FRO_DIV2, |
| 25 | CM33_BUSCLK, |
| 26 | PLL1_VCO_DIV, |
| 27 | PLL0_PFD2_DIV, |
| 28 | PLL0_PFD1_DIV, |
| 29 | } |
| 30 | }; |
| 31 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 32 | static enum cgc_clk pcc3_clksrc[][8] = { |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 33 | { |
| 34 | }, |
| 35 | { DUMMY0_CLK, |
| 36 | LPOSC, |
| 37 | SOSC_DIV2, |
| 38 | FRO_DIV2, |
| 39 | XBAR_BUSCLK, |
| 40 | PLL3_PFD1_DIV1, |
| 41 | PLL3_PFD0_DIV2, |
| 42 | PLL3_PFD0_DIV1 |
| 43 | } |
| 44 | }; |
| 45 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 46 | static enum cgc_clk pcc4_clksrc[][8] = { |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 47 | { |
| 48 | DUMMY0_CLK, |
| 49 | SOSC_DIV1, |
| 50 | FRO_DIV1, |
| 51 | PLL3_PFD3_DIV2, |
| 52 | PLL3_PFD3_DIV1, |
| 53 | PLL3_PFD2_DIV2, |
| 54 | PLL3_PFD2_DIV1, |
| 55 | PLL3_PFD1_DIV2 |
| 56 | }, |
| 57 | { |
| 58 | DUMMY0_CLK, |
| 59 | DUMMY1_CLK, |
| 60 | LPOSC, |
| 61 | SOSC_DIV2, |
| 62 | FRO_DIV2, |
| 63 | XBAR_BUSCLK, |
| 64 | PLL3_VCODIV, |
| 65 | PLL3_PFD0_DIV1 |
| 66 | } |
| 67 | }; |
| 68 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 69 | static enum cgc_clk pcc5_clksrc[][8] = { |
| 70 | { |
| 71 | DUMMY0_CLK, |
| 72 | PLL4_PFD3_DIV2, |
| 73 | PLL4_PFD2_DIV2, |
| 74 | PLL4_PFD2_DIV1, |
| 75 | PLL4_PFD1_DIV2, |
| 76 | PLL4_PFD1_DIV1, |
| 77 | PLL4_PFD0_DIV2, |
| 78 | PLL4_PFD0_DIV1 |
| 79 | }, |
| 80 | { |
| 81 | DUMMY0_CLK, |
| 82 | DUMMY1_CLK, |
| 83 | LPOSC, |
| 84 | SOSC_DIV2, |
| 85 | FRO_DIV2, |
| 86 | LPAV_BUSCLK, |
| 87 | PLL4_VCODIV, |
| 88 | PLL4_PFD3_DIV1 |
| 89 | } |
| 90 | }; |
| 91 | |
Alice Guo | 23ee0e1 | 2021-10-29 09:46:29 +0800 | [diff] [blame] | 92 | static struct pcc_entry pcc1_arrays[] = { |
| 93 | {PCC1_RBASE, ADC1_PCC1_SLOT, CLKSRC_PER_BUS, PCC_NO_DIV, PCC_HAS_RST_B}, |
| 94 | {} |
| 95 | }; |
| 96 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 97 | static struct pcc_entry pcc3_arrays[] = { |
| 98 | {PCC3_RBASE, DMA1_MP_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 99 | {PCC3_RBASE, DMA1_CH0_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 100 | {PCC3_RBASE, DMA1_CH1_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 101 | {PCC3_RBASE, DMA1_CH2_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 102 | {PCC3_RBASE, DMA1_CH3_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 103 | {PCC3_RBASE, DMA1_CH4_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 104 | {PCC3_RBASE, DMA1_CH5_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 105 | {PCC3_RBASE, DMA1_CH6_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 106 | {PCC3_RBASE, DMA1_CH7_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 107 | {PCC3_RBASE, DMA1_CH8_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 108 | {PCC3_RBASE, DMA1_CH9_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 109 | {PCC3_RBASE, DMA1_CH10_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 110 | {PCC3_RBASE, DMA1_CH11_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 111 | {PCC3_RBASE, DMA1_CH12_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 112 | {PCC3_RBASE, DMA1_CH13_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 113 | {PCC3_RBASE, DMA1_CH14_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 114 | {PCC3_RBASE, DMA1_CH15_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 115 | {PCC3_RBASE, DMA1_CH16_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 116 | {PCC3_RBASE, DMA1_CH17_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 117 | {PCC3_RBASE, DMA1_CH18_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 118 | {PCC3_RBASE, DMA1_CH19_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 119 | {PCC3_RBASE, DMA1_CH20_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 120 | {PCC3_RBASE, DMA1_CH21_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 121 | {PCC3_RBASE, DMA1_CH22_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 122 | {PCC3_RBASE, DMA1_CH23_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 123 | {PCC3_RBASE, DMA1_CH24_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 124 | {PCC3_RBASE, DMA1_CH25_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 125 | {PCC3_RBASE, DMA1_CH26_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 126 | {PCC3_RBASE, DMA1_CH27_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 127 | {PCC3_RBASE, DMA1_CH28_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 128 | {PCC3_RBASE, DMA1_CH29_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 129 | {PCC3_RBASE, DMA1_CH30_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 130 | {PCC3_RBASE, DMA1_CH31_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 131 | {PCC3_RBASE, MU0_B_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 132 | {PCC3_RBASE, MU3_A_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 133 | {PCC3_RBASE, LLWU1_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 134 | {PCC3_RBASE, UPOWER_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 135 | {PCC3_RBASE, WDOG3_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 136 | {PCC3_RBASE, WDOG4_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
Peng Fan | e612904 | 2022-04-06 14:30:10 +0800 | [diff] [blame] | 137 | {PCC3_RBASE, CAAM_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B}, |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 138 | {PCC3_RBASE, XRDC_MGR_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 139 | {PCC3_RBASE, SEMA42_1_PCC3_SLOT, CLKSRC_PER_BUS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 140 | {PCC3_RBASE, ROMCP1_PCC3_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B}, |
| 141 | {PCC3_RBASE, LPIT1_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 142 | {PCC3_RBASE, TPM4_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 143 | {PCC3_RBASE, TPM5_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 144 | {PCC3_RBASE, FLEXIO1_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 145 | {PCC3_RBASE, I3C2_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 146 | {PCC3_RBASE, LPI2C4_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 147 | {PCC3_RBASE, LPI2C5_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 148 | {PCC3_RBASE, LPUART4_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 149 | {PCC3_RBASE, LPUART5_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 150 | {PCC3_RBASE, LPSPI4_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 151 | {PCC3_RBASE, LPSPI5_PCC3_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B}, |
| 152 | {} |
| 153 | }; |
| 154 | |
| 155 | static struct pcc_entry pcc4_arrays[] = { |
| 156 | {PCC4_RBASE, FLEXSPI2_PCC4_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 157 | {PCC4_RBASE, TPM6_PCC4_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 158 | {PCC4_RBASE, TPM7_PCC4_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 159 | {PCC4_RBASE, LPI2C6_PCC4_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 160 | {PCC4_RBASE, LPI2C7_PCC4_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 161 | {PCC4_RBASE, LPUART6_PCC4_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 162 | {PCC4_RBASE, LPUART7_PCC4_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 163 | {PCC4_RBASE, SAI4_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 164 | {PCC4_RBASE, SAI5_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 165 | {PCC4_RBASE, PCTLE_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 166 | {PCC4_RBASE, PCTLF_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 167 | {PCC4_RBASE, SDHC0_PCC4_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 168 | {PCC4_RBASE, SDHC1_PCC4_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 169 | {PCC4_RBASE, SDHC2_PCC4_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 170 | {PCC4_RBASE, USB0_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 171 | {PCC4_RBASE, USBPHY_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 172 | {PCC4_RBASE, USB1_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 173 | {PCC4_RBASE, USB1PHY_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 174 | {PCC4_RBASE, USB_XBAR_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 175 | {PCC4_RBASE, ENET_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 176 | {PCC4_RBASE, SFA1_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 177 | {PCC4_RBASE, RGPIOE_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 178 | {PCC4_RBASE, RGPIOF_PCC4_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 179 | {} |
| 180 | }; |
| 181 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 182 | static struct pcc_entry pcc5_arrays[] = { |
| 183 | {PCC5_RBASE, DMA2_MP_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 184 | {PCC5_RBASE, DMA2_CH0_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 185 | {PCC5_RBASE, DMA2_CH1_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 186 | {PCC5_RBASE, DMA2_CH2_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 187 | {PCC5_RBASE, DMA2_CH3_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 188 | {PCC5_RBASE, DMA2_CH4_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 189 | {PCC5_RBASE, DMA2_CH5_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 190 | {PCC5_RBASE, DMA2_CH6_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 191 | {PCC5_RBASE, DMA2_CH7_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 192 | {PCC5_RBASE, DMA2_CH8_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 193 | {PCC5_RBASE, DMA2_CH9_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 194 | {PCC5_RBASE, DMA2_CH10_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 195 | {PCC5_RBASE, DMA2_CH11_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 196 | {PCC5_RBASE, DMA2_CH12_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 197 | {PCC5_RBASE, DMA2_CH13_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 198 | {PCC5_RBASE, DMA2_CH14_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 199 | {PCC5_RBASE, DMA2_CH15_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 200 | {PCC5_RBASE, DMA2_CH16_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 201 | {PCC5_RBASE, DMA2_CH17_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 202 | {PCC5_RBASE, DMA2_CH18_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 203 | {PCC5_RBASE, DMA2_CH19_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 204 | {PCC5_RBASE, DMA2_CH20_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 205 | {PCC5_RBASE, DMA2_CH21_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 206 | {PCC5_RBASE, DMA2_CH22_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 207 | {PCC5_RBASE, DMA2_CH23_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 208 | {PCC5_RBASE, DMA2_CH24_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 209 | {PCC5_RBASE, DMA2_CH25_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 210 | {PCC5_RBASE, DMA2_CH26_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 211 | {PCC5_RBASE, DMA2_CH27_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 212 | {PCC5_RBASE, DMA2_CH28_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 213 | {PCC5_RBASE, DMA2_CH29_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 214 | {PCC5_RBASE, DMA2_CH30_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 215 | {PCC5_RBASE, DMA2_CH31_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 216 | {PCC5_RBASE, MU2_B_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 217 | {PCC5_RBASE, MU3_B_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 218 | {PCC5_RBASE, SEMA42_2_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 219 | {PCC5_RBASE, CMC2_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 220 | {PCC5_RBASE, AVD_SIM_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 221 | {PCC5_RBASE, LPAV_CGC_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 222 | {PCC5_RBASE, PCC5_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 223 | {PCC5_RBASE, TPM8_PCC5_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 224 | {PCC5_RBASE, SAI6_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 225 | {PCC5_RBASE, SAI7_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 226 | {PCC5_RBASE, SPDIF_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 227 | {PCC5_RBASE, ISI_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 228 | {PCC5_RBASE, CSI_REGS_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 229 | {PCC5_RBASE, CSI_PCC5_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 230 | {PCC5_RBASE, DSI_PCC5_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 231 | {PCC5_RBASE, WDOG5_PCC5_SLOT, CLKSRC_PER_BUS, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 232 | {PCC5_RBASE, EPDC_PCC5_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 233 | {PCC5_RBASE, PXP_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 234 | {PCC5_RBASE, SFA2_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 235 | {PCC5_RBASE, GPU2D_PCC5_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 236 | {PCC5_RBASE, GPU3D_PCC5_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 237 | {PCC5_RBASE, DCNANO_PCC5_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_HAS_RST_B }, |
| 238 | {PCC5_RBASE, LPDDR4_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_HAS_RST_B }, |
| 239 | {PCC5_RBASE, CSI_CLK_UI_PCC5_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_NO_RST_B }, |
| 240 | {PCC5_RBASE, CSI_CLK_ESC_PCC5_SLOT, CLKSRC_PER_PLAT, PCC_HAS_DIV, PCC_NO_RST_B }, |
| 241 | {PCC5_RBASE, RGPIOD_PCC5_SLOT, CLKSRC_NO_PCS, PCC_NO_DIV, PCC_NO_RST_B }, |
| 242 | {} |
| 243 | }; |
| 244 | |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 245 | static int find_pcc_entry(int pcc_controller, int pcc_clk_slot, struct pcc_entry **out) |
| 246 | { |
| 247 | struct pcc_entry *pcc_array; |
| 248 | int index = 0; |
| 249 | |
| 250 | switch (pcc_controller) { |
Alice Guo | 23ee0e1 | 2021-10-29 09:46:29 +0800 | [diff] [blame] | 251 | case 1: |
| 252 | pcc_array = pcc1_arrays; |
| 253 | *out = &pcc1_arrays[0]; |
| 254 | break; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 255 | case 3: |
| 256 | pcc_array = pcc3_arrays; |
| 257 | *out = &pcc3_arrays[0]; |
| 258 | break; |
| 259 | case 4: |
| 260 | pcc_array = pcc4_arrays; |
| 261 | *out = &pcc4_arrays[0]; |
| 262 | break; |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 263 | case 5: |
| 264 | pcc_array = pcc5_arrays; |
| 265 | *out = &pcc5_arrays[0]; |
| 266 | break; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 267 | default: |
| 268 | printf("Not supported pcc_controller: %d\n", pcc_controller); |
| 269 | return -EINVAL; |
| 270 | } |
| 271 | |
| 272 | while (pcc_array->pcc_base) { |
| 273 | if (pcc_array->pcc_slot == pcc_clk_slot) |
| 274 | return index; |
| 275 | |
| 276 | pcc_array++; |
| 277 | index++; |
| 278 | } |
| 279 | |
| 280 | return -ENOENT; |
| 281 | } |
| 282 | |
| 283 | int pcc_clock_enable(int pcc_controller, int pcc_clk_slot, bool enable) |
| 284 | { |
| 285 | u32 val; |
| 286 | void __iomem *reg; |
| 287 | int clk; |
| 288 | struct pcc_entry *pcc_array; |
| 289 | |
| 290 | clk = find_pcc_entry(pcc_controller, pcc_clk_slot, &pcc_array); |
| 291 | if (clk < 0) |
| 292 | return -EINVAL; |
| 293 | |
| 294 | reg = (void __iomem *)(uintptr_t)(pcc_array[clk].pcc_base + pcc_array[clk].pcc_slot * 4); |
| 295 | |
| 296 | val = readl(reg); |
| 297 | |
| 298 | debug("%s: clk %d, reg 0x%p, val 0x%x, enable %d\n", __func__, clk, reg, val, enable); |
| 299 | |
| 300 | if (!(val & PCC_PR_MASK) || (val & PCC_INUSE_MASK)) |
| 301 | return -EPERM; |
| 302 | |
| 303 | if (enable) |
| 304 | val |= PCC_CGC_MASK; |
| 305 | else |
| 306 | val &= ~PCC_CGC_MASK; |
| 307 | |
| 308 | writel(val, reg); |
| 309 | |
| 310 | debug("%s: val 0x%x\n", __func__, val); |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | /* The clock source select needs clock is disabled */ |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 316 | int pcc_clock_sel(int pcc_controller, int pcc_clk_slot, enum cgc_clk src) |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 317 | { |
| 318 | u32 val, i, clksrc_type; |
| 319 | void __iomem *reg; |
| 320 | struct pcc_entry *pcc_array; |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 321 | enum cgc_clk *cgc_clk_array; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 322 | int clk; |
| 323 | |
| 324 | clk = find_pcc_entry(pcc_controller, pcc_clk_slot, &pcc_array); |
| 325 | if (clk < 0) |
| 326 | return -EINVAL; |
| 327 | |
| 328 | reg = (void __iomem *)(uintptr_t)(pcc_array[clk].pcc_base + pcc_array[clk].pcc_slot * 4); |
| 329 | |
| 330 | clksrc_type = pcc_array[clk].clksrc; |
| 331 | if (clksrc_type >= CLKSRC_NO_PCS) { |
| 332 | printf("No PCS field for the PCC %d, clksrc type %d\n", |
| 333 | clk, clksrc_type); |
| 334 | return -EPERM; |
| 335 | } |
| 336 | |
Alice Guo | 23ee0e1 | 2021-10-29 09:46:29 +0800 | [diff] [blame] | 337 | if (pcc_controller == 1) |
| 338 | cgc_clk_array = pcc1_clksrc[clksrc_type]; |
| 339 | else if (pcc_controller == 3) |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 340 | cgc_clk_array = pcc3_clksrc[clksrc_type]; |
| 341 | else if (pcc_controller == 4) |
| 342 | cgc_clk_array = pcc4_clksrc[clksrc_type]; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 343 | else |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 344 | cgc_clk_array = pcc5_clksrc[clksrc_type]; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 345 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 346 | for (i = 0; i < cgc_clk_NUM; i++) { |
| 347 | if (cgc_clk_array[i] == src) { |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 348 | /* Find the clock src, then set it to PCS */ |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 353 | if (i == cgc_clk_NUM) { |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 354 | printf("No parent in PCS of PCC %d, invalid scg_clk %d\n", clk, src); |
| 355 | return -EINVAL; |
| 356 | } |
| 357 | |
| 358 | val = readl(reg); |
| 359 | |
| 360 | debug("%s: clk %d, reg 0x%p, val 0x%x, clksrc_type %d\n", |
| 361 | __func__, clk, reg, val, clksrc_type); |
| 362 | |
| 363 | if (!(val & PCC_PR_MASK) || (val & PCC_INUSE_MASK) || |
| 364 | (val & PCC_CGC_MASK)) { |
| 365 | printf("Not permit to select clock source val = 0x%x\n", val); |
| 366 | return -EPERM; |
| 367 | } |
| 368 | |
| 369 | val &= ~PCC_PCS_MASK; |
| 370 | val |= i << PCC_PCS_OFFSET; |
| 371 | |
| 372 | writel(val, reg); |
| 373 | |
| 374 | debug("%s: val 0x%x\n", __func__, val); |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | int pcc_clock_div_config(int pcc_controller, int pcc_clk_slot, bool frac, u8 div) |
| 380 | { |
| 381 | u32 val; |
| 382 | void __iomem *reg; |
| 383 | struct pcc_entry *pcc_array; |
| 384 | int clk; |
| 385 | |
| 386 | clk = find_pcc_entry(pcc_controller, pcc_clk_slot, &pcc_array); |
| 387 | if (clk < 0) |
| 388 | return -EINVAL; |
| 389 | |
| 390 | reg = (void __iomem *)(uintptr_t)(pcc_array[clk].pcc_base + pcc_array[clk].pcc_slot * 4); |
| 391 | |
| 392 | if (div > 8 || (div == 1 && frac != 0)) |
| 393 | return -EINVAL; |
| 394 | |
| 395 | if (pcc_array[clk].div >= PCC_NO_DIV) { |
| 396 | printf("No DIV/FRAC field for the PCC %d\n", clk); |
| 397 | return -EPERM; |
| 398 | } |
| 399 | |
| 400 | val = readl(reg); |
| 401 | |
| 402 | if (!(val & PCC_PR_MASK) || (val & PCC_INUSE_MASK) || |
| 403 | (val & PCC_CGC_MASK)) { |
| 404 | printf("Not permit to set div/frac val = 0x%x\n", val); |
| 405 | return -EPERM; |
| 406 | } |
| 407 | |
| 408 | if (frac) |
| 409 | val |= PCC_FRAC_MASK; |
| 410 | else |
| 411 | val &= ~PCC_FRAC_MASK; |
| 412 | |
| 413 | val &= ~PCC_PCD_MASK; |
| 414 | val |= (div - 1) & PCC_PCD_MASK; |
| 415 | |
| 416 | writel(val, reg); |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | bool pcc_clock_is_enable(int pcc_controller, int pcc_clk_slot) |
| 422 | { |
| 423 | u32 val; |
| 424 | void __iomem *reg; |
| 425 | struct pcc_entry *pcc_array; |
| 426 | int clk; |
| 427 | |
| 428 | clk = find_pcc_entry(pcc_controller, pcc_clk_slot, &pcc_array); |
| 429 | if (clk < 0) |
| 430 | return -EINVAL; |
| 431 | |
| 432 | reg = (void __iomem *)(uintptr_t)(pcc_array[clk].pcc_base + pcc_array[clk].pcc_slot * 4); |
| 433 | val = readl(reg); |
| 434 | |
| 435 | if ((val & PCC_INUSE_MASK) || (val & PCC_CGC_MASK)) |
| 436 | return true; |
| 437 | |
| 438 | return false; |
| 439 | } |
| 440 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 441 | int pcc_clock_get_clksrc(int pcc_controller, int pcc_clk_slot, enum cgc_clk *src) |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 442 | { |
| 443 | u32 val, clksrc_type; |
| 444 | void __iomem *reg; |
| 445 | struct pcc_entry *pcc_array; |
| 446 | int clk; |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 447 | enum cgc_clk *cgc_clk_array; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 448 | |
| 449 | clk = find_pcc_entry(pcc_controller, pcc_clk_slot, &pcc_array); |
| 450 | if (clk < 0) |
| 451 | return -EINVAL; |
| 452 | |
| 453 | clksrc_type = pcc_array[clk].clksrc; |
| 454 | if (clksrc_type >= CLKSRC_NO_PCS) { |
| 455 | printf("No PCS field for the PCC %d, clksrc type %d\n", |
| 456 | pcc_clk_slot, clksrc_type); |
| 457 | return -EPERM; |
| 458 | } |
| 459 | |
| 460 | reg = (void __iomem *)(uintptr_t)(pcc_array[clk].pcc_base + pcc_array[clk].pcc_slot * 4); |
| 461 | |
| 462 | val = readl(reg); |
| 463 | |
| 464 | debug("%s: clk %d, reg 0x%p, val 0x%x, type %d\n", |
| 465 | __func__, pcc_clk_slot, reg, val, clksrc_type); |
| 466 | |
| 467 | if (!(val & PCC_PR_MASK)) { |
| 468 | printf("This pcc slot is not present = 0x%x\n", val); |
| 469 | return -EPERM; |
| 470 | } |
| 471 | |
| 472 | val &= PCC_PCS_MASK; |
| 473 | val = (val >> PCC_PCS_OFFSET); |
| 474 | |
| 475 | if (!val) { |
| 476 | printf("Clock source is off\n"); |
| 477 | return -EIO; |
| 478 | } |
| 479 | |
| 480 | if (pcc_controller == 3) |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 481 | cgc_clk_array = pcc3_clksrc[clksrc_type]; |
| 482 | else if (pcc_controller == 4) |
| 483 | cgc_clk_array = pcc4_clksrc[clksrc_type]; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 484 | else |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 485 | cgc_clk_array = pcc5_clksrc[clksrc_type]; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 486 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 487 | *src = cgc_clk_array[val]; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 488 | |
| 489 | debug("%s: parent cgc1 clk %d\n", __func__, *src); |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | int pcc_reset_peripheral(int pcc_controller, int pcc_clk_slot, bool reset) |
| 495 | { |
| 496 | u32 val; |
| 497 | void __iomem *reg; |
| 498 | struct pcc_entry *pcc_array; |
| 499 | int clk; |
| 500 | |
| 501 | clk = find_pcc_entry(pcc_controller, pcc_clk_slot, &pcc_array); |
| 502 | if (clk < 0) |
| 503 | return -EINVAL; |
| 504 | |
| 505 | if (pcc_array[clk].rst_b == PCC_NO_RST_B) |
| 506 | return 0; |
| 507 | |
| 508 | reg = (void __iomem *)(uintptr_t)(pcc_array[clk].pcc_base + pcc_array[clk].pcc_slot * 4); |
| 509 | |
| 510 | val = readl(reg); |
| 511 | |
| 512 | debug("%s: clk %d, reg 0x%p, val 0x%x\n", __func__, pcc_clk_slot, reg, val); |
| 513 | |
| 514 | if (!(val & PCC_PR_MASK)) { |
| 515 | printf("This pcc slot is not present = 0x%x\n", val); |
| 516 | return -EPERM; |
| 517 | } |
| 518 | |
| 519 | if (reset) |
| 520 | val &= ~BIT(28); |
| 521 | else |
| 522 | val |= BIT(28); |
| 523 | |
| 524 | writel(val, reg); |
| 525 | |
| 526 | debug("%s: clk %d, reg 0x%p, val 0x%x\n", __func__, pcc_clk_slot, reg, val); |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | u32 pcc_clock_get_rate(int pcc_controller, int pcc_clk_slot) |
| 532 | { |
| 533 | u32 val, rate, frac, div; |
| 534 | void __iomem *reg; |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 535 | enum cgc_clk parent; |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 536 | int ret; |
| 537 | int clk; |
| 538 | struct pcc_entry *pcc_array; |
| 539 | |
| 540 | clk = find_pcc_entry(pcc_controller, pcc_clk_slot, &pcc_array); |
| 541 | if (clk < 0) |
| 542 | return -EINVAL; |
| 543 | |
| 544 | ret = pcc_clock_get_clksrc(pcc_controller, pcc_clk_slot, &parent); |
| 545 | if (ret) |
| 546 | return 0; |
| 547 | |
Ye Li | da0469d | 2021-10-29 09:46:18 +0800 | [diff] [blame] | 548 | rate = cgc_clk_get_rate(parent); |
Peng Fan | 690eea1 | 2021-08-07 16:00:45 +0800 | [diff] [blame] | 549 | |
| 550 | debug("%s: parent rate %u\n", __func__, rate); |
| 551 | |
| 552 | if (pcc_array[clk].div == PCC_HAS_DIV) { |
| 553 | reg = (void __iomem *)(uintptr_t)(pcc_array[clk].pcc_base + |
| 554 | pcc_array[clk].pcc_slot * 4); |
| 555 | val = readl(reg); |
| 556 | |
| 557 | frac = (val & PCC_FRAC_MASK) >> PCC_FRAC_OFFSET; |
| 558 | div = (val & PCC_PCD_MASK) >> PCC_PCD_OFFSET; |
| 559 | |
| 560 | /* |
| 561 | * Theoretically don't have overflow in the calc, |
| 562 | * the rate won't exceed 2G |
| 563 | */ |
| 564 | rate = rate * (frac + 1) / (div + 1); |
| 565 | } |
| 566 | |
| 567 | debug("%s: rate %u\n", __func__, rate); |
| 568 | return rate; |
| 569 | } |