aboutsummaryrefslogtreecommitdiff
path: root/sys/riscv
diff options
context:
space:
mode:
authorPhilip Paeps <philip@FreeBSD.org>2019-12-29 04:26:10 +0000
committerPhilip Paeps <philip@FreeBSD.org>2019-12-29 04:26:10 +0000
commit2d581b3a7cf522b76d2d403b35bd49cef9c40223 (patch)
tree733b654e6530b026556360f138f79608eee4b095 /sys/riscv
parentd8fa560202a5c4651878855056335d7acf49b056 (diff)
Notes
Diffstat (limited to 'sys/riscv')
-rw-r--r--sys/riscv/sifive/fu540_spi.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/sys/riscv/sifive/fu540_spi.c b/sys/riscv/sifive/fu540_spi.c
index 1c7b3911ebe5..4c13a483b5df 100644
--- a/sys/riscv/sifive/fu540_spi.c
+++ b/sys/riscv/sifive/fu540_spi.c
@@ -80,6 +80,7 @@ struct fuspi_softc {
void *ih;
clk_t clk;
+ uint64_t freq;
uint32_t cs_max;
};
@@ -207,22 +208,14 @@ fuspi_setup(struct fuspi_softc *sc, uint32_t cs, uint32_t mode,
uint32_t freq)
{
uint32_t csmode, fmt, sckdiv, sckmode;
- uint64_t clock;
- int ret;
FUSPI_ASSERT_LOCKED(sc);
- ret = clk_get_freq(sc->clk, &clock);
- if (ret) {
- device_printf(sc->dev, "Cannot get clock frequency: %d\n", ret);
- return (ret);
- }
-
/*
* Fsck = Fin / 2 * (div + 1)
* -> div = Fin / (2 * Fsck) - 1
*/
- sckdiv = (howmany(clock >> 1, freq) - 1) & FUSPI_SCKDIV_MASK;
+ sckdiv = (howmany(sc->freq >> 1, freq) - 1) & FUSPI_SCKDIV_MASK;
FUSPI_WRITE(sc, FUSPI_REG_SCKDIV, sckdiv);
switch (mode) {
@@ -331,6 +324,12 @@ fuspi_attach(device_t dev)
goto fail;
}
+ error = clk_get_freq(sc->clk, &sc->freq);
+ if (error) {
+ device_printf(sc->dev, "Couldn't get frequency: %d\n", error);
+ goto fail;
+ }
+
/*
* From Sifive-Unleashed-FU540-C000-v1.0.pdf page 103:
* csdef is cs_width bits wide and all ones on reset.