Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

SPI driver



I've written a userland interface to our spi(4) driver.

crw-------  1 root  wheel  346, 0 Jan  5 16:02 /dev/spi0

It supports two ioctls:

SPI_IOCTL_CONFIGURE
calls spi_configure() to chose operational mode and clock. Argument is

typedef struct spi_ioctl_configure {
        int sic_mode;
        int sic_speed;
} spi_ioctl_configure_t;

The mode defines polarity and phase of the clock, speed is the clock in Hz,
a value of 0 means to keep the existing (default) speed of the device.


SPI_IOCTL_TRANSFER
calls spi_transfer() to handle an I/O transaction. Argument is

typedef struct spi_ioctl_transfer {
        int sit_addr;
        const void *sit_send;
        size_t sit_sendlen;
        void *sit_recv;
        size_t sit_recvlen;
} spi_ioctl_transfer_t;

which specifies the slave (i.e. which chip select signal), a send buffer
and a receive buffer.

This exposes directly the internal spi(4) programming interface similar
to iic(4) for I2C interfaces.

The interface is different from spigen(4) used by FreeBSD and also different
from an early example of an SPI driver by Jonathan Kollasch. See:
https://mail-index.netbsd.org/port-arm/2016/12/31/msg004050.html

I'd like to commit the driver in the next days, feel free to comment
on the interface.


There is one problem with our current spi_configure kernel interface.
To avoid conflicts by multiple users of an SPI interface, the mode,
once set, cannot be changed and the frequency can only be reduced.
This is fine for code that is run once after bootstrap, but not
useful for generic programs. As there is no kind of session handling,
I suggest an operation that resets the configuration and isn't
used by regular drivers. E.g. setting a mode or speed of -1 would
indicate a reset to initial conditions.


-- 
-- 
                                Michael van Elst
Internet: mlelstv%serpens.de@localhost
                                "A potential Snark may lurk in every tree."


Home | Main Index | Thread Index | Old Index