xref: /freebsd/share/man/man4/spigen.4 (revision 1fa996add5cca61a8081a95e7b66e2a4b97afdc4)
1*1fa996adSIan Lepore.\"
2*1fa996adSIan Lepore.\" Copyright (c) 2018 Ian Lepore <ian@freebsd.org>
3*1fa996adSIan Lepore.\" All rights reserved.
4*1fa996adSIan Lepore.\"
5*1fa996adSIan Lepore.\" Redistribution and use in source and binary forms, with or without
6*1fa996adSIan Lepore.\" modification, are permitted provided that the following conditions
7*1fa996adSIan Lepore.\" are met:
8*1fa996adSIan Lepore.\"
9*1fa996adSIan Lepore.\" 1. Redistributions of source code must retain the above copyright
10*1fa996adSIan Lepore.\"    notice, this list of conditions and the following disclaimer.
11*1fa996adSIan Lepore.\" 2. Redistributions in binary form must reproduce the above copyright
12*1fa996adSIan Lepore.\"    notice, this list of conditions and the following disclaimer in the
13*1fa996adSIan Lepore.\"    documentation and/or other materials provided with the distribution.
14*1fa996adSIan Lepore.\"
15*1fa996adSIan Lepore.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*1fa996adSIan Lepore.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*1fa996adSIan Lepore.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*1fa996adSIan Lepore.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*1fa996adSIan Lepore.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*1fa996adSIan Lepore.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*1fa996adSIan Lepore.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*1fa996adSIan Lepore.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*1fa996adSIan Lepore.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*1fa996adSIan Lepore.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*1fa996adSIan Lepore.\"
26*1fa996adSIan Lepore.\" $FreeBSD$
27*1fa996adSIan Lepore.\"
28*1fa996adSIan Lepore.Dd April 7, 2018
29*1fa996adSIan Lepore.Dt SPIGEN 4
30*1fa996adSIan Lepore.Os
31*1fa996adSIan Lepore.Sh NAME
32*1fa996adSIan Lepore.Nm spigen
33*1fa996adSIan Lepore.Nd SPI generic I/O device driver
34*1fa996adSIan Lepore.Sh SYNOPSIS
35*1fa996adSIan LeporeTo compile this driver into the kernel,
36*1fa996adSIan Leporeplace the following lines in your
37*1fa996adSIan Leporekernel configuration file:
38*1fa996adSIan Lepore.Bd -ragged -offset indent
39*1fa996adSIan Lepore.Cd "device spi"
40*1fa996adSIan Lepore.Cd "device spibus"
41*1fa996adSIan Lepore.Cd "device spigen"
42*1fa996adSIan Lepore.Ed
43*1fa996adSIan Lepore.Pp
44*1fa996adSIan LeporeAlternatively, to load the driver as a
45*1fa996adSIan Leporemodule at boot time, place the following line in
46*1fa996adSIan Lepore.Xr loader.conf 5 :
47*1fa996adSIan Lepore.Bd -literal -offset indent
48*1fa996adSIan Leporespigen_load="YES"
49*1fa996adSIan Lepore.Ed
50*1fa996adSIan Lepore.Sh DESCRIPTION
51*1fa996adSIan LeporeThe
52*1fa996adSIan Lepore.Nm
53*1fa996adSIan Leporedriver provides direct access to a slave device on the SPI bus.
54*1fa996adSIan LeporeEach instance of a
55*1fa996adSIan Lepore.Nm
56*1fa996adSIan Leporedevice is associated with a single chip-select
57*1fa996adSIan Leporeline on the bus, and all I/O performed through that instance is done
58*1fa996adSIan Leporewith that chip-select line asserted.
59*1fa996adSIan Lepore.Pp
60*1fa996adSIan LeporeSPI data transfers are inherently bi-directional; there are not separate
61*1fa996adSIan Leporeread and write operations.
62*1fa996adSIan LeporeWhen commands and data are sent to a device, data also comes back from
63*1fa996adSIan Leporethe device, although in some cases the data may not be useful (or even
64*1fa996adSIan Leporedocumented or predictable for some devices).
65*1fa996adSIan LeporeLikewise on a read operation, whatever data is in the buffer at the start
66*1fa996adSIan Leporeof the operation is sent to (and typically ignored by) the device, with each
67*1fa996adSIan Leporeoutgoing byte then replaced in the buffer by the corresponding incoming byte.
68*1fa996adSIan LeporeThus, all buffers passed to the transfer functions are both input and
69*1fa996adSIan Leporeoutput buffers.
70*1fa996adSIan Lepore.Pp
71*1fa996adSIan LeporeThe
72*1fa996adSIan Lepore.Nm
73*1fa996adSIan Leporedriver provides access to the SPI slave device with the following
74*1fa996adSIan Lepore.Xr ioctl 2
75*1fa996adSIan Leporecalls, defined in
76*1fa996adSIan Lepore.In sys/spigenio.h :
77*1fa996adSIan Lepore.Bl -tag -width indent
78*1fa996adSIan Lepore.It Dv SPIGENIOC_TRANSFER Pq Vt "struct spigen_transfer"
79*1fa996adSIan LeporeTransfer a command and optional associated data to/from the device,
80*1fa996adSIan Leporeusing the buffers described by the st_command and st_data fields in the
81*1fa996adSIan Lepore.Vt spigen_transfer .
82*1fa996adSIan LeporeSet
83*1fa996adSIan Lepore.Vt st_data.iov_len
84*1fa996adSIan Leporeto zero if there is no data associated with the command.
85*1fa996adSIan Lepore.Bd -literal
86*1fa996adSIan Leporestruct spigen_transfer {
87*1fa996adSIan Lepore	struct iovec st_command;
88*1fa996adSIan Lepore	struct iovec st_data;
89*1fa996adSIan Lepore};
90*1fa996adSIan Lepore.Ed
91*1fa996adSIan Lepore.It Dv SPIGENIOC_TRANSFER_MMAPPED Pq Vt "spigen_transfer_mmapped"
92*1fa996adSIan LeporeTransfer a command and optional associated data to/from the device.
93*1fa996adSIan LeporeThe buffers for the transfer are a previously-mmap'd region.
94*1fa996adSIan LeporeThe length of the command and data within that region are described by the
95*1fa996adSIan Lepore.Vt stm_command_length
96*1fa996adSIan Leporeand
97*1fa996adSIan Lepore.Vt stm_data_length
98*1fa996adSIan Leporefields of
99*1fa996adSIan Lepore.Vt spigen_transfer_mmapped .
100*1fa996adSIan LeporeIf
101*1fa996adSIan Lepore.Vt stm_data_length
102*1fa996adSIan Leporeis non-zero, the data appears in the memory region immediately
103*1fa996adSIan Leporefollowing the command (that is, at offset
104*1fa996adSIan Lepore.Vt stm_command_length
105*1fa996adSIan Leporefrom the start of the mapped region).
106*1fa996adSIan Lepore.Bd -literal
107*1fa996adSIan Leporestruct spigen_transfer_mmapped {
108*1fa996adSIan Lepore	size_t stm_command_length;
109*1fa996adSIan Lepore	size_t stm_data_length;
110*1fa996adSIan Lepore};
111*1fa996adSIan Lepore.Ed
112*1fa996adSIan Lepore.It Dv SPIGENIOC_GET_CLOCK_SPEED Pq Vt uint32_t
113*1fa996adSIan LeporeGet the maximum clock speed (bus frequency in Hertz) to be used
114*1fa996adSIan Leporewhen communicating with this slave device.
115*1fa996adSIan Lepore.It Dv SPIGENIOC_SET_CLOCK_SPEED Pq Vt uint32_t
116*1fa996adSIan LeporeSet the maximum clock speed (bus frequency in Hertz) to be used
117*1fa996adSIan Leporewhen communicating with this slave device.
118*1fa996adSIan LeporeThe setting remains in effect for subsequent transfers; it
119*1fa996adSIan Leporeis not necessary to reset this before each transfer.
120*1fa996adSIan LeporeThe actual bus frequency may be lower due to hardware limitiations
121*1fa996adSIan Leporeof the SPI bus controller device.
122*1fa996adSIan Lepore.It Dv SPIGENIOC_GET_SPI_MODE Pq Vt uint32_t
123*1fa996adSIan LeporeGet the SPI mode (clock polarity and phase) to be used
124*1fa996adSIan Leporewhen communicating with this device.
125*1fa996adSIan Lepore.It Dv SPIGENIOC_SET_SPI_MODE Pq Vt uint32_t
126*1fa996adSIan LeporeSet the SPI mode (clock polarity and phase) to be used
127*1fa996adSIan Leporewhen communicating with this device.
128*1fa996adSIan LeporeThe setting remains in effect for subsequent transfers; it
129*1fa996adSIan Leporeis not necessary to reset this before each transfer.
130*1fa996adSIan Lepore.El
131*1fa996adSIan Lepore.Sh HINTS CONFIGURATION
132*1fa996adSIan LeporeOn a
133*1fa996adSIan Lepore.Xr device.hints 5
134*1fa996adSIan Leporebased system, such as
135*1fa996adSIan Lepore.Li MIPS ,
136*1fa996adSIan Leporethese values are configurable for
137*1fa996adSIan Lepore.Nm :
138*1fa996adSIan Lepore.Bl -tag -width indent
139*1fa996adSIan Lepore.It Va hint.spigen.%d.at
140*1fa996adSIan LeporeThe spibus the
141*1fa996adSIan Lepore.Nm
142*1fa996adSIan Leporeinstance is attached to.
143*1fa996adSIan Lepore.It Va hint.spigen.%d.clock
144*1fa996adSIan LeporeThe maximum bus frequency to use when communicating with this device.
145*1fa996adSIan LeporeActual bus speed may be lower, depending on the capabilities of the SPI
146*1fa996adSIan Leporebus controller hardware.
147*1fa996adSIan Lepore.It Va hint.spigen.%d.cs
148*1fa996adSIan LeporeThe chip-select number to assert when performing I/O for this device.
149*1fa996adSIan LeporeSet the high bit (1 << 31) to invert the logic level of the chip select line.
150*1fa996adSIan Lepore.It Va hint.spigen.%d.mode
151*1fa996adSIan LeporeThe SPI mode (0-3) to use when communicating with this device.
152*1fa996adSIan Lepore.El
153*1fa996adSIan Lepore.Sh FDT CONFIGURATION
154*1fa996adSIan LeporeOn an
155*1fa996adSIan Lepore.Xr fdt 4
156*1fa996adSIan Leporebased system, the spigen device is defined as a slave device subnode
157*1fa996adSIan Leporeof the SPI bus controller node.
158*1fa996adSIan LeporeAll properties documented in the
159*1fa996adSIan Lepore.Va spibus.txt
160*1fa996adSIan Leporebindings document can be used with the
161*1fa996adSIan Lepore.Nm
162*1fa996adSIan Leporedevice.
163*1fa996adSIan LeporeThe most commonly-used ones are documented below.
164*1fa996adSIan Lepore.Pp
165*1fa996adSIan LeporeThe following properties are required in the
166*1fa996adSIan Lepore.Nm
167*1fa996adSIan Leporedevice subnode:
168*1fa996adSIan Lepore.Bl -tag -width indent
169*1fa996adSIan Lepore.It Va compatible
170*1fa996adSIan LeporeMust be the string "freebsd,spigen".
171*1fa996adSIan Lepore.It Va reg
172*1fa996adSIan LeporeChip select address of device.
173*1fa996adSIan Lepore.It Va spi-max-frequency
174*1fa996adSIan LeporeThe maximum bus frequency to use when communicating with this slave device.
175*1fa996adSIan LeporeActual bus speed may be lower, depending on the capabilities of the SPI
176*1fa996adSIan Leporebus controller hardware.
177*1fa996adSIan Lepore.El
178*1fa996adSIan Lepore.Pp
179*1fa996adSIan LeporeThe following properties are optional for the
180*1fa996adSIan Lepore.Nm
181*1fa996adSIan Leporedevice subnode:
182*1fa996adSIan Lepore.Bl -tag -width indent
183*1fa996adSIan Lepore.It Va spi-cpha
184*1fa996adSIan LeporeEmpty property indicating the slave device requires shifted clock
185*1fa996adSIan Leporephase (CPHA) mode.
186*1fa996adSIan Lepore.It Va spi-cpol
187*1fa996adSIan LeporeEmpty property indicating the slave device requires inverse clock
188*1fa996adSIan Leporepolarity (CPOL) mode.
189*1fa996adSIan Lepore.It Va spi-cs-high
190*1fa996adSIan LeporeEmpty property indicating the slave device requires chip select active high.
191*1fa996adSIan Lepore.El
192*1fa996adSIan Lepore.Sh FILES
193*1fa996adSIan Lepore.Bl -tag -width -compact
194*1fa996adSIan Lepore.It Pa /dev/spigen*
195*1fa996adSIan Lepore.El
196*1fa996adSIan Lepore.Sh SEE ALSO
197*1fa996adSIan Lepore.Xr fdt 4 ,
198*1fa996adSIan Lepore.Xr device.hints 5
199*1fa996adSIan Lepore.Sh HISTORY
200*1fa996adSIan LeporeThe
201*1fa996adSIan Lepore.Nm
202*1fa996adSIan Leporedriver
203*1fa996adSIan Leporeappeared in
204*1fa996adSIan Lepore.Fx 11.0 .
205*1fa996adSIan LeporeFDT support appeared in
206*1fa996adSIan Lepore.Fx 11.2 .
207