Linux Kernel
3.7.1
|
#include <linux/device.h>
#include <linux/mod_devicetable.h>
#include <linux/slab.h>
#include <linux/kthread.h>
Go to the source code of this file.
Data Structures | |
struct | spi_device |
struct | spi_driver |
struct | spi_master |
struct | spi_transfer |
struct | spi_message |
struct | spi_board_info |
Macros | |
#define | SPI_CPHA 0x01 /* clock phase */ |
#define | SPI_CPOL 0x02 /* clock polarity */ |
#define | SPI_MODE_0 (0|0) /* (original MicroWire) */ |
#define | SPI_MODE_1 (0|SPI_CPHA) |
#define | SPI_MODE_2 (SPI_CPOL|0) |
#define | SPI_MODE_3 (SPI_CPOL|SPI_CPHA) |
#define | SPI_CS_HIGH 0x04 /* chipselect active high? */ |
#define | SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */ |
#define | SPI_3WIRE 0x10 /* SI/SO signals shared */ |
#define | SPI_LOOP 0x20 /* loopback mode */ |
#define | SPI_NO_CS 0x40 /* 1 dev/bus, no chipselect */ |
#define | SPI_READY 0x80 /* slave pulls low to pause */ |
#define | module_spi_driver(__spi_driver) |
#define | SPI_MASTER_HALF_DUPLEX BIT(0) /* can't do full duplex */ |
#define | SPI_MASTER_NO_RX BIT(1) /* can't do buffer read */ |
#define | SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */ |
Variables | |
struct bus_type | spi_bus_type |
#define module_spi_driver | ( | __spi_driver | ) |
module_spi_driver() - Helper macro for registering a SPI driver : spi_driver struct
Helper macro for SPI drivers which do not do anything special in module init/exit. This eliminates a lot of boilerplate. Each module may only use this macro once, and calling it replaces module_init() and module_exit()
int spi_add_device | ( | struct spi_device * | spi | ) |
spi_add_device - Add spi_device allocated with spi_alloc_device : spi_device to register
Companion function to spi_alloc_device. Devices allocated with spi_alloc_device can be added onto the spi bus with this function.
Returns 0 on success; negative errno on failure
|
read |
spi_alloc_device - Allocate a new SPI device : Controller to which device is connected Context: can sleep
Allows a driver to allocate and initialize a spi_device without registering it immediately. This allows a driver to directly fill the spi_device with device parameters before calling spi_add_device() on it.
Caller is responsible to call spi_add_device() on the returned spi_device structure to add it to the SPI master. If the caller needs to discard the spi_device without adding it, then it should call spi_dev_put() on it.
|
read |
spi_alloc_master - allocate SPI master controller : the controller, possibly using the platform_bus : how much zeroed driver-private data to allocate; the pointer to this memory is in the driver_data field of the returned device, accessible with spi_master_get_devdata(). Context: can sleep
This call is used only by SPI master controller drivers, which are the only ones directly touching chip registers. It's how they allocate an spi_master structure, prior to calling spi_register_master().
This must be called from context that can sleep. It returns the SPI master structure on success, else NULL.
The caller is responsible for assigning the bus number and initializing the master's methods before calling spi_register_master(); and (after errors adding the device) calling spi_master_put() and kfree() to prevent a memory leak.
int spi_async | ( | struct spi_device * | spi, |
struct spi_message * | message | ||
) |
spi_async - asynchronous SPI transfer : device with which data will be exchanged : describes the data transfers, including completion callback Context: any (irqs may be blocked, etc)
This call may be used in_irq and other contexts which can't sleep, as well as from task contexts which can sleep.
The completion callback is invoked in a context which can't sleep. Before that invocation, the value of message->status is undefined. When the callback is issued, message->status holds either zero (to indicate complete success) or a negative error code. After that callback returns, the driver which issued the transfer request may deallocate the associated memory; it's no longer in use by any SPI core or controller driver code.
Note that although all messages to a spi_device are handled in FIFO order, messages may go to different devices in other orders. Some device might be higher priority, or have various "hard" access time requirements, for example.
On detection of any fault during the transfer, processing of the entire message is aborted, and the device is deselected. Until returning from the associated message completion callback, no other spi_message queued to that device will be processed. (This rule applies equally to all the synchronous transfer calls, which are wrappers around this core asynchronous primitive.)
int spi_async_locked | ( | struct spi_device * | spi, |
struct spi_message * | message | ||
) |
spi_async_locked - version of spi_async with exclusive bus usage : device with which data will be exchanged : describes the data transfers, including completion callback Context: any (irqs may be blocked, etc)
This call may be used in_irq and other contexts which can't sleep, as well as from task contexts which can sleep.
The completion callback is invoked in a context which can't sleep. Before that invocation, the value of message->status is undefined. When the callback is issued, message->status holds either zero (to indicate complete success) or a negative error code. After that callback returns, the driver which issued the transfer request may deallocate the associated memory; it's no longer in use by any SPI core or controller driver code.
Note that although all messages to a spi_device are handled in FIFO order, messages may go to different devices in other orders. Some device might be higher priority, or have various "hard" access time requirements, for example.
On detection of any fault during the transfer, processing of the entire message is aborted, and the device is deselected. Until returning from the associated message completion callback, no other spi_message queued to that device will be processed. (This rule applies equally to all the synchronous transfer calls, which are wrappers around this core asynchronous primitive.)
int spi_bus_lock | ( | struct spi_master * | master | ) |
spi_bus_lock - obtain a lock for exclusive SPI bus usage : SPI bus master that should be locked for exclusive bus access Context: can sleep
This call may only be used from a context that may sleep. The sleep is non-interruptible, and has no timeout.
This call should be used by drivers that require exclusive access to the SPI bus. The SPI bus must be released by a spi_bus_unlock call when the exclusive access is over. Data transfer must be done by spi_sync_locked and spi_async_locked calls when the SPI bus lock is held.
It returns zero on success, else a negative error code.
int spi_bus_unlock | ( | struct spi_master * | master | ) |
spi_bus_unlock - release the lock for exclusive SPI bus usage : SPI bus master that was locked for exclusive bus access Context: can sleep
This call may only be used from a context that may sleep. The sleep is non-interruptible, and has no timeout.
This call releases an SPI bus lock previously obtained by an spi_bus_lock call.
It returns zero on success, else a negative error code.
|
read |
spi_busnum_to_master - look up master associated with bus_num : the master's bus number Context: can sleep
This call may be used with devices that are registered after arch init time. It returns a refcounted pointer to the relevant spi_master (which the caller must release), or NULL if there is no such master registered.
void spi_finalize_current_message | ( | struct spi_master * | master | ) |
|
read |
|
read |
int spi_master_resume | ( | struct spi_master * | master | ) |
int spi_master_suspend | ( | struct spi_master * | master | ) |
|
read |
spi_new_device - instantiate one new SPI device : Controller to which device is connected : Describes the SPI device Context: can sleep
On typical mainboards, this is purely internal; and it's not needed after board init creates the hard-wired devices. Some development platforms may not be able to use spi_register_board_info though, and this is exported so that for example a USB or parport based adapter driver could add devices (which it would learn about out-of-band).
Returns the new device, or NULL.
int spi_register_driver | ( | struct spi_driver * | sdrv | ) |
int spi_register_master | ( | struct spi_master * | master | ) |
spi_register_master - register SPI master controller : initialized master, originally from spi_alloc_master() Context: can sleep
SPI master controllers connect to their drivers using some non-SPI bus, such as the platform bus. The final stage of probe() in that code includes calling spi_register_master() to hook up to this SPI bus glue.
SPI controllers use board specific (often SOC specific) bus numbers, and board-specific addressing for SPI devices combines those numbers with chip select numbers. Since SPI does not directly support dynamic device identification, boards need configuration tables telling which chip is at which address.
This must be called from context that can sleep. It returns zero on success, else a negative error code (dropping the master's refcount). After a successful return, the caller is responsible for calling spi_unregister_master().
int spi_setup | ( | struct spi_device * | spi | ) |
spi_setup - setup SPI mode and clock rate : the device whose settings are being modified Context: can sleep, and no requests are queued to the device
SPI protocol drivers may need to update the transfer mode if the device doesn't work with its default. They may likewise need to update clock rates or word sizes from initial values. This function changes those settings, and must be called from a context that can sleep. Except for SPI_CS_HIGH, which takes effect immediately, the changes take effect the next time the device is selected and data is transferred to or from it. When this function returns, the spi device is deselected.
Note that this call will fail if the protocol driver specifies an option that the underlying controller or its driver does not support. For example, not all hardware supports wire transfers using nine bit words, LSB-first wire encoding, or active-high chipselects.
int spi_sync | ( | struct spi_device * | spi, |
struct spi_message * | message | ||
) |
spi_sync - blocking/synchronous SPI data transfers : device with which data will be exchanged : describes the data transfers Context: can sleep
This call may only be used from a context that may sleep. The sleep is non-interruptible, and has no timeout. Low-overhead controller drivers may DMA directly into and out of the message buffers.
Note that the SPI device's chip select is active during the message, and then is normally disabled between messages. Drivers for some frequently-used devices may want to minimize costs of selecting a chip, by leaving it selected in anticipation that the next message will go to the same chip. (That may increase power usage.)
Also, the caller is guaranteeing that the memory associated with the message will not be freed before this call returns.
It returns zero on success, else a negative error code.
int spi_sync_locked | ( | struct spi_device * | spi, |
struct spi_message * | message | ||
) |
spi_sync_locked - version of spi_sync with exclusive bus usage : device with which data will be exchanged : describes the data transfers Context: can sleep
This call may only be used from a context that may sleep. The sleep is non-interruptible, and has no timeout. Low-overhead controller drivers may DMA directly into and out of the message buffers.
This call should be used by drivers that require exclusive access to the SPI bus. It has to be preceded by a spi_bus_lock call. The SPI bus must be released by a spi_bus_unlock call when the exclusive access is over.
It returns zero on success, else a negative error code.
void spi_unregister_master | ( | struct spi_master * | master | ) |
int spi_write_then_read | ( | struct spi_device * | spi, |
const void * | txbuf, | ||
unsigned | n_tx, | ||
void * | rxbuf, | ||
unsigned | n_rx | ||
) |
spi_write_then_read - SPI synchronous write followed by read : device with which data will be exchanged : data to be written (need not be dma-safe) : size of txbuf, in bytes : buffer into which data will be read (need not be dma-safe) : size of rxbuf, in bytes Context: can sleep
This performs a half duplex MicroWire style transaction with the device, sending txbuf and then reading rxbuf. The return value is zero for success, else a negative errno status code. This call may only be used from a context that may sleep.
Parameters to this routine are always copied using a small buffer; portable code should never use this for more than 32 bytes. Performance-sensitive or bulk transfer code should instead use spi_{async,sync}() calls with dma-safe buffers.