Lines Matching +full:switch +full:- +full:freq +full:- +full:select
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
80 uint64_t freq; member
84 #define SFSPI_LOCK(sc) mtx_lock(&(sc)->mtx)
85 #define SFSPI_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
86 #define SFSPI_ASSERT_LOCKED(sc) mtx_assert(&(sc)->mtx, MA_OWNED);
87 #define SFSPI_ASSERT_UNLOCKED(sc) mtx_assert(&(sc)->mtx, MA_NOTOWNED);
91 * From Sifive-Unleashed-FU540-C000-v1.0.pdf page 101.
95 #define SFSPI_REG_CSID 0x10 /* Chip select ID */
96 #define SFSPI_REG_CSDEF 0x14 /* Chip select default */
97 #define SFSPI_REG_CSMODE 0x18 /* Chip select mode */
112 #define SFSPI_CSDEF_ALL ((1 << sc->cs_max)-1)
139 bus_space_read_4((_sc)->bst, (_sc)->bsh, (_reg))
141 bus_space_write_4((_sc)->bst, (_sc)->bsh, (_reg), (_val))
197 txlen -= bytes; in sfspi_xfer_buf()
205 uint32_t freq) in sfspi_setup() argument
213 * -> div = Fin / (2 * Fsck) - 1 in sfspi_setup()
215 sckdiv = (howmany(sc->freq >> 1, freq) - 1) & SFSPI_SCKDIV_MASK; in sfspi_setup()
218 switch (mode) { in sfspi_setup()
256 KASSERT(cmd->tx_cmd_sz == cmd->rx_cmd_sz, in sfspi_transfer()
258 KASSERT(cmd->tx_data_sz == cmd->rx_data_sz, in sfspi_transfer()
266 if (cs > sc->cs_max) { in sfspi_transfer()
267 device_printf(sc->dev, "Invalid chip select %u\n", cs); in sfspi_transfer()
272 device_busy(sc->dev); in sfspi_transfer()
281 if (cmd->tx_cmd_sz > 0) in sfspi_transfer()
282 err = sfspi_xfer_buf(sc, cmd->rx_cmd, cmd->tx_cmd, in sfspi_transfer()
283 cmd->tx_cmd_sz, cmd->rx_cmd_sz); in sfspi_transfer()
284 if (cmd->tx_data_sz > 0 && err == 0) in sfspi_transfer()
285 err = sfspi_xfer_buf(sc, cmd->rx_data, cmd->tx_data, in sfspi_transfer()
286 cmd->tx_data_sz, cmd->rx_data_sz); in sfspi_transfer()
288 /* Deassert chip select. */ in sfspi_transfer()
293 device_unbusy(sc->dev); in sfspi_transfer()
306 sc->dev = dev; in sfspi_attach()
308 mtx_init(&sc->mtx, device_get_nameunit(sc->dev), NULL, MTX_DEF); in sfspi_attach()
310 error = bus_alloc_resources(dev, sfspi_spec, &sc->res); in sfspi_attach()
315 sc->bst = rman_get_bustag(sc->res); in sfspi_attach()
316 sc->bsh = rman_get_bushandle(sc->res); in sfspi_attach()
318 error = clk_get_by_ofw_index(dev, 0, 0, &sc->clk); in sfspi_attach()
323 error = clk_enable(sc->clk); in sfspi_attach()
329 error = clk_get_freq(sc->clk, &sc->freq); in sfspi_attach()
331 device_printf(sc->dev, "Couldn't get frequency: %d\n", error); in sfspi_attach()
336 * From Sifive-Unleashed-FU540-C000-v1.0.pdf page 103: in sfspi_attach()
339 sc->cs_max = SFSPI_READ(sc, SFSPI_REG_CSDEF); in sfspi_attach()
342 * We don't support the direct-mapped flash interface. in sfspi_attach()
348 sc->parent = device_add_child(dev, "spibus", DEVICE_UNIT_ANY); in sfspi_attach()
354 bus_release_resources(dev, sfspi_spec, &sc->res); in sfspi_attach()
355 mtx_destroy(&sc->mtx); in sfspi_attach()