11fa996adSIan Lepore.\" 21fa996adSIan Lepore.\" Copyright (c) 2018 Ian Lepore <ian@freebsd.org> 31fa996adSIan Lepore.\" All rights reserved. 41fa996adSIan Lepore.\" 51fa996adSIan Lepore.\" Redistribution and use in source and binary forms, with or without 61fa996adSIan Lepore.\" modification, are permitted provided that the following conditions 71fa996adSIan Lepore.\" are met: 81fa996adSIan Lepore.\" 91fa996adSIan Lepore.\" 1. Redistributions of source code must retain the above copyright 101fa996adSIan Lepore.\" notice, this list of conditions and the following disclaimer. 111fa996adSIan Lepore.\" 2. Redistributions in binary form must reproduce the above copyright 121fa996adSIan Lepore.\" notice, this list of conditions and the following disclaimer in the 131fa996adSIan Lepore.\" documentation and/or other materials provided with the distribution. 141fa996adSIan Lepore.\" 151fa996adSIan Lepore.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 161fa996adSIan Lepore.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 171fa996adSIan Lepore.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 181fa996adSIan Lepore.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 191fa996adSIan Lepore.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 201fa996adSIan Lepore.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 211fa996adSIan Lepore.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 221fa996adSIan Lepore.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 231fa996adSIan Lepore.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 241fa996adSIan Lepore.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 251fa996adSIan Lepore.\" 261fa996adSIan Lepore.\" $FreeBSD$ 271fa996adSIan Lepore.\" 28*e378129eSMateusz Piotrowski.Dd August 21, 2020 291fa996adSIan Lepore.Dt SPIGEN 4 301fa996adSIan Lepore.Os 311fa996adSIan Lepore.Sh NAME 321fa996adSIan Lepore.Nm spigen 331fa996adSIan Lepore.Nd SPI generic I/O device driver 341fa996adSIan Lepore.Sh SYNOPSIS 351fa996adSIan LeporeTo compile this driver into the kernel, 361fa996adSIan Leporeplace the following lines in your 371fa996adSIan Leporekernel configuration file: 381fa996adSIan Lepore.Bd -ragged -offset indent 391fa996adSIan Lepore.Cd "device spi" 401fa996adSIan Lepore.Cd "device spibus" 411fa996adSIan Lepore.Cd "device spigen" 421fa996adSIan Lepore.Ed 431fa996adSIan Lepore.Pp 441fa996adSIan LeporeAlternatively, to load the driver as a 451fa996adSIan Leporemodule at boot time, place the following line in 461fa996adSIan Lepore.Xr loader.conf 5 : 471fa996adSIan Lepore.Bd -literal -offset indent 481fa996adSIan Leporespigen_load="YES" 491fa996adSIan Lepore.Ed 501fa996adSIan Lepore.Sh DESCRIPTION 511fa996adSIan LeporeThe 521fa996adSIan Lepore.Nm 531fa996adSIan Leporedriver provides direct access to a slave device on the SPI bus. 541fa996adSIan LeporeEach instance of a 551fa996adSIan Lepore.Nm 561fa996adSIan Leporedevice is associated with a single chip-select 571fa996adSIan Leporeline on the bus, and all I/O performed through that instance is done 581fa996adSIan Leporewith that chip-select line asserted. 591fa996adSIan Lepore.Pp 601fa996adSIan LeporeSPI data transfers are inherently bi-directional; there are not separate 611fa996adSIan Leporeread and write operations. 621fa996adSIan LeporeWhen commands and data are sent to a device, data also comes back from 631fa996adSIan Leporethe device, although in some cases the data may not be useful (or even 641fa996adSIan Leporedocumented or predictable for some devices). 651fa996adSIan LeporeLikewise on a read operation, whatever data is in the buffer at the start 661fa996adSIan Leporeof the operation is sent to (and typically ignored by) the device, with each 671fa996adSIan Leporeoutgoing byte then replaced in the buffer by the corresponding incoming byte. 681fa996adSIan LeporeThus, all buffers passed to the transfer functions are both input and 691fa996adSIan Leporeoutput buffers. 701fa996adSIan Lepore.Pp 711fa996adSIan LeporeThe 721fa996adSIan Lepore.Nm 731fa996adSIan Leporedriver provides access to the SPI slave device with the following 741fa996adSIan Lepore.Xr ioctl 2 751fa996adSIan Leporecalls, defined in 761fa996adSIan Lepore.In sys/spigenio.h : 771fa996adSIan Lepore.Bl -tag -width indent 781fa996adSIan Lepore.It Dv SPIGENIOC_TRANSFER Pq Vt "struct spigen_transfer" 791fa996adSIan LeporeTransfer a command and optional associated data to/from the device, 801fa996adSIan Leporeusing the buffers described by the st_command and st_data fields in the 811fa996adSIan Lepore.Vt spigen_transfer . 821fa996adSIan LeporeSet 831fa996adSIan Lepore.Vt st_data.iov_len 841fa996adSIan Leporeto zero if there is no data associated with the command. 851fa996adSIan Lepore.Bd -literal 861fa996adSIan Leporestruct spigen_transfer { 871fa996adSIan Lepore struct iovec st_command; 881fa996adSIan Lepore struct iovec st_data; 891fa996adSIan Lepore}; 901fa996adSIan Lepore.Ed 911fa996adSIan Lepore.It Dv SPIGENIOC_TRANSFER_MMAPPED Pq Vt "spigen_transfer_mmapped" 921fa996adSIan LeporeTransfer a command and optional associated data to/from the device. 931fa996adSIan LeporeThe buffers for the transfer are a previously-mmap'd region. 941fa996adSIan LeporeThe length of the command and data within that region are described by the 951fa996adSIan Lepore.Vt stm_command_length 961fa996adSIan Leporeand 971fa996adSIan Lepore.Vt stm_data_length 981fa996adSIan Leporefields of 991fa996adSIan Lepore.Vt spigen_transfer_mmapped . 1001fa996adSIan LeporeIf 1011fa996adSIan Lepore.Vt stm_data_length 1021fa996adSIan Leporeis non-zero, the data appears in the memory region immediately 1031fa996adSIan Leporefollowing the command (that is, at offset 1041fa996adSIan Lepore.Vt stm_command_length 1051fa996adSIan Leporefrom the start of the mapped region). 1061fa996adSIan Lepore.Bd -literal 1071fa996adSIan Leporestruct spigen_transfer_mmapped { 1081fa996adSIan Lepore size_t stm_command_length; 1091fa996adSIan Lepore size_t stm_data_length; 1101fa996adSIan Lepore}; 1111fa996adSIan Lepore.Ed 1121fa996adSIan Lepore.It Dv SPIGENIOC_GET_CLOCK_SPEED Pq Vt uint32_t 1131fa996adSIan LeporeGet the maximum clock speed (bus frequency in Hertz) to be used 1141fa996adSIan Leporewhen communicating with this slave device. 1151fa996adSIan Lepore.It Dv SPIGENIOC_SET_CLOCK_SPEED Pq Vt uint32_t 1161fa996adSIan LeporeSet the maximum clock speed (bus frequency in Hertz) to be used 1171fa996adSIan Leporewhen communicating with this slave device. 1181fa996adSIan LeporeThe setting remains in effect for subsequent transfers; it 1191fa996adSIan Leporeis not necessary to reset this before each transfer. 1201fa996adSIan LeporeThe actual bus frequency may be lower due to hardware limitiations 1211fa996adSIan Leporeof the SPI bus controller device. 1221fa996adSIan Lepore.It Dv SPIGENIOC_GET_SPI_MODE Pq Vt uint32_t 1231fa996adSIan LeporeGet the SPI mode (clock polarity and phase) to be used 1241fa996adSIan Leporewhen communicating with this device. 1251fa996adSIan Lepore.It Dv SPIGENIOC_SET_SPI_MODE Pq Vt uint32_t 1261fa996adSIan LeporeSet the SPI mode (clock polarity and phase) to be used 1271fa996adSIan Leporewhen communicating with this device. 1281fa996adSIan LeporeThe setting remains in effect for subsequent transfers; it 1291fa996adSIan Leporeis not necessary to reset this before each transfer. 1301fa996adSIan Lepore.El 1311fa996adSIan Lepore.Sh HINTS CONFIGURATION 1321fa996adSIan LeporeOn a 1331fa996adSIan Lepore.Xr device.hints 5 1341fa996adSIan Leporebased system, such as 1351fa996adSIan Lepore.Li MIPS , 1361fa996adSIan Leporethese values are configurable for 1371fa996adSIan Lepore.Nm : 1381fa996adSIan Lepore.Bl -tag -width indent 1391fa996adSIan Lepore.It Va hint.spigen.%d.at 1401fa996adSIan LeporeThe spibus the 1411fa996adSIan Lepore.Nm 1421fa996adSIan Leporeinstance is attached to. 1431fa996adSIan Lepore.It Va hint.spigen.%d.clock 1441fa996adSIan LeporeThe maximum bus frequency to use when communicating with this device. 1451fa996adSIan LeporeActual bus speed may be lower, depending on the capabilities of the SPI 1461fa996adSIan Leporebus controller hardware. 1471fa996adSIan Lepore.It Va hint.spigen.%d.cs 1481fa996adSIan LeporeThe chip-select number to assert when performing I/O for this device. 1491fa996adSIan LeporeSet the high bit (1 << 31) to invert the logic level of the chip select line. 1501fa996adSIan Lepore.It Va hint.spigen.%d.mode 1511fa996adSIan LeporeThe SPI mode (0-3) to use when communicating with this device. 1521fa996adSIan Lepore.El 1531fa996adSIan Lepore.Sh FDT CONFIGURATION 1541fa996adSIan LeporeOn an 1551fa996adSIan Lepore.Xr fdt 4 1561fa996adSIan Leporebased system, the spigen device is defined as a slave device subnode 1571fa996adSIan Leporeof the SPI bus controller node. 1581fa996adSIan LeporeAll properties documented in the 1591fa996adSIan Lepore.Va spibus.txt 1601fa996adSIan Leporebindings document can be used with the 1611fa996adSIan Lepore.Nm 1621fa996adSIan Leporedevice. 1631fa996adSIan LeporeThe most commonly-used ones are documented below. 1641fa996adSIan Lepore.Pp 1651fa996adSIan LeporeThe following properties are required in the 1661fa996adSIan Lepore.Nm 1671fa996adSIan Leporedevice subnode: 1681fa996adSIan Lepore.Bl -tag -width indent 1691fa996adSIan Lepore.It Va compatible 1701fa996adSIan LeporeMust be the string "freebsd,spigen". 1711fa996adSIan Lepore.It Va reg 1721fa996adSIan LeporeChip select address of device. 1731fa996adSIan Lepore.It Va spi-max-frequency 1741fa996adSIan LeporeThe maximum bus frequency to use when communicating with this slave device. 1751fa996adSIan LeporeActual bus speed may be lower, depending on the capabilities of the SPI 1761fa996adSIan Leporebus controller hardware. 1771fa996adSIan Lepore.El 1781fa996adSIan Lepore.Pp 1791fa996adSIan LeporeThe following properties are optional for the 1801fa996adSIan Lepore.Nm 1811fa996adSIan Leporedevice subnode: 1821fa996adSIan Lepore.Bl -tag -width indent 1831fa996adSIan Lepore.It Va spi-cpha 1841fa996adSIan LeporeEmpty property indicating the slave device requires shifted clock 1851fa996adSIan Leporephase (CPHA) mode. 1861fa996adSIan Lepore.It Va spi-cpol 1871fa996adSIan LeporeEmpty property indicating the slave device requires inverse clock 1881fa996adSIan Leporepolarity (CPOL) mode. 1891fa996adSIan Lepore.It Va spi-cs-high 1901fa996adSIan LeporeEmpty property indicating the slave device requires chip select active high. 1911fa996adSIan Lepore.El 1921fa996adSIan Lepore.Sh FILES 1931fa996adSIan Lepore.Bl -tag -width -compact 1941fa996adSIan Lepore.It Pa /dev/spigen* 1951fa996adSIan Lepore.El 1961fa996adSIan Lepore.Sh SEE ALSO 1971fa996adSIan Lepore.Xr fdt 4 , 198*e378129eSMateusz Piotrowski.Xr device.hints 5 , 199*e378129eSMateusz Piotrowski.Xr spi 8 2001fa996adSIan Lepore.Sh HISTORY 2011fa996adSIan LeporeThe 2021fa996adSIan Lepore.Nm 2031fa996adSIan Leporedriver 2041fa996adSIan Leporeappeared in 2051fa996adSIan Lepore.Fx 11.0 . 2061fa996adSIan LeporeFDT support appeared in 2071fa996adSIan Lepore.Fx 11.2 . 208