Commit Graph

14 Commits

Author SHA1 Message Date
Jeff Roberson
91e31c3c08 Consistently use busy and vm_page_valid() rather than touching page bits
directly.  This improves API compliance, asserts, etc.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D23283
2020-01-23 04:54:49 +00:00
Ian Lepore
7a4f19151a Enhancements and fixes for the spigen(4) driver...
- Resources used by spigen_mmap_single() are now tracked using
  devfs_set_cdevpriv() rather than in the softc.

- Since resources are now tracked per-open-fd, there is no need to try to
  impose any exclusive-open logic, so flags related to that are removed.

- Flags used to track open status to prevent detach() when the device is
  open are replaced with calls to device_busy()/device_unbusy().  That
  extends the protection up the hierarchy so that the spibus and hardware
  controller drivers also can't be detached while the device is open/in use.

- Arbitrary limits on the maximum size of a transfer are removed, along with
  the sysctl variables that allowed the limits to be changed.  There is just
  no reason to limit the size of a spi transfer to the machine's page size.
  Or to any other arbitrary value, really.

- Most of the locking is removed.  It was mostly protecting access to flags
  and fields in the softc that no longer exist.  The locking that remains is
  just to prevent concurrent calls to device_[un]busy().

- The code was calling malloc() with M_WAITOK while holding a mutex in
  several places.  Since most of the locking is gone, that's fixed.
2018-07-11 17:54:41 +00:00
Ian Lepore
1fcf4de055 Incorporate bus and chip select numbers into spigen(4) cdev names. Rather
than assigning spigen device names in order of creation, this uses a device
name that corresponds to the owning spibus and chip-select index.

Example: /dev/spigen0.1 would be a child of spibus0, and use cs = 1

The intent is for systems like Raspberry Pi to have a consistent way of
using an SPI interface with a specific cs value from a user application.
Otherwise, there is no consistent way of knowing which cs pin will be
assigned to a particular spigen device. The alternative is to specify
everything in "the right order" in an overlay file, which is less than
ideal. Additionally, this duplicates (to some extent) the way Linux handles
a similar situation with their 'spidev' device, so it would be somewhat
familiar to those who also use Linux.

A new kernel config option, SPIGEN_LEGACY_CDEVNAME, causes the driver to
also create /dev/spigenN device name aliases, with N incrementing in the
order of device instantiation.  This is provided to ease the transition
for existing systems using the original naming convention (particularly
when these changes are MFC'd to stable branches).

Differential Revision:	https://reviews.freebsd.org/D15301
2018-06-21 21:16:26 +00:00
Ian Lepore
bc7b44aeaf Allow hinted attachment on FDT-based systems. Instead of returning ENXIO
when the FDT data doesn't enable the device instance, return
BUS_PROBE_NOWILDCARD, the same as for non-FDT systems.
2018-04-08 17:06:30 +00:00
Ian Lepore
197d784bf3 Cast the data pointer to the correct type for the data being accessed (as
opposed to one that accidentally worked on the one arch I test-compiled for
on my first try).

Reported by:	np@, O. Hartmann <ohartmann@walstatt.org>
Pointy hat:	ian@
2018-04-07 22:21:06 +00:00
Ian Lepore
e973ad2298 Don't check for impossible NULL return from malloc(..., M_WAITOK). 2018-04-07 21:31:09 +00:00
Ian Lepore
a0e911e097 Add an ioctl to get/set the SPI transfer mode. Also, make the bus clock
frequency ioctl actually set the corresponding ivar instead of just storing
the value locally in the softc (and then not using it for anything).  Also,
return the correct error code if the ioctl cmd is not recognized.
2018-04-07 20:38:01 +00:00
Ian Lepore
3b46d8687a Remove the existing identify() hack to force-add a spigen device on
FDT-based systems, and instead add proper FDT probe code.  Because this
driver is freebsd-specific and just provides generic userland access to run
spibus transactions, there is no bindings document to mandate a compatible
string, so just arbitrarily use "freebsd,spigen".
2018-04-07 20:04:03 +00:00
Ian Lepore
cdfebb9cf5 Add a missing MODULE_DEPEND(). 2018-04-04 21:19:33 +00:00
Oleksandr Tymoshenko
50868fa68b [spigen] make spigen device ready to be compiled as a module
- Add flag to indicate that device is opened by userland
- Replace "always fail" detach method with proper detach implementation

MFC after:	1 week
2017-03-09 01:00:27 +00:00
Oleksandr Tymoshenko
32d7412741 [spigen] Fix spigen attaching as a driver for SPI devices nodes in FDT
Return BUS_PROBE_NOWILDCARD in probe method to make sure that spigen
attaches only to the device created in identify method.

Before this change spigen probe method used to return 0 which meant it
competed with other drivers to be attached to the devices created for
child nodes of SPI bus node in FDT.

Reported by:	Daniel Braniss
MFC after:	1 week
2016-12-24 00:30:29 +00:00
Oleksandr Tymoshenko
3c43a826c6 [spigen] Make "data" part of spigen_transfer optional
Make st_data part of spigen_transfer optional by letting pass zero length
and NULL pointer. SPI controller drivers handle this case fine.

MFC after:	1 week
2016-12-16 19:09:57 +00:00
Emmanuel Vadot
dac458e0d6 Enable the use of spigen on FDT platform
MFC after:	2 weeks
2016-11-20 18:20:28 +00:00
Adrian Chadd
d67fe28ba6 [spigen] add initial spigen driver from green@
This is a simple ioctl and mmap API to issue SPI transactions from
userland.  It's useful for simple devices (eg spi temperature sensors,
etc) for experimentation.

TODO:

* Write some documentation!

Submitted by:	green
2016-05-26 07:02:20 +00:00