1 /* 2 * Copyright (c) 2019-2022, Intel Corporation. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef CLOCKMANAGER_H 8 #define CLOCKMANAGER_H 9 10 #include "socfpga_handoff.h" 11 12 /* Clock Manager Registers */ 13 #define CLKMGR_OFFSET 0x10d10000 14 15 #define CLKMGR_CTRL 0x0 16 #define CLKMGR_STAT 0x4 17 #define CLKMGR_TESTIOCTROL 0x8 18 #define CLKMGR_INTRGEN 0xc 19 #define CLKMGR_INTRMSK 0x10 20 #define CLKMGR_INTRCLR 0x14 21 #define CLKMGR_INTRSTS 0x18 22 #define CLKMGR_INTRSTK 0x1c 23 #define CLKMGR_INTRRAW 0x20 24 25 /* Main PLL Group */ 26 #define CLKMGR_MAINPLL 0x10d10024 27 #define CLKMGR_MAINPLL_EN 0x0 28 #define CLKMGR_MAINPLL_ENS 0x4 29 #define CLKMGR_MAINPLL_BYPASS 0xc 30 #define CLKMGR_MAINPLL_BYPASSS 0x10 31 #define CLKMGR_MAINPLL_BYPASSR 0x14 32 #define CLKMGR_MAINPLL_NOCCLK 0x1c 33 #define CLKMGR_MAINPLL_NOCDIV 0x20 34 #define CLKMGR_MAINPLL_PLLGLOB 0x24 35 #define CLKMGR_MAINPLL_FDBCK 0x28 36 #define CLKMGR_MAINPLL_MEM 0x2c 37 #define CLKMGR_MAINPLL_MEMSTAT 0x30 38 #define CLKMGR_MAINPLL_VCOCALIB 0x34 39 #define CLKMGR_MAINPLL_PLLC0 0x38 40 #define CLKMGR_MAINPLL_PLLC1 0x3c 41 #define CLKMGR_MAINPLL_PLLC2 0x40 42 #define CLKMGR_MAINPLL_PLLC3 0x44 43 #define CLKMGR_MAINPLL_PLLM 0x48 44 #define CLKMGR_MAINPLL_FHOP 0x4c 45 #define CLKMGR_MAINPLL_SSC 0x50 46 #define CLKMGR_MAINPLL_LOSTLOCK 0x54 47 48 /* Peripheral PLL Group */ 49 #define CLKMGR_PERPLL 0x10d1007c 50 #define CLKMGR_PERPLL_EN 0x0 51 #define CLKMGR_PERPLL_ENS 0x4 52 #define CLKMGR_PERPLL_BYPASS 0xc 53 #define CLKMGR_PERPLL_EMACCTL 0x18 54 #define CLKMGR_PERPLL_GPIODIV 0x1c 55 #define CLKMGR_PERPLL_PLLGLOB 0x20 56 #define CLKMGR_PERPLL_FDBCK 0x24 57 #define CLKMGR_PERPLL_MEM 0x28 58 #define CLKMGR_PERPLL_MEMSTAT 0x2c 59 #define CLKMGR_PERPLL_PLLC0 0x30 60 #define CLKMGR_PERPLL_PLLC1 0x34 61 #define CLKMGR_PERPLL_VCOCALIB 0x38 62 #define CLKMGR_PERPLL_PLLC2 0x3c 63 #define CLKMGR_PERPLL_PLLC3 0x40 64 #define CLKMGR_PERPLL_PLLM 0x44 65 #define CLKMGR_PERPLL_LOSTLOCK 0x50 66 67 /* Altera Group */ 68 #define CLKMGR_ALTERA 0x10d100d0 69 #define CLKMGR_ALTERA_JTAG 0x0 70 #define CLKMGR_ALTERA_EMACACTR 0x4 71 #define CLKMGR_ALTERA_EMACBCTR 0x8 72 #define CLKMGR_ALTERA_EMACPTPCTR 0xc 73 #define CLKMGR_ALTERA_GPIODBCTR 0x10 74 #define CLKMGR_ALTERA_S2FUSER0CTR 0x18 75 #define CLKMGR_ALTERA_S2FUSER1CTR 0x1c 76 #define CLKMGR_ALTERA_PSIREFCTR 0x20 77 #define CLKMGR_ALTERA_EXTCNTRST 0x24 78 #define CLKMGR_ALTERA_USB31CTR 0x28 79 #define CLKMGR_ALTERA_DSUCTR 0x2c 80 #define CLKMGR_ALTERA_CORE01CTR 0x30 81 #define CLKMGR_ALTERA_CORE23CTR 0x34 82 #define CLKMGR_ALTERA_CORE2CTR 0x38 83 #define CLKMGR_ALTERA_CORE3CTR 0x3c 84 85 /* Membus */ 86 #define CLKMGR_MEM_REQ BIT(24) 87 #define CLKMGR_MEM_WR BIT(25) 88 #define CLKMGR_MEM_ERR BIT(26) 89 #define CLKMGR_MEM_WDAT_OFFSET 16 90 #define CLKMGR_MEM_ADDR 0x4027 91 #define CLKMGR_MEM_WDAT 0x80 92 93 /* Clock Manager Macros */ 94 #define CLKMGR_CTRL_BOOTMODE_SET_MSK 0x00000001 95 #define CLKMGR_STAT_BUSY_E_BUSY 0x1 96 #define CLKMGR_STAT_BUSY(x) (((x) & 0x00000001) >> 0) 97 #define CLKMGR_STAT_MAINPLLLOCKED(x) (((x) & 0x00000100) >> 8) 98 #define CLKMGR_STAT_PERPLLLOCKED(x) (((x) & 0x00010000) >> 16) 99 #define CLKMGR_INTRCLR_MAINLOCKLOST_SET_MSK 0x00000004 100 #define CLKMGR_INTRCLR_PERLOCKLOST_SET_MSK 0x00000008 101 #define CLKMGR_INTOSC_HZ 460000000 102 103 /* Main PLL Macros */ 104 #define CLKMGR_MAINPLL_EN_RESET 0x0000005e 105 #define CLKMGR_MAINPLL_ENS_RESET 0x0000005e 106 107 /* Peripheral PLL Macros */ 108 #define CLKMGR_PERPLL_EN_RESET 0x040007FF 109 #define CLKMGR_PERPLL_ENS_RESET 0x040007FF 110 111 #define CLKMGR_PERPLL_EN_SDMMCCLK BIT(5) 112 #define CLKMGR_PERPLL_GPIODIV_GPIODBCLK_SET(x) (((x) << 0) & 0x0000ffff) 113 114 /* Altera Macros */ 115 #define CLKMGR_ALTERA_EXTCNTRST_RESET 0xff 116 117 /* Shared Macros */ 118 #define CLKMGR_PSRC(x) (((x) & 0x00030000) >> 16) 119 #define CLKMGR_PSRC_MAIN 0 120 #define CLKMGR_PSRC_PER 1 121 122 #define CLKMGR_PLLGLOB_PSRC_EOSC1 0x0 123 #define CLKMGR_PLLGLOB_PSRC_INTOSC 0x1 124 #define CLKMGR_PLLGLOB_PSRC_F2S 0x2 125 126 #define CLKMGR_PLLM_MDIV(x) ((x) & 0x000003ff) 127 #define CLKMGR_PLLGLOB_PD_SET_MSK 0x00000001 128 #define CLKMGR_PLLGLOB_RST_SET_MSK 0x00000002 129 130 #define CLKMGR_PLLGLOB_REFCLKDIV(x) (((x) & 0x00003f00) >> 8) 131 #define CLKMGR_PLLGLOB_AREFCLKDIV(x) (((x) & 0x00000f00) >> 8) 132 #define CLKMGR_PLLGLOB_DREFCLKDIV(x) (((x) & 0x00003000) >> 12) 133 134 #define CLKMGR_VCOCALIB_HSCNT_SET(x) (((x) << 0) & 0x000003ff) 135 #define CLKMGR_VCOCALIB_MSCNT_SET(x) (((x) << 16) & 0x00ff0000) 136 137 #define CLKMGR_CLR_LOSTLOCK_BYPASS 0x20000000 138 139 typedef struct { 140 uint32_t clk_freq_of_eosc1; 141 uint32_t clk_freq_of_f2h_free; 142 uint32_t clk_freq_of_cb_intosc_ls; 143 } CLOCK_SOURCE_CONFIG; 144 145 void config_clkmgr_handoff(handoff *hoff_ptr); 146 uint32_t get_wdt_clk(void); 147 uint32_t get_uart_clk(void); 148 uint32_t get_mmc_clk(void); 149 150 #endif 151