blob: e0d0f8f81b7cf180c736fbbdc1bbdc3e9e7d3621 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut084d06c2015-07-25 08:44:27 +02002/*
3 * Copyright (C) 2015 Marek Vasut <marex@denx.de>
Marek Vasut084d06c2015-07-25 08:44:27 +02004 */
5
Tom Rinidec7ea02024-05-20 13:35:03 -06006#include <config.h>
Marek Vasut084d06c2015-07-25 08:44:27 +02007#include <asm/arch/clock_manager.h>
Marek Vasutaefb78d2015-08-02 21:12:09 +02008#include <qts/pll_config.h>
Marek Vasut084d06c2015-07-25 08:44:27 +02009
10#define MAIN_VCO_BASE ( \
Tom Rinidcdd3bd2022-10-28 20:27:14 -040011 (CFG_HPS_MAINPLLGRP_VCO_DENOM << \
Marek Vasut084d06c2015-07-25 08:44:27 +020012 CLKMGR_MAINPLLGRP_VCO_DENOM_OFFSET) | \
Tom Rinidcdd3bd2022-10-28 20:27:14 -040013 (CFG_HPS_MAINPLLGRP_VCO_NUMER << \
Marek Vasut084d06c2015-07-25 08:44:27 +020014 CLKMGR_MAINPLLGRP_VCO_NUMER_OFFSET) \
15 )
16
17#define PERI_VCO_BASE ( \
Tom Rinidcdd3bd2022-10-28 20:27:14 -040018 (CFG_HPS_PERPLLGRP_VCO_PSRC << \
Marek Vasut084d06c2015-07-25 08:44:27 +020019 CLKMGR_PERPLLGRP_VCO_PSRC_OFFSET) | \
Tom Rinidcdd3bd2022-10-28 20:27:14 -040020 (CFG_HPS_PERPLLGRP_VCO_DENOM << \
Marek Vasut084d06c2015-07-25 08:44:27 +020021 CLKMGR_PERPLLGRP_VCO_DENOM_OFFSET) | \
Tom Rinidcdd3bd2022-10-28 20:27:14 -040022 (CFG_HPS_PERPLLGRP_VCO_NUMER << \
Marek Vasut084d06c2015-07-25 08:44:27 +020023 CLKMGR_PERPLLGRP_VCO_NUMER_OFFSET) \
24 )
25
26#define SDR_VCO_BASE ( \
Tom Rinidcdd3bd2022-10-28 20:27:14 -040027 (CFG_HPS_SDRPLLGRP_VCO_SSRC << \
Marek Vasut084d06c2015-07-25 08:44:27 +020028 CLKMGR_SDRPLLGRP_VCO_SSRC_OFFSET) | \
Tom Rinidcdd3bd2022-10-28 20:27:14 -040029 (CFG_HPS_SDRPLLGRP_VCO_DENOM << \
Marek Vasut084d06c2015-07-25 08:44:27 +020030 CLKMGR_SDRPLLGRP_VCO_DENOM_OFFSET) | \
Tom Rinidcdd3bd2022-10-28 20:27:14 -040031 (CFG_HPS_SDRPLLGRP_VCO_NUMER << \
Marek Vasut084d06c2015-07-25 08:44:27 +020032 CLKMGR_SDRPLLGRP_VCO_NUMER_OFFSET) \
33 )
34
35static const struct cm_config cm_default_cfg = {
36 /* main group */
37 MAIN_VCO_BASE,
Tom Rinidcdd3bd2022-10-28 20:27:14 -040038 (CFG_HPS_MAINPLLGRP_MPUCLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020039 CLKMGR_MAINPLLGRP_MPUCLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040040 (CFG_HPS_MAINPLLGRP_MAINCLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020041 CLKMGR_MAINPLLGRP_MAINCLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040042 (CFG_HPS_MAINPLLGRP_DBGATCLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020043 CLKMGR_MAINPLLGRP_DBGATCLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040044 (CFG_HPS_MAINPLLGRP_MAINQSPICLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020045 CLKMGR_MAINPLLGRP_MAINQSPICLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040046 (CFG_HPS_MAINPLLGRP_MAINNANDSDMMCCLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020047 CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040048 (CFG_HPS_MAINPLLGRP_CFGS2FUSER0CLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020049 CLKMGR_MAINPLLGRP_CFGS2FUSER0CLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040050 (CFG_HPS_MAINPLLGRP_MAINDIV_L3MPCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020051 CLKMGR_MAINPLLGRP_MAINDIV_L3MPCLK_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040052 (CFG_HPS_MAINPLLGRP_MAINDIV_L3SPCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020053 CLKMGR_MAINPLLGRP_MAINDIV_L3SPCLK_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040054 (CFG_HPS_MAINPLLGRP_MAINDIV_L4MPCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020055 CLKMGR_MAINPLLGRP_MAINDIV_L4MPCLK_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040056 (CFG_HPS_MAINPLLGRP_MAINDIV_L4SPCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020057 CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040058 (CFG_HPS_MAINPLLGRP_DBGDIV_DBGATCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020059 CLKMGR_MAINPLLGRP_DBGDIV_DBGATCLK_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040060 (CFG_HPS_MAINPLLGRP_DBGDIV_DBGCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020061 CLKMGR_MAINPLLGRP_DBGDIV_DBGCLK_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040062 (CFG_HPS_MAINPLLGRP_TRACEDIV_TRACECLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020063 CLKMGR_MAINPLLGRP_TRACEDIV_TRACECLK_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040064 (CFG_HPS_MAINPLLGRP_L4SRC_L4MP <<
Marek Vasut084d06c2015-07-25 08:44:27 +020065 CLKMGR_MAINPLLGRP_L4SRC_L4MP_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040066 (CFG_HPS_MAINPLLGRP_L4SRC_L4SP <<
Marek Vasut084d06c2015-07-25 08:44:27 +020067 CLKMGR_MAINPLLGRP_L4SRC_L4SP_OFFSET),
68
69 /* peripheral group */
70 PERI_VCO_BASE,
Tom Rinidcdd3bd2022-10-28 20:27:14 -040071 (CFG_HPS_PERPLLGRP_EMAC0CLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020072 CLKMGR_PERPLLGRP_EMAC0CLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040073 (CFG_HPS_PERPLLGRP_EMAC1CLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020074 CLKMGR_PERPLLGRP_EMAC1CLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040075 (CFG_HPS_PERPLLGRP_PERQSPICLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020076 CLKMGR_PERPLLGRP_PERQSPICLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040077 (CFG_HPS_PERPLLGRP_PERNANDSDMMCCLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020078 CLKMGR_PERPLLGRP_PERNANDSDMMCCLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040079 (CFG_HPS_PERPLLGRP_PERBASECLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020080 CLKMGR_PERPLLGRP_PERBASECLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040081 (CFG_HPS_PERPLLGRP_S2FUSER1CLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +020082 CLKMGR_PERPLLGRP_S2FUSER1CLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040083 (CFG_HPS_PERPLLGRP_DIV_USBCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020084 CLKMGR_PERPLLGRP_DIV_USBCLK_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040085 (CFG_HPS_PERPLLGRP_DIV_SPIMCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020086 CLKMGR_PERPLLGRP_DIV_SPIMCLK_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040087 (CFG_HPS_PERPLLGRP_DIV_CAN0CLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020088 CLKMGR_PERPLLGRP_DIV_CAN0CLK_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040089 (CFG_HPS_PERPLLGRP_DIV_CAN1CLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020090 CLKMGR_PERPLLGRP_DIV_CAN1CLK_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040091 (CFG_HPS_PERPLLGRP_GPIODIV_GPIODBCLK <<
Marek Vasut084d06c2015-07-25 08:44:27 +020092 CLKMGR_PERPLLGRP_GPIODIV_GPIODBCLK_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -040093 (CFG_HPS_PERPLLGRP_SRC_QSPI <<
Marek Vasut084d06c2015-07-25 08:44:27 +020094 CLKMGR_PERPLLGRP_SRC_QSPI_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040095 (CFG_HPS_PERPLLGRP_SRC_NAND <<
Marek Vasut084d06c2015-07-25 08:44:27 +020096 CLKMGR_PERPLLGRP_SRC_NAND_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -040097 (CFG_HPS_PERPLLGRP_SRC_SDMMC <<
Marek Vasut084d06c2015-07-25 08:44:27 +020098 CLKMGR_PERPLLGRP_SRC_SDMMC_OFFSET),
99
100 /* sdram pll group */
101 SDR_VCO_BASE,
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400102 (CFG_HPS_SDRPLLGRP_DDRDQSCLK_PHASE <<
Marek Vasut084d06c2015-07-25 08:44:27 +0200103 CLKMGR_SDRPLLGRP_DDRDQSCLK_PHASE_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400104 (CFG_HPS_SDRPLLGRP_DDRDQSCLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +0200105 CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400106 (CFG_HPS_SDRPLLGRP_DDR2XDQSCLK_PHASE <<
Marek Vasut084d06c2015-07-25 08:44:27 +0200107 CLKMGR_SDRPLLGRP_DDR2XDQSCLK_PHASE_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400108 (CFG_HPS_SDRPLLGRP_DDR2XDQSCLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +0200109 CLKMGR_SDRPLLGRP_DDR2XDQSCLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400110 (CFG_HPS_SDRPLLGRP_DDRDQCLK_PHASE <<
Marek Vasut084d06c2015-07-25 08:44:27 +0200111 CLKMGR_SDRPLLGRP_DDRDQCLK_PHASE_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400112 (CFG_HPS_SDRPLLGRP_DDRDQCLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +0200113 CLKMGR_SDRPLLGRP_DDRDQCLK_CNT_OFFSET),
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400114 (CFG_HPS_SDRPLLGRP_S2FUSER2CLK_PHASE <<
Marek Vasut084d06c2015-07-25 08:44:27 +0200115 CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_OFFSET) |
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400116 (CFG_HPS_SDRPLLGRP_S2FUSER2CLK_CNT <<
Marek Vasut084d06c2015-07-25 08:44:27 +0200117 CLKMGR_SDRPLLGRP_S2FUSER2CLK_CNT_OFFSET),
Dinh Nguyen2492b9f2017-01-31 12:33:08 -0600118
119 /* altera group */
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400120 CFG_HPS_ALTERAGRP_MPUCLK,
Marek Vasut084d06c2015-07-25 08:44:27 +0200121};
122
123const struct cm_config * const cm_get_default_config(void)
124{
125 return &cm_default_cfg;
126}
127
128const unsigned int cm_get_osc_clk_hz(const int osc)
129{
130 if (osc == 1)
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400131 return CFG_HPS_CLK_OSC1_HZ;
Marek Vasut084d06c2015-07-25 08:44:27 +0200132 else if (osc == 2)
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400133 return CFG_HPS_CLK_OSC2_HZ;
Marek Vasut084d06c2015-07-25 08:44:27 +0200134 else
135 return 0;
136}
137
138const unsigned int cm_get_f2s_per_ref_clk_hz(void)
139{
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400140 return CFG_HPS_CLK_F2S_PER_REF_HZ;
Marek Vasut084d06c2015-07-25 08:44:27 +0200141}
142
143const unsigned int cm_get_f2s_sdr_ref_clk_hz(void)
144{
Tom Rinidcdd3bd2022-10-28 20:27:14 -0400145 return CFG_HPS_CLK_F2S_SDR_REF_HZ;
Marek Vasut084d06c2015-07-25 08:44:27 +0200146}