Jit Loon Lim | 977071e | 2024-03-12 22:01:03 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (C) 2024 Intel Corporation <www.intel.com> |
| 4 | */ |
| 5 | |
| 6 | #ifndef _CLK_AGILEX5_ |
| 7 | #define _CLK_AGILEX5_ |
| 8 | |
| 9 | #ifndef __ASSEMBLY__ |
| 10 | #include <linux/bitops.h> |
| 11 | #endif |
| 12 | |
| 13 | #define CORE0 1 |
| 14 | #define CORE1 2 |
| 15 | #define CORE2 3 |
| 16 | #define CORE3 4 |
| 17 | |
| 18 | /* Derived from l4_main_clk (PSS clock) */ |
| 19 | #define COUNTER_FREQUENCY_REAL 400000000 |
| 20 | |
| 21 | #define CM_REG_READL(plat, reg) \ |
| 22 | readl((plat)->regs + (reg)) |
| 23 | |
| 24 | #define CM_REG_WRITEL(plat, data, reg) \ |
| 25 | writel(data, (plat)->regs + (reg)) |
| 26 | |
| 27 | #define CM_REG_CLRBITS(plat, reg, clear) \ |
| 28 | clrbits_le32((plat)->regs + (reg), (clear)) |
| 29 | |
| 30 | #define CM_REG_SETBITS(plat, reg, set) \ |
| 31 | setbits_le32((plat)->regs + (reg), (set)) |
| 32 | |
| 33 | struct cm_config { |
| 34 | /* main group */ |
| 35 | u32 main_pll_nocclk; |
| 36 | u32 main_pll_nocdiv; |
| 37 | u32 main_pll_pllglob; |
| 38 | u32 main_pll_fdbck; |
| 39 | u32 main_pll_pllc0; |
| 40 | u32 main_pll_pllc1; |
| 41 | u32 main_pll_pllc2; |
| 42 | u32 main_pll_pllc3; |
| 43 | u32 main_pll_pllm; |
| 44 | |
| 45 | /* peripheral group */ |
| 46 | u32 per_pll_emacctl; |
| 47 | u32 per_pll_gpiodiv; |
| 48 | u32 per_pll_pllglob; |
| 49 | u32 per_pll_fdbck; |
| 50 | u32 per_pll_pllc0; |
| 51 | u32 per_pll_pllc1; |
| 52 | u32 per_pll_pllc2; |
| 53 | u32 per_pll_pllc3; |
| 54 | u32 per_pll_pllm; |
| 55 | |
| 56 | /* control group */ |
| 57 | u32 ctl_emacactr; |
| 58 | u32 ctl_emacbctr; |
| 59 | u32 ctl_emacptpctr; |
| 60 | u32 ctl_gpiodbctr; |
| 61 | u32 ctl_s2fuser0ctr; |
| 62 | u32 ctl_s2fuser1ctr; |
| 63 | u32 ctl_psirefctr; |
| 64 | u32 ctl_usb31ctr; |
| 65 | u32 ctl_dsuctr; |
| 66 | u32 ctl_core01ctr; |
| 67 | u32 ctl_core23ctr; |
| 68 | u32 ctl_core2ctr; |
| 69 | u32 ctl_core3ctr; |
| 70 | |
| 71 | /* incoming clock */ |
| 72 | u32 hps_osc_clk_hz; |
| 73 | u32 fpga_clk_hz; |
| 74 | u32 spare[3]; |
| 75 | }; |
| 76 | |
| 77 | /* Clock Manager registers */ |
| 78 | #define CLKMGR_CTRL 0 |
| 79 | #define CLKMGR_STAT 4 |
| 80 | #define CLKMGR_TESTIOCTRL 8 |
| 81 | #define CLKMGR_INTRGEN 0x0c |
| 82 | #define CLKMGR_INTRMSK 0x10 |
| 83 | #define CLKMGR_INTRCLR 0x14 |
| 84 | #define CLKMGR_INTRSTS 0x18 |
| 85 | #define CLKMGR_INTRSTK 0x1c |
| 86 | #define CLKMGR_INTRRAW 0x20 |
| 87 | |
| 88 | /* Clock Manager Main PPL group registers */ |
| 89 | #define CLKMGR_MAINPLL_EN 0x24 |
| 90 | #define CLKMGR_MAINPLL_ENS 0x28 |
| 91 | #define CLKMGR_MAINPLL_ENR 0x2c |
| 92 | #define CLKMGR_MAINPLL_BYPASS 0x30 |
| 93 | #define CLKMGR_MAINPLL_BYPASSS 0x34 |
| 94 | #define CLKMGR_MAINPLL_BYPASSR 0x38 |
| 95 | #define CLKMGR_MAINPLL_NOCCLK 0x40 |
| 96 | #define CLKMGR_MAINPLL_NOCDIV 0x44 |
| 97 | #define CLKMGR_MAINPLL_PLLGLOB 0x48 |
| 98 | #define CLKMGR_MAINPLL_FDBCK 0x4c |
| 99 | #define CLKMGR_MAINPLL_MEM 0x50 |
| 100 | #define CLKMGR_MAINPLL_MEMSTAT 0x54 |
| 101 | #define CLKMGR_MAINPLL_VCOCALIB 0x58 |
| 102 | #define CLKMGR_MAINPLL_PLLC0 0x5c |
| 103 | #define CLKMGR_MAINPLL_PLLC1 0x60 |
| 104 | #define CLKMGR_MAINPLL_PLLC2 0x64 |
| 105 | #define CLKMGR_MAINPLL_PLLC3 0x68 |
| 106 | #define CLKMGR_MAINPLL_PLLM 0x6c |
| 107 | #define CLKMGR_MAINPLL_FHOP 0x70 |
| 108 | #define CLKMGR_MAINPLL_SSC 0x74 |
| 109 | #define CLKMGR_MAINPLL_LOSTLOCK 0x78 |
| 110 | |
| 111 | /* Clock Manager Peripheral PPL group registers */ |
| 112 | #define CLKMGR_PERPLL_EN 0x7c |
| 113 | #define CLKMGR_PERPLL_ENS 0x80 |
| 114 | #define CLKMGR_PERPLL_ENR 0x84 |
| 115 | #define CLKMGR_PERPLL_BYPASS 0x88 |
| 116 | #define CLKMGR_PERPLL_BYPASSS 0x8c |
| 117 | #define CLKMGR_PERPLL_BYPASSR 0x90 |
| 118 | #define CLKMGR_PERPLL_EMACCTL 0x94 |
| 119 | #define CLKMGR_PERPLL_GPIODIV 0x98 |
| 120 | #define CLKMGR_PERPLL_PLLGLOB 0x9c |
| 121 | #define CLKMGR_PERPLL_FDBCK 0xa0 |
| 122 | #define CLKMGR_PERPLL_MEM 0xa4 |
| 123 | #define CLKMGR_PERPLL_MEMSTAT 0xa8 |
| 124 | #define CLKMGR_PERPLL_VCOCALIB 0xac |
| 125 | #define CLKMGR_PERPLL_PLLC0 0xb0 |
| 126 | #define CLKMGR_PERPLL_PLLC1 0xb4 |
| 127 | #define CLKMGR_PERPLL_PLLC2 0xb8 |
| 128 | #define CLKMGR_PERPLL_PLLC3 0xbc |
| 129 | #define CLKMGR_PERPLL_PLLM 0xc0 |
| 130 | #define CLKMGR_PERPLL_FHOP 0xc4 |
| 131 | #define CLKMGR_PERPLL_SSC 0xc8 |
| 132 | #define CLKMGR_PERPLL_LOSTLOCK 0xcc |
| 133 | |
| 134 | /* Clock Manager Control group registers */ |
| 135 | #define CLKMGR_CTL_JTAG 0xd0 |
| 136 | #define CLKMGR_CTL_EMACACTR 0xd4 |
| 137 | #define CLKMGR_CTL_EMACBCTR 0xd8 |
| 138 | #define CLKMGR_CTL_EMACPTPCTR 0xdc |
| 139 | #define CLKMGR_CTL_GPIODBCTR 0xe0 |
| 140 | #define CLKMGR_CTL_S2FUSER0CTR 0xe8 |
| 141 | #define CLKMGR_CTL_S2FUSER1CTR 0xec |
| 142 | #define CLKMGR_CTL_PSIREFCTR 0xf0 |
| 143 | #define CLKMGR_CTL_EXTCNTRST 0xf4 |
| 144 | #define CLKMGR_CTL_USB31CTR 0xf8 |
| 145 | #define CLKMGR_CTL_DSUCTR 0xfc |
| 146 | #define CLKMGR_CTL_CORE01CTR 0x100 |
| 147 | #define CLKMGR_CTL_CORE23CTR 0x104 |
| 148 | #define CLKMGR_CTL_CORE2CTR 0x108 |
| 149 | #define CLKMGR_CTL_CORE3CTR 0x10C |
| 150 | |
| 151 | #define CLKMGR_CTRL_BOOTMODE BIT(0) |
| 152 | |
| 153 | #define CLKMGR_STAT_BUSY BIT(0) |
| 154 | #define CLKMGR_STAT_MAINPLL_LOCKED BIT(8) |
| 155 | #define CLKMGR_STAT_MAIN_TRANS BIT(9) |
| 156 | #define CLKMGR_STAT_PERPLL_LOCKED BIT(16) |
| 157 | #define CLKMGR_STAT_PERF_TRANS BIT(17) |
| 158 | #define CLKMGR_STAT_BOOTMODE BIT(24) |
| 159 | #define CLKMGR_STAT_BOOTCLKSRC BIT(25) |
| 160 | |
| 161 | #define CLKMGR_STAT_ALLPLL_LOCKED_MASK \ |
| 162 | (CLKMGR_STAT_MAINPLL_LOCKED | CLKMGR_STAT_PERPLL_LOCKED) |
| 163 | |
| 164 | #define CLKMGR_INTER_MAINPLLLOCKED_MASK 0x00000001 |
| 165 | #define CLKMGR_INTER_PERPLLLOCKED_MASK 0x00000002 |
| 166 | #define CLKMGR_INTER_MAINPLLLOST_MASK 0x00000004 |
| 167 | #define CLKMGR_INTER_PERPLLLOST_MASK 0x00000008 |
| 168 | |
| 169 | #define CLKMGR_CLKSRC_MASK GENMASK(18, 16) |
| 170 | #define CLKMGR_CLKSRC_OFFSET 16 |
| 171 | #define CLKMGR_CLKSRC_MAIN 0 |
| 172 | #define CLKMGR_CLKSRC_PER 1 |
| 173 | #define CLKMGR_CLKSRC_OSC1 2 |
| 174 | #define CLKMGR_CLKSRC_INTOSC 3 |
| 175 | #define CLKMGR_CLKSRC_FPGA 4 |
| 176 | #define CLKMGR_CLKCNT_MSK GENMASK(10, 0) |
| 177 | |
| 178 | #define CLKMGR_BYPASS_MAINPLL_ALL 0xf6 |
| 179 | #define CLKMGR_BYPASS_PERPLL_ALL 0xef |
| 180 | |
| 181 | #define CLKMGR_NOCDIV_SOFTPHY_DIV_ONE 0 |
| 182 | #define CLKMGR_NOCDIV_SOFTPHY_DIV_TWO 1 |
| 183 | #define CLKMGR_NOCDIV_SOFTPHY_DIV_FOUR 2 |
| 184 | #define CLKMGR_NOCDIV_L4SYSFREECLK_OFFSET 0 |
| 185 | #define CLKMGR_NOCDIV_L4MPCLK_OFFSET 4 |
| 186 | #define CLKMGR_NOCDIV_L4SPCLK_OFFSET 6 |
| 187 | #define CLKMGR_NOCDIV_SOFTPHY_OFFSET 16 |
| 188 | #define CLKMGR_NOCDIV_CCU_OFFSET 18 |
| 189 | #define CLKMGR_NOCDIV_MPUPERIPH_OFFSET 20 |
| 190 | #define CLKMGR_NOCDIV_CSATCLK_OFFSET 24 |
| 191 | #define CLKMGR_NOCDIV_CSTRACECLK_OFFSET 26 |
| 192 | #define CLKMGR_NOCDIV_CSPDBGCLK_OFFSET 28 |
| 193 | #define CLKMGR_NOCDIV_DIVIDER_MASK 0x3 |
| 194 | |
| 195 | #define CLKMGR_PLLGLOB_PD_MASK BIT(0) |
| 196 | #define CLKMGR_PLLGLOB_RST_MASK BIT(1) |
| 197 | #define CLKMGR_PLLGLOB_AREFCLKDIV_MASK GENMASK(11, 8) |
| 198 | #define CLKMGR_PLLGLOB_DREFCLKDIV_MASK GENMASK(13, 12) |
| 199 | #define CLKMGR_PLLGLOB_REFCLKDIV_MASK GENMASK(13, 8) |
| 200 | #define CLKMGR_PLLGLOB_MODCLKDIV_MASK GENMASK(24, 27) |
| 201 | #define CLKMGR_PLLGLOB_AREFCLKDIV_OFFSET 8 |
| 202 | #define CLKMGR_PLLGLOB_DREFCLKDIV_OFFSET 12 |
| 203 | #define CLKMGR_PLLGLOB_REFCLKDIV_OFFSET 8 |
| 204 | #define CLKMGR_PLLGLOB_MODCLKDIV_OFFSET 24 |
| 205 | #define CLKMGR_PLLGLOB_VCO_PSRC_MASK GENMASK(17, 16) |
| 206 | #define CLKMGR_PLLGLOB_VCO_PSRC_OFFSET 16 |
| 207 | #define CLKMGR_PLLGLOB_CLR_LOSTLOCK_BYPASS_MASK BIT(29) |
| 208 | |
| 209 | #define CLKMGR_VCO_PSRC_EOSC1 0 |
| 210 | #define CLKMGR_VCO_PSRC_INTOSC 1 |
| 211 | #define CLKMGR_VCO_PSRC_F2S 2 |
| 212 | |
| 213 | #define CLKMGR_MEM_REQ_SET_MSK BIT(24) |
| 214 | #define CLKMGR_MEM_WR_SET_MSK BIT(25) |
| 215 | #define CLKMGR_MEM_ERR_MSK BIT(26) |
| 216 | #define CLKMGR_MEM_WDAT_LSB_OFFSET 16 |
| 217 | #define CLKMGR_MEM_ADDR_MASK GENMASK(15, 0) |
| 218 | #define CLKMGR_MEM_ADDR_START 0x00004000 |
| 219 | |
| 220 | #define CLKMGR_PLLCX_EN_SET_MSK BIT(27) |
| 221 | #define CLKMGR_PLLCX_MUTE_SET_MSK BIT(28) |
| 222 | |
| 223 | #define CLKMGR_VCOCALIB_MSCNT_MASK GENMASK(23, 16) |
| 224 | #define CLKMGR_VCOCALIB_MSCNT_OFFSET 16 |
| 225 | #define CLKMGR_VCOCALIB_HSCNT_MASK GENMASK(9, 0) |
| 226 | #define CLKMGR_VCOCALIB_MSCNT_CONST 100 |
| 227 | #define CLKMGR_VCOCALIB_HSCNT_CONST 4 |
| 228 | |
| 229 | #define CLKMGR_PLLM_MDIV_MASK GENMASK(9, 0) |
| 230 | |
| 231 | #define CLKMGR_LOSTLOCK_SET_MASK BIT(0) |
| 232 | |
| 233 | #define CLKMGR_PERPLLGRP_EN_SDMMCCLK_MASK BIT(5) |
| 234 | #define CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_OFFSET 26 |
| 235 | #define CLKMGR_PERPLLGRP_EMACCTL_EMAC0SELB_MASK BIT(26) |
| 236 | #define CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_OFFSET 27 |
| 237 | #define CLKMGR_PERPLLGRP_EMACCTL_EMAC1SELB_MASK BIT(27) |
| 238 | #define CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_OFFSET 28 |
| 239 | #define CLKMGR_PERPLLGRP_EMACCTL_EMAC2SELB_MASK BIT(28) |
| 240 | |
| 241 | #define CLKMGR_CTL_EMACCTR_SRC_OFFSET 16 |
| 242 | #define CLKMGR_CTL_EMACCTR_SRC_MASK GENMASK(18, 16) |
| 243 | #define CLKMGR_CTL_EMACCTR_CNT_OFFSET 0 |
| 244 | #define CLKMGR_CTL_EMACCTR_CNT_MASK GENMASK(10, 0) |
| 245 | |
| 246 | #define CLKMGR_CTL_EXTCNTRST_EMACACNTRST BIT(0) |
| 247 | #define CLKMGR_CTL_EXTCNTRST_EMACBCNTRST BIT(1) |
| 248 | #define CLKMGR_CTL_EXTCNTRST_EMACPTPCNTRST BIT(2) |
| 249 | #define CLKMGR_CTL_EXTCNTRST_GPIODBCNTRST BIT(3) |
| 250 | #define CLKMGR_CTL_EXTCNTRST_S2FUSER0CNTRST BIT(5) |
| 251 | #define CLKMGR_CTL_EXTCNTRST_S2FUSER1CNTRST BIT(6) |
| 252 | #define CLKMGR_CTL_EXTCNTRST_PSIREFCNTRST BIT(7) |
| 253 | #define CLKMGR_CTL_EXTCNTRST_USB31REFCNTRST BIT(8) |
| 254 | #define CLKMGR_CTL_EXTCNTRST_DSUCNTRST BIT(10) |
| 255 | #define CLKMGR_CTL_EXTCNTRST_CORE01CNTRST BIT(11) |
| 256 | #define CLKMGR_CTL_EXTCNTRST_CORE2CNTRST BIT(12) |
| 257 | #define CLKMGR_CTL_EXTCNTRST_CORE3CNTRST BIT(13) |
| 258 | #define CLKMGR_CTL_EXTCNTRST_ALLCNTRST \ |
| 259 | (CLKMGR_CTL_EXTCNTRST_EMACACNTRST | \ |
| 260 | CLKMGR_CTL_EXTCNTRST_EMACBCNTRST | \ |
| 261 | CLKMGR_CTL_EXTCNTRST_EMACPTPCNTRST | \ |
| 262 | CLKMGR_CTL_EXTCNTRST_GPIODBCNTRST | \ |
| 263 | CLKMGR_CTL_EXTCNTRST_S2FUSER0CNTRST | \ |
| 264 | CLKMGR_CTL_EXTCNTRST_S2FUSER1CNTRST | \ |
| 265 | CLKMGR_CTL_EXTCNTRST_PSIREFCNTRST | \ |
| 266 | CLKMGR_CTL_EXTCNTRST_USB31REFCNTRST | \ |
| 267 | CLKMGR_CTL_EXTCNTRST_DSUCNTRST | \ |
| 268 | CLKMGR_CTL_EXTCNTRST_CORE01CNTRST | \ |
| 269 | CLKMGR_CTL_EXTCNTRST_CORE2CNTRST | \ |
| 270 | CLKMGR_CTL_EXTCNTRST_CORE3CNTRST) |
| 271 | |
| 272 | #define MEMBUS_MAINPLL 0 |
| 273 | #define MEMBUS_PERPLL 1 |
| 274 | #define MEMBUS_TIMEOUT 1000 |
| 275 | |
| 276 | #define MEMBUS_CLKSLICE_REG 0x27 |
| 277 | #define MEMBUS_SYNTHCALFOSC_INIT_CENTERFREQ_REG 0xb3 |
| 278 | #define MEMBUS_SYNTHPPM_WATCHDOGTMR_VF01_REG 0xe6 |
| 279 | #define MEMBUS_CALCLKSLICE0_DUTY_LOCOVR_REG 0x03 |
| 280 | #define MEMBUS_CALCLKSLICE1_DUTY_LOCOVR_REG 0x07 |
| 281 | |
| 282 | #define MPIDR_AFF1_OFFSET 8 |
| 283 | #define MPIDR_AFF1_MASK 0x3 |
| 284 | #endif /* _CLK_AGILEX5_ */ |