2018-04-05 04:11:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Jean-Paul Etienne <fractalclone@gmail.com>
|
|
|
|
* Copyright (c) 2017 Palmer Dabbelt <palmer@dabbelt.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <init.h>
|
2019-03-21 01:22:28 +08:00
|
|
|
#include "fe310_prci.h"
|
2018-04-05 04:11:07 +08:00
|
|
|
|
2022-04-01 01:51:54 +08:00
|
|
|
BUILD_ASSERT(MHZ(16) == DT_PROP(DT_NODELABEL(coreclk), clock_frequency),
|
|
|
|
"Unsupported CORECLK frequency");
|
|
|
|
BUILD_ASSERT(DT_PROP(DT_NODELABEL(tlclk), clock_div) == 1,
|
|
|
|
"Unsupported TLCLK divider");
|
|
|
|
|
2022-03-17 05:07:43 +08:00
|
|
|
/* Selects the 16MHz oscillator on the HiFive1 board, which provides a clock
|
2018-04-05 04:11:07 +08:00
|
|
|
* that's accurate enough to actually drive serial ports off of.
|
|
|
|
*/
|
2020-05-01 02:33:38 +08:00
|
|
|
static int fe310_clock_init(const struct device *dev)
|
2018-04-05 04:11:07 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
|
|
|
PRCI_REG(PRCI_PLLCFG) = PLL_REFSEL(1) | PLL_BYPASS(1);
|
|
|
|
PRCI_REG(PRCI_PLLDIV) = (PLL_FINAL_DIV_BY_1(1) | PLL_FINAL_DIV(0));
|
|
|
|
PRCI_REG(PRCI_PLLCFG) |= PLL_SEL(1);
|
|
|
|
PRCI_REG(PRCI_HFROSCCFG) &= ~ROSC_EN(1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:38:57 +08:00
|
|
|
SYS_INIT(fe310_clock_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
|