SPIGEN(4)
π¦ NAME π¦
Hey bestie π β this is the SPIGEN(4) page from the Kernel Interfaces Manual, and the main character is spigen, the SPI generic I/O device driver. That's the whole vibe, and yes, we're covering every deet. β¨
πΈ SYNOPSIS πΈ
To compile this driver into the kernel, put these lines in your kernel configuration file:
device spi
device spibus
device spigen
Alternatively, to load the driver as a module at boot time, put this line in loader.conf(5):
spigen_load="YES"
π DESCRIPTION π
The spigen driver provides direct access to a slave device on the SPI bus. Each instance of a spigen device is associated with a single chip-select line on the bus, and all I/O performed through that instance is done with that chip-select line asserted. Slay. β¨
SPI data transfers are inherently bi-directional; there are no separate read and write operations. When commands and data are sent to a device, data also comes back from the device, although in some cases the data may not be useful (or even documented or predictable for some devices). Likewise on a read operation, whatever data is in the buffer at the start of the operation is sent to (and typically ignored by) the device, with each outgoing byte then replaced in the buffer by the corresponding incoming byte. Thus, all buffers passed to the transfer functions are both input and output buffers. π
Bestie, this is the whole plot twist: the buffers are input and output. No cap. π«Ά
The spigen driver provides access to the SPI slave device with the following ioctl(2) calls, defined in <sys/spigenio.h>:
SPIGENIOC_TRANSFER(struct spigen_transfer) β transfer a command and optional associated data to/from the device, using the buffers described by thest_commandandst_datafields in thespigen_transfer. Setst_data.iov_lento zero if there is no data associated with the command.
struct spigen_transfer {
struct iovec st_command;
struct iovec st_data;
};
SPIGENIOC_TRANSFER_MMAPPED(spigen_transfer_mmapped) β transfer a command and optional associated data to/from the device. The buffers for the transfer are a previously-mmap'd region. The length of the command and data within that region are described by thestm_command_lengthandstm_data_lengthfields ofspigen_transfer_mmapped. Ifstm_data_lengthis non-zero, the data appears in the memory region immediately following the command (that is, at offsetstm_command_lengthfrom the start of the mapped region).
struct spigen_transfer_mmapped {
size_t stm_command_length;
size_t stm_data_length;
};
SPIGENIOC_GET_CLOCK_SPEED(uint32_t) β get the maximum clock speed (bus frequency in Hertz) to be used when communicating with this slave device.SPIGENIOC_SET_CLOCK_SPEED(uint32_t) β set the maximum clock speed (bus frequency in Hertz) to be used when communicating with this slave device. The setting remains in effect for subsequent transfers; it is not necessary to reset this before each transfer. The actual bus frequency may be lower due to hardware limitations of the SPI bus controller device.SPIGENIOC_GET_SPI_MODE(uint32_t) β get the SPI mode (clock polarity and phase) to be used when communicating with this device.SPIGENIOC_SET_SPI_MODE(uint32_t) β set the SPI mode (clock polarity and phase) to be used when communicating with this device. The setting remains in effect for subsequent transfers; it is not necessary to reset this before each transfer.
π HINTS CONFIGURATION π
On a device.hints(5) based system, such as MIPS, these values are configurable for spigen:
hint.spigen.%d.atβ thespibusthespigeninstance is attached to.hint.spigen.%d.clockβ the maximum bus frequency to use when communicating with this device. Actual bus speed may be lower, depending on the capabilities of the SPI bus controller hardware.hint.spigen.%d.csβ the chip-select number to assert when performing I/O for this device. Set the high bit (1 << 31) to invert the logic level of the chip select line.hint.spigen.%d.modeβ the SPI mode (0-3) to use when communicating with this device.
π§ FDT CONFIGURATION π§
On an fdt(4) based system, the spigen device is defined as a slave device subnode of the SPI bus controller node. All properties documented in the spibus.txt bindings document can be used with the spigen device. The most commonly-used ones are documented below. π
The following properties are required in the spigen device subnode:
compatibleβ must be the string"freebsd,spigen".regβ chip select address of device.spi-max-frequencyβ the maximum bus frequency to use when communicating with this slave device. Actual bus speed may be lower, depending on the capabilities of the SPI bus controller hardware.
The following properties are optional for the spigen device subnode:
spi-cphaβ empty property indicating the slave device requires shifted clock phase (CPHA) mode.spi-cpolβ empty property indicating the slave device requires inverse clock polarity (CPOL) mode.spi-cs-highβ empty property indicating the slave device requires chip select active high.
π FILES π
/dev/spigen*β that's the path, bestie. β¨
π SEE ALSO π
π HISTORY π
The spigen driver appeared in FreeBSD 11.0. FDT support appeared in FreeBSD 11.2. Iconic. π
Source/version: Debian Β· date: August 21, 2020 Β· page: SPIGEN(4) β that's the footer, bestie, mwah π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2018 Ian Lepore <ian@freebsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms