blob: cbbba2e9c0e6ce236218b3bf1eda35fc57440628 [file] [log] [blame]
/*
* Copyright (c) 2021 Katsuhiro Suzuki
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <init.h>
#include "fu540_prci.h"
/*
* Switch the clock source to 1GHz PLL from 33.333MHz oscilator on the HiFive
* Unleashed board.
*/
static int fu540_clock_init(const struct device *dev)
{
ARG_UNUSED(dev);
PRCI_REG(PRCI_COREPLLCFG0) =
PLL_R(0) | /* input divider: Fin / (0 + 1) = 33.33MHz */
PLL_F(59) | /* VCO: 2 x (59 + 1) = 120 = 3999.6MHz */
PLL_Q(2) | /* output divider: VCO / 2^2 = 999.9MHz */
PLL_RANGE(PLL_RANGE_33MHZ) |
PLL_BYPASS(PLL_BYPASS_DISABLE) |
PLL_FSE(PLL_FSE_INTERNAL);
while ((PRCI_REG(PRCI_COREPLLCFG0) & PLL_LOCK(1)) == 0)
;
/* Switch clock to COREPLL */
PRCI_REG(PRCI_CORECLKSEL) = CORECLKSEL_CORECLKSEL(CORECLKSEL_CORE_PLL);
return 0;
}
SYS_INIT(fu540_clock_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);