Linux Kernel
3.7.1
|
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/cache.h>
#include <linux/mutex.h>
#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/slab.h>
#include <linux/mod_devicetable.h>
#include <linux/spi/spi.h>
#include <linux/pm_runtime.h>
#include <linux/export.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/kthread.h>
Go to the source code of this file.
Data Structures | |
struct | boardinfo |
Macros | |
#define | spi_pm_suspend NULL |
#define | spi_pm_resume NULL |
#define | spi_pm_freeze NULL |
#define | spi_pm_thaw NULL |
#define | spi_pm_poweroff NULL |
#define | spi_pm_restore NULL |
#define | SPI_BUFSIZ max(32,SMP_CACHE_BYTES) |
Variables | |
struct bus_type | spi_bus_type |
#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES) |
EXPORT_SYMBOL_GPL | ( | spi_get_device_id | ) |
EXPORT_SYMBOL_GPL | ( | spi_bus_type | ) |
EXPORT_SYMBOL_GPL | ( | spi_register_driver | ) |
EXPORT_SYMBOL_GPL | ( | spi_alloc_device | ) |
EXPORT_SYMBOL_GPL | ( | spi_add_device | ) |
EXPORT_SYMBOL_GPL | ( | spi_new_device | ) |
EXPORT_SYMBOL_GPL | ( | spi_get_next_queued_message | ) |
EXPORT_SYMBOL_GPL | ( | spi_finalize_current_message | ) |
EXPORT_SYMBOL_GPL | ( | spi_alloc_master | ) |
EXPORT_SYMBOL_GPL | ( | spi_register_master | ) |
EXPORT_SYMBOL_GPL | ( | spi_unregister_master | ) |
EXPORT_SYMBOL_GPL | ( | spi_master_suspend | ) |
EXPORT_SYMBOL_GPL | ( | spi_master_resume | ) |
EXPORT_SYMBOL_GPL | ( | spi_busnum_to_master | ) |
EXPORT_SYMBOL_GPL | ( | spi_setup | ) |
EXPORT_SYMBOL_GPL | ( | spi_async | ) |
EXPORT_SYMBOL_GPL | ( | spi_async_locked | ) |
EXPORT_SYMBOL_GPL | ( | spi_sync | ) |
EXPORT_SYMBOL_GPL | ( | spi_sync_locked | ) |
EXPORT_SYMBOL_GPL | ( | spi_bus_lock | ) |
EXPORT_SYMBOL_GPL | ( | spi_bus_unlock | ) |
EXPORT_SYMBOL_GPL | ( | spi_write_then_read | ) |
postcore_initcall | ( | spi_init | ) |
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 __devinit spi_register_board_info | ( | struct spi_board_info const * | info, |
unsigned | n | ||
) |
spi_register_board_info - register SPI devices for a given board : array of chip descriptors
: how many descriptors are provided Context: can sleep
Board-specific early init code calls this (probably during arch_initcall) with segments of the SPI device table. Any device nodes are created later, after the relevant parent SPI controller (bus_num) is defined. We keep this table of devices forever, so that reloading a controller driver will not make Linux forget about these hard-wired devices.
Other code can also call this, e.g. a particular add-on board might provide SPI devices through its expansion connector, so code initializing that board would naturally declare its SPI devices.
The board info passed can safely be __initdata ... but be careful of any embedded pointers (platform_data, etc), they're copied as-is.
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.