Home | History | Annotate | Download | only in spi
History log of /src/sys/dev/spi/spi.c
RevisionDateAuthorComments
 1.37  21-Sep-2025  thorpej Fix typo in the indirect config case.
 1.36  14-Sep-2025  thorpej In spi_configure() attempt to fetch transfer mode information from the
platform device tree. Implement this for FDT per the SPI controller and
periperal Device Tree bindings.
 1.35  14-Sep-2025  thorpej Make SPI direct configuration less #ifdef'y. No more checking what kind
of platform device tree; instead, use a device call to enumerate the
direct config children of the bus.
 1.34  13-Sep-2025  thorpej Re-factor the logic of attaching child devices to share more between
the direct an indirect cases.
 1.33  13-Sep-2025  thorpej Define and use spi_handle_t to drive home the point that it's an opaque
type.
 1.32  11-Sep-2025  thorpej Introduce spi_use_direct_match() which, like its i2c cousin, informs
the driver if a direct config match is in play, allowing the driver
more easily apply direct vs indirect config match logic.
 1.31  10-Sep-2025  thorpej In the direct config case, use the correct spi_handle for the child
device (index the array using the slave #, not the child_devices array
index).
 1.30  10-Sep-2025  thorpej Don't pass a "cookie" in the attach args to SPI devices. Instead,
properly initialize the child device's device handle. G/C unused
fields in spi_attach_args.
 1.29  10-Sep-2025  thorpej Put the task of getting the device array from the FDT onto the
SPI bus attach routine. This is slightly ugly now, but a prettier
solution is on the way, and this at least funnels the ugliness into
a single location.
 1.28  10-Sep-2025  thorpej - Const poison references to spi_controller.
- Don't make a copy of the spi_controller in the SPI bus softc; just take
a reference to the one we got from the back-end driver.
 1.27  10-Sep-2025  thorpej Register the SPI controller with FDT in spi_attach(), not in each
driver.
 1.26  17-May-2022  andvar fix few typos in comments.
 1.25  08-May-2022  skrll Trailing whitespace
 1.24  28-Mar-2022  mlelstv Fix sanity check for zero sized buffer.
 1.23  19-Jan-2022  thorpej Provide a spi_compatible_lookup() function to go along with
spi_compatible_match().
 1.22  19-Jan-2022  thorpej Stash the device_t in spi_softc.
 1.21  19-Jan-2022  martin Try to fix the build.
 1.20  19-Jan-2022  thorpej Pass the device_t into spi_configure(), and make the API contract that
spi_configure() will print errors if they occur; the driver is off the
hook.
 1.19  07-Aug-2021  thorpej branches: 1.19.2;
Merge thorpej-cfargs2.
 1.18  16-May-2021  mlelstv branches: 1.18.4;
Protect ioctl and declare MPSAFE.
 1.17  24-Apr-2021  thorpej branches: 1.17.2; 1.17.4;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.16  18-Jan-2021  thorpej branches: 1.16.2;
Change the device_compatible_match() function to only perform the match.
Introduce a device_compatible_lookup() function to return an entry based
on the same matching criteria (a'la of_search_compatible()).

Update iic_compatible_match() to reflect the above change, and introduce
iic_compatible_lookup(). This pattern is less awkward to use.
 1.15  04-Aug-2020  kardel branches: 1.15.2;
Use mutex for lwp/interrupt coordination. using splX() simply does not work
on multiprocessor systems.

fixes PR kern/55506
 1.14  11-Jun-2020  thorpej Update for proplib(3) API changes.
 1.13  27-Nov-2019  hkenken Remove GPIO driver attach defer.
 1.12  13-Aug-2019  tnn spi: prepare for fdt direct attachment of spi slaves

Introduce sba_child_devices array in spibus_attach_args. If the parent has
populated sba_child_devices then attach them first. Then do any devices
devices the user has wired in the kernel config, if any.
 1.11  09-Mar-2019  mlelstv branches: 1.11.4;
More input validation. Fix off-by-1 for size limit.
 1.10  23-Feb-2019  mlelstv Add userland driver to spi framework.

Previously spi would configure the controller to use the lowest speed of
all connected devices since the kernel started and to fail attempted mode
changes. This is now improved to keep individual modes and speeds for each
slave and to reconfigure the controller as necessary for each transfer.

Added man page for spi(9).
 1.9  03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.8  15-Feb-2013  rkujawa branches: 1.8.6; 1.8.36; 1.8.38;
Fix usage of uninitialised variable holding number of slave devices.
The sc_nslaves has to be initialised before it is used in allocation of a memory holding save devices' configuration, otherwise slave drivers are causing kernel crashes.

Patch from Semihalf.
Author: Michal Dubiel <md@semihalf.com>
 1.7  04-Jan-2013  jakllsch Don't leak condvars and mutexes, even if they are on the stack.
Fixes LOCKDEBUG asserts when a mutex/condvar is initialized at the same
stack address as a previous initialization. We probably want to revisit
the transfer structure lifecyle at some point in the future.
 1.6  08-Jul-2011  mrg branches: 1.6.2; 1.6.8; 1.6.12;
initialise chuck_rptr as well, instead of chuck_read twice.
 1.5  08-Jun-2011  rmind - Use IPL_BIO (instead of IPL_SERIAL) for SPI.
- Convert simple_lock/ltsleep to mutex/condvar.
 1.4  14-Aug-2010  jym branches: 1.4.6;
Fix the while condition: sleep while the SPI_F_DONE bit is not set.

'!' takes precedence over bitwise operation '&', so use parenthesis.
 1.3  04-May-2008  xtraeme branches: 1.3.20; 1.3.22;
device_t/softc split.
 1.2  07-Oct-2006  gdamore branches: 1.2.2; 1.2.4; 1.2.8; 1.2.54; 1.2.56; 1.2.58;
Add spiflash driver, and M25P instance, used for STMicro flash devices
found on Meraki Mini (for example).
 1.1  02-Oct-2006  gdamore Initial commit of SPI bus (also known as Microwire) framework, along with
a sample driver for the TI TMP121 temperature sensor. This has been
moderately tested on Au1550, and it is not enabled in sys/conf (yet). So
the change is harmless at worst, and useful at best.

Alchemy Au1550 bus driver forthcoming, along with a driver for SPI flash
devices, such as found on the Meraki Mini

This development was partially funded by the Champaign-Urbana Community
Wireless Network Project.

Note that there are some MD-specific SPI drivers that could probably be
made MI under this new framework.
 1.2.58.2  09-Oct-2010  yamt sync with head
 1.2.58.1  16-May-2008  yamt sync with head.
 1.2.56.1  18-May-2008  yamt sync with head.
 1.2.54.1  02-Jun-2008  mjf Sync with HEAD.
 1.2.8.2  30-Dec-2006  yamt sync with head.
 1.2.8.1  07-Oct-2006  yamt file spi.c was added on branch yamt-lazymbuf on 2006-12-30 20:49:37 +0000
 1.2.4.2  18-Nov-2006  ad Sync with head.
 1.2.4.1  07-Oct-2006  ad file spi.c was added on branch newlock2 on 2006-11-18 21:34:49 +0000
 1.2.2.2  22-Oct-2006  yamt sync with head
 1.2.2.1  07-Oct-2006  yamt file spi.c was added on branch yamt-splraiseipl on 2006-10-22 06:06:48 +0000
 1.3.22.2  12-Jun-2011  rmind sync with head
 1.3.22.1  05-Mar-2011  rmind sync with head
 1.3.20.1  17-Aug-2010  uebayasi Sync with HEAD.
 1.4.6.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.6.12.1  25-Feb-2013  tls resync with head
 1.6.8.1  11-Feb-2013  riz Pull up following revision(s) (requested by skrll in ticket #809):
sys/dev/spi/spi.c: revision 1.7
Don't leak condvars and mutexes, even if they are on the stack.
Fixes LOCKDEBUG asserts when a mutex/condvar is initialized at the same
stack address as a previous initialization. We probably want to revisit
the transfer structure lifecyle at some point in the future.
 1.6.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.2.1  23-Jan-2013  yamt sync with head
 1.8.38.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8.38.1  10-Jun-2019  christos Sync with HEAD
 1.8.36.1  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.8.6.2  15-May-2013  khorben Let the bus speed of SPI devices be specified within the kernel
configuration.
 1.8.6.1  10-May-2013  khorben Just like for the I2C and GPIO buses, added an interrupt locator to the SPI
bus, so that ARM device drivers on either of these buses (like on the Nokia
N900) can register and react on system interrupts. These interrupts are
typically triggered via GPIO pins.

XXX This change is not adequate because intr_establish() is a MD interface,
so it will have to be re-designed before merging to the main tree.
 1.11.4.1  11-Aug-2020  martin Pull up following revision(s) (requested by 1043):

sys/dev/spi/spivar.h: revision 1.10
sys/arch/arm/broadcom/bcm2835_spi.c: revision 1.7
sys/dev/spi/spi.c: revision 1.15

Use mutex for lwp/interrupt coordination. using splX() simply does not work
on multiprocessor systems.

fixes PR kern/55506
 1.15.2.1  03-Apr-2021  thorpej Sync with HEAD.
 1.16.2.8  05-Apr-2021  thorpej Treat config_probe() as if it were a boolean function; don't compare
return value > 0... except for the odd balls, which are now really easy
to spot.
 1.16.2.7  05-Apr-2021  thorpej config_match() -> config_probe() for the straight-forward indirect config
cases. There are still a few odd balls using config_match() which should
be sorted out later.
 1.16.2.6  04-Apr-2021  thorpej CFARG_SUBMATCH -> CFARG_SEARCH for the indirect configuration uses.
 1.16.2.5  03-Apr-2021  thorpej Give config_attach() the tagged variadic argument treatment and
mechanically convert all call sites.
 1.16.2.4  22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.16.2.3  22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.16.2.2  21-Mar-2021  thorpej CFARG_IATTR usage audit:

If a device carries only one interface attribute, there is no need
to specify it when calling config_search(); that specification is
meant only to disambiguate which interface attribute (which is a
proxy for "what kind of attach args are being used") is having
children attached. cfparent_match() will take care of ensuring that
any potential children can attach to one of the parent's iterface
attributes, and if the parent only carries one, no disambiguation is
necessary.
 1.16.2.1  20-Mar-2021  thorpej The proliferation if config_search_*() and config_found_*() combinations
is a little absurd, so begin to tidy this up:

- Introduce a new cfarg_t enumerated type, that defines the types of
tag-value variadic arguments that can be passed to the various
config_*() functions (CFARG_SUBMATCH, CFARG_IATTR, and CFARG_LOCATORS,
for now, plus a CFARG_EOL sentinel).
- Collapse config_search_*() into config_search() that takes these
variadic arguments.
- Convert all call sites of config_search_*() to the new signature.
Noticed several incorrect usages along the way, which will be
audited in a future commit.
 1.17.4.1  31-May-2021  cjep sync with head
 1.17.2.2  17-Jun-2021  thorpej Sync w/ HEAD.
 1.17.2.1  18-May-2021  thorpej Define a "spi-enumerate-devices" device call and use it for direct
configuration of SPI devices, rather than slinging arrays of dictionaries
around. Implement this device call for OpenFirmware / FDT, following
the SPI bindings for Device Tree.
 1.18.4.1  04-Aug-2021  thorpej Adapt to CFARGS().
 1.19.2.2  10-Sep-2021  thorpej Record the attached child device_t in the spi_handle.
 1.19.2.1  09-Aug-2021  thorpej Port over the changes from thorpej-i2c-spi-conf to thorpej-i2c-spi-conf2,
which is based on a newer HEAD revision.

RSS XML Feed