diff --git a/sys/dev/xilinx/axi_quad_spi.c b/sys/dev/xilinx/axi_quad_spi.c index eba320731659..86b00473fc96 100644 --- a/sys/dev/xilinx/axi_quad_spi.c +++ b/sys/dev/xilinx/axi_quad_spi.c @@ -1,231 +1,250 @@ /*- - * Copyright (c) 2016 Ruslan Bukin + * Copyright (c) 2016-2025 Ruslan Bukin * All rights reserved. * * Portions of this software were developed by SRI International and the * University of Cambridge Computer Laboratory under DARPA/AFRL contract * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. * * Portions of this software were developed by the University of Cambridge * Computer Laboratory as part of the CTSRD Project, with support from the * UK Higher Education Innovation Fund (HEIF). * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Xilinx AXI_QUAD_SPI */ #include #include #include #include #include #include #include #include #include #include #include #include #include "spibus_if.h" #include #include #include #include #include #include #include #define READ4(_sc, _reg) \ bus_space_read_4(_sc->bst, _sc->bsh, _reg) #define WRITE4(_sc, _reg, _val) \ bus_space_write_4(_sc->bst, _sc->bsh, _reg, _val) #define SPI_SRR 0x40 /* Software reset register */ #define SRR_RESET 0x0A /* The only reset value */ #define SPI_CR 0x60 /* Control register */ #define CR_LSB_FIRST (1 << 9) /* LSB first */ #define CR_MASTER_TI (1 << 8) /* Master Transaction Inhibit */ #define CR_MSS (1 << 7) /* Manual Slave Select */ #define CR_RST_RX (1 << 6) /* RX FIFO Reset */ #define CR_RST_TX (1 << 5) /* TX FIFO Reset */ #define CR_CPHA (1 << 4) /* Clock phase */ #define CR_CPOL (1 << 3) /* Clock polarity */ #define CR_MASTER (1 << 2) /* Master (SPI master mode) */ #define CR_SPE (1 << 1) /* SPI system enable */ #define CR_LOOP (1 << 0) /* Local loopback mode */ #define SPI_SR 0x64 /* Status register */ #define SR_TX_FULL (1 << 3) /* Transmit full */ #define SR_TX_EMPTY (1 << 2) /* Transmit empty */ #define SR_RX_FULL (1 << 1) /* Receive full */ #define SR_RX_EMPTY (1 << 0) /* Receive empty */ #define SPI_DTR 0x68 /* Data transmit register */ #define SPI_DRR 0x6C /* Data receive register */ #define SPI_SSR 0x70 /* Slave select register */ #define SPI_TFOR 0x74 /* Transmit FIFO Occupancy Register */ #define SPI_RFOR 0x78 /* Receive FIFO Occupancy Register */ #define SPI_DGIER 0x1C /* Device global interrupt enable register */ #define SPI_IPISR 0x20 /* IP interrupt status register */ #define SPI_IPIER 0x28 /* IP interrupt enable register */ struct spi_softc { struct resource *res[1]; bus_space_tag_t bst; bus_space_handle_t bsh; void *ih; }; +static struct ofw_compat_data compat_data[] = { + { "xlnx,xps-spi-3.2", 1 }, + { "xlnx,xps-spi-2.00.a", 1 }, + { NULL, 0 } +}; + static struct resource_spec spi_spec[] = { { SYS_RES_MEMORY, 0, RF_ACTIVE }, { -1, 0 } }; static int spi_probe(device_t dev) { if (!ofw_bus_status_okay(dev)) return (ENXIO); - if (!ofw_bus_is_compatible(dev, "xlnx,xps-spi-3.2")) + if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) return (ENXIO); device_set_desc(dev, "Xilinx Quad SPI"); return (BUS_PROBE_DEFAULT); } static int spi_attach(device_t dev) { struct spi_softc *sc; uint32_t reg; sc = device_get_softc(dev); if (bus_alloc_resources(dev, spi_spec, sc->res)) { device_printf(dev, "could not allocate resources\n"); return (ENXIO); } /* Memory interface */ sc->bst = rman_get_bustag(sc->res[0]); sc->bsh = rman_get_bushandle(sc->res[0]); /* Reset */ WRITE4(sc, SPI_SRR, SRR_RESET); DELAY(1000); reg = (CR_MASTER | CR_MSS | CR_RST_RX | CR_RST_TX); WRITE4(sc, SPI_CR, reg); WRITE4(sc, SPI_DGIER, 0); /* Disable interrupts */ reg = (CR_MASTER | CR_MSS | CR_SPE); WRITE4(sc, SPI_CR, reg); - device_add_child(dev, "spibus", 0); + device_add_child(dev, "spibus", DEVICE_UNIT_ANY); bus_attach_children(dev); return (0); } static int spi_txrx(struct spi_softc *sc, uint8_t *out_buf, uint8_t *in_buf, int bufsz, int cs) { uint32_t data; uint32_t i; for (i = 0; i < bufsz; i++) { WRITE4(sc, SPI_DTR, out_buf[i]); while(!(READ4(sc, SPI_SR) & SR_TX_EMPTY)) continue; data = READ4(sc, SPI_DRR); if (in_buf) in_buf[i] = (data & 0xff); } return (0); } static int spi_transfer(device_t dev, device_t child, struct spi_command *cmd) { struct spi_softc *sc; uint32_t reg; uint32_t cs; sc = device_get_softc(dev); KASSERT(cmd->tx_cmd_sz == cmd->rx_cmd_sz, ("%s: TX/RX command sizes should be equal", __func__)); KASSERT(cmd->tx_data_sz == cmd->rx_data_sz, ("%s: TX/RX data sizes should be equal", __func__)); /* get the proper chip select */ spibus_get_cs(child, &cs); cs &= ~SPIBUS_CS_HIGH; /* Assert CS */ reg = READ4(sc, SPI_SSR); reg &= ~(1 << cs); WRITE4(sc, SPI_SSR, reg); /* Command */ spi_txrx(sc, cmd->tx_cmd, cmd->rx_cmd, cmd->tx_cmd_sz, cs); /* Data */ spi_txrx(sc, cmd->tx_data, cmd->rx_data, cmd->tx_data_sz, cs); /* Deassert CS */ reg = READ4(sc, SPI_SSR); reg |= (1 << cs); WRITE4(sc, SPI_SSR, reg); return (0); } +static phandle_t +axispi_get_node(device_t bus, device_t dev) +{ + + return (ofw_bus_get_node(bus)); +} + static device_method_t spi_methods[] = { /* Device interface */ DEVMETHOD(device_probe, spi_probe), DEVMETHOD(device_attach, spi_attach), + /* ofw_bus_if */ + DEVMETHOD(ofw_bus_get_node, axispi_get_node), + /* SPI interface */ DEVMETHOD(spibus_transfer, spi_transfer), DEVMETHOD_END }; -static driver_t spi_driver = { - "spi", +static driver_t axispi_driver = { + "axispi", spi_methods, sizeof(struct spi_softc), }; -DRIVER_MODULE(spi, simplebus, spi_driver, 0, 0); +DRIVER_MODULE(axispi, simplebus, axispi_driver, 0, 0); +DRIVER_MODULE(ofw_spibus, axispi, ofw_spibus_driver, 0, 0); +MODULE_DEPEND(axispi, ofw_spibus, 1, 1, 1); +SIMPLEBUS_PNP_INFO(compat_data); diff --git a/sys/riscv/conf/GENERIC b/sys/riscv/conf/GENERIC index 8dca3bdb3369..7d7d0ca6e79c 100644 --- a/sys/riscv/conf/GENERIC +++ b/sys/riscv/conf/GENERIC @@ -1,210 +1,211 @@ # # GENERIC -- Generic kernel configuration file for FreeBSD/RISC-V # # For more information on this file, please read the config(5) manual page, # and/or the handbook section on Kernel Configuration Files: # # https://docs.freebsd.org/en/books/handbook/kernelconfig/#kernelconfig-config # # The handbook is also available locally in /usr/share/doc/handbook # if you've installed the doc distribution, otherwise always see the # FreeBSD World Wide Web server (https://www.FreeBSD.org/) for the # latest information. # # An exhaustive list of options and more detailed explanations of the # device lines is also present in the ../../conf/NOTES and NOTES files. # If you are in doubt as to the purpose or necessity of a line, check first # in NOTES. # cpu RISCV ident GENERIC makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols makeoptions WITH_CTF=1 # Run ctfconvert(1) for DTrace support options SCHED_ULE # ULE scheduler options PREEMPTION # Enable kernel thread preemption options VIMAGE # Subsystem virtualization, e.g. VNET options INET # InterNETworking options INET6 # IPv6 communications protocols options TCP_HHOOK # hhook(9) framework for TCP options IPSEC_SUPPORT # Allow kldload of ipsec and tcpmd5 options ROUTE_MPATH # Multipath routing support options TCP_OFFLOAD # TCP offload options TCP_BLACKBOX # Enhanced TCP event logging options TCP_RFC7413 # TCP Fast Open options SCTP_SUPPORT # Allow kldload of SCTP options FFS # Berkeley Fast Filesystem options SOFTUPDATES # Enable FFS soft updates support options UFS_ACL # Support for access control lists options UFS_DIRHASH # Improve performance on big directories options UFS_GJOURNAL # Enable gjournal-based UFS journaling options QUOTA # Enable disk quotas for UFS options NFSCL # Network Filesystem Client options NFSD # Network Filesystem Server options NFSLOCKD # Network Lock Manager options NFS_ROOT # NFS usable as /, requires NFSCL options MSDOSFS # MSDOS Filesystem options CD9660 # ISO 9660 Filesystem options PROCFS # Process filesystem (requires PSEUDOFS) options PSEUDOFS # Pseudo-filesystem framework options TMPFS # Efficient memory filesystem options GEOM_RAID # Soft RAID functionality. options GEOM_LABEL # Provides labelization options COMPAT_FREEBSD12 # Compatible with FreeBSD12 options COMPAT_FREEBSD13 # Compatible with FreeBSD13 options COMPAT_FREEBSD14 # Compatible with FreeBSD14 options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI options KTRACE # ktrace(1) support options STACK # stack(9) support options SYSVSHM # SYSV-style shared memory options SYSVMSG # SYSV-style message queues options SYSVSEM # SYSV-style semaphores options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions options PRINTF_BUFR_SIZE=128 # Prevent printf output being interspersed. options KBD_INSTALL_CDEV # install a CDEV entry in /dev # options HWPMC_HOOKS # Necessary kernel hooks for hwpmc(4) options AUDIT # Security event auditing options CAPABILITY_MODE # Capsicum capability mode options CAPABILITIES # Capsicum capabilities options MAC # TrustedBSD MAC Framework options KDTRACE_FRAME # Ensure frames are compiled in options KDTRACE_HOOKS # Kernel DTrace hooks options DDB_CTF # Kernel ELF linker loads CTF data options RACCT # Resource accounting framework options RACCT_DEFAULT_TO_DISABLED # Set kern.racct.enable=0 by default options RCTL # Resource limits options SMP # RISC-V SBI console device rcons # pseudo devices device clk device hwreset device nvmem device phy device regulator device syscon device syscon_power device riscv_syscon # CPU frequency control device cpufreq # Bus drivers device pci # Block devices device ahci device scbus device da # VirtIO support device virtio # Generic VirtIO bus (required) device virtio_pci # VirtIO PCI device device vtnet # VirtIO Ethernet device device virtio_blk # VirtIO Block device device virtio_mmio # VirtIO MMIO bus # ATA/SCSI peripherals device pass # Passthrough device (direct ATA/SCSI access) # NVM Express (NVMe) support device nvme # base NVMe driver options NVME_USE_NVD=0 # prefer the cam(4) based nda(4) driver device nvd # expose NVMe namespaces as disks, depends on nvme # USB support options USB_DEBUG # enable debug msgs device ohci # OHCI USB interface device uhci # UHCI USB interface device ehci # EHCI USB interface (USB 2.0) device xhci # XHCI USB interface (USB 3.0) device usb # USB Bus (required) device usbhid # USB HID Transport device hkbd # Keyboard device ukbd # Keyboard device umass # Disks/Mass storage - Requires scbus and da # HID support options HID_DEBUG # enable debug msgs device hid # Generic HID support device hidbus # Generic HID Bus # Serial (COM) ports device uart # Generic UART driver device uart_lowrisc # lowRISC UART driver device uart_ns8250 # ns8250-type UART driver # Console device vt device vt_efifb device kbdmux # RTC device goldfish_rtc # QEMU RTC # Ethernet drivers device miibus # MII bus support device xae # Xilinx AXI Ethernet MAC # DMA support device xdma # DMA interface device axidma # Xilinx AXI DMA Controller # GPIO device gpio device fdt_pinctrl # SPI device spibus device spigen +device xilinx_spi # Xilinx AXI SPI Controller # Debugging support. Always need this: options KDB # Enable kernel debugger support. options KDB_TRACE # Print a stack trace for a panic. # For full debugger support use (turn off in stable branch): include "std.debug" # options EARLY_PRINTF=sbi # Kernel dump features. options EKCD # Support for encrypted kernel dumps options GZIO # gzip-compressed kernel and user dumps options ZSTDIO # zstd-compressed kernel and user dumps options DEBUGNET # debugnet networking options NETDUMP # netdump(4) client support # Pseudo devices. device crypto # core crypto support device loop # Network loopback device ether # Ethernet support device vlan # 802.1Q VLAN support device tuntap # Packet tunnel. device md # Memory "disks" device gif # IPv6 and IPv4 tunneling device firmware # firmware assist module # MMC/SD/SDIO Card slot support device sdhci device mmc # MMC/SD bus device mmcsd # MMC/SD flash cards # The `bpf' device enables the Berkeley Packet Filter. # Be aware of the administrative consequences of enabling this! # Note that 'bpf' is required for DHCP. device bpf # Berkeley packet filter # Flattened Device Tree options FDT # I2C support device iicbus # Bus support, required for iicoc below. device iicoc # OpenCores I2C controller support # Include SoC specific configuration include "std.allwinner" include "std.eswin" include "std.sifive" include "std.starfive"