diff options
| -rw-r--r-- | sys/riscv/sifive/fu540_spi.c | 17 |
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. |
