Main Page | Data Structures | File List | Data Fields | Globals

spi_io.c File Reference


Detailed Description

SPI Support.

Author:
Andrew Roca
Supports access to multiple SPI device through the Axis SPI core, the on board PIC is logically SPI device 0 Multiple SPI clients can send data to multiple devices concurrently to support this the SPI code needs to queue transactions.

#include "spi_io.h"
#include "axis_pci.h"
#include "axis.h"

Include dependency graph for spi_io.c:

Include dependency graph

Functions

void init_spi_channel (struct spi_channel *ptr,unsigned char no, struct axis_pci_device_entry *device)
 Initialise a SPI channel structure.

void init_spi (struct axis_pci_device_entry *device)
int wait_for_spi_free (struct spi_op *op)
 moves spi operation on to queue for SPI hardware

void set_spi_control_1 (struct axis_pci_device_entry *device, unsigned char options)
 Writes optional SPI settings (bitorder divisor clock phase etc) to control register.

unsigned char read_spi_status (struct axis_pci_device_entry *device)
 Reads SPI status register.

unsigned char read_spi_control_1 (struct axis_pci_device_entry *device)
 reads SPI control register 1

void set_spi_control_2 (struct axis_pci_device_entry *device)
 writes SPI control register 2

void set_spi_address (struct axis_pci_device_entry *device, unsigned char address)
 set up SPI addressing for selected channel

void disable_spi (struct axis_pci_device_entry *device)
 turn off SPI

int despatch_spi_op (struct spi_op *op)
 process a single SPI operation

ssize_t axis_spi_read (struct file *file_ptr, char *buffer, size_t size, loff_t *offset)
 Gets data from the selected SPI and returns it to userland.

ssize_t axis_spi_write (struct file *file_ptr, const char *buffer,size_t size,loff_t *offset)
 Copies data from USER space and sends it to spi.

int axis_spi_ioctl (struct inode *inode_ptr, struct file *file_ptr, unsigned int type,unsigned long args)
 Provides an interface to allow user land to control spi options.

int axis_spi_open (struct inode *inode_ptr, struct file *file_ptr)
 open function for spi support

int axis_spi_release (struct inode *inode_ptr, struct file *file_ptr)
 Called by kernel in response to a process closing a device.


Variables

file_operations spi_file_operations

Function Documentation

int axis_spi_ioctl struct inode *  inode_ptr,
struct file *  file_ptr,
unsigned int  type,
unsigned long  args
[static]
 

Provides an interface to allow user land to control spi options.

Parameters:
inode_ptr - devices inode
file_ptr - pointer to kernel file structure for open device
type - identifies the IOCTL operation requested
args - unspecified parameter supplied by user program meaning depends on type
Returns:
0 on success error number otherwise

To allow user applications options other then read / write the driver support IOCTL calls the type constants are defined in axis.h

int axis_spi_open struct inode *  inode_ptr,
struct file *  file_ptr
[static]
 

open function for spi support

Parameters:
inode_ptr - pointer to inode structure the kernel will associate with this instance
file_ptr - pointer to the file structure the kernel uses to track this open instance
Returns:
0 on sucess error code otherwise

This open is called from the general open after its worked out what type of subdevice user space has requested Open an individual SPI device for sanities sake only allow a single open for each device

ssize_t axis_spi_read struct file *  file_ptr,
char *  buffer,
size_t  size,
loff_t *  offset
[static]
 

Gets data from the selected SPI and returns it to userland.

Parameters:
file_ptr - pointer to kernel file structure for open device
buffer - pointer to user applications buffer
size - number of bytes to read
offset - not used
Returns:
number read

Called by kernel in response to a user application making a read call. Note the user buffer pointer is not a valid address from inside the kernel. Gets data from the SPI device and returns it to userland.

Here is the call graph for this function:

int axis_spi_release struct inode *  inode_ptr,
struct file *  file_ptr
[static]
 

Called by kernel in response to a process closing a device.

Parameters:
inode_ptr 
file_ptr 
Returns:
0 on success

Called by kernel if user application closes device. Release must decrement the open count to signal that the device has been finished with and that other processes can open it

ssize_t axis_spi_write struct file *  file_ptr,
const char *  buffer,
size_t  size,
loff_t *  offset
[static]
 

Copies data from USER space and sends it to spi.

Parameters:
file_ptr - pointer to kernel file structure for open device
buffer - user processes buffer
size - number of bytes to write
offset - allow lseek offset
Returns:
number written

Copies data from USER space and sends it on to the SPI write code

Here is the call graph for this function:

int despatch_spi_op struct spi_op op  ) 
 

process a single SPI operation

Parameters:
op - spi operation
Returns:
zero for success

In the case of SPI we have to write dummy data out in order to perform a read given this SPI read and write operations are managed by this one function. Note the hardware supports multiple SPI devices using one interface. We allow single open for each device this means operations must be queued so access to the SPI hardware is serialised

Here is the call graph for this function:

void disable_spi struct axis_pci_device_entry device  )  [inline, static]
 

turn off SPI

Parameters:
device - hardware master structure
Returns:
NONE

once we have finished with SPI disable it

void init_spi struct axis_pci_device_entry device  ) 
 

Here is the call graph for this function:

void init_spi_channel struct spi_channel ptr,
unsigned char  no,
struct axis_pci_device_entry device
 

Initialise a SPI channel structure.

Parameters:
ptr - spi_channel structure to initalise
no - number to identify this channal
device - hardware master structure
Returns:
NONE

Initialise the SPI channel structure, called as we initalise the PCI structure

unsigned char read_spi_control_1 struct axis_pci_device_entry device  )  [inline, static]
 

reads SPI control register 1

Parameters:
device - hardware master structure
Returns:
register value

Reads SPI control register 1

unsigned char read_spi_status struct axis_pci_device_entry device  )  [inline, static]
 

Reads SPI status register.

Parameters:
device - hardware master structure
Returns:
current value

Read status register associated with SPI device

void set_spi_address struct axis_pci_device_entry device,
unsigned char  address
[inline, static]
 

set up SPI addressing for selected channel

Parameters:
device - hardware master structure
address - requested channel
Returns:
NONE

The SPI hardware has multiple enable/chip select lines. These are set by writing a bit to a register. Note the PIC interface still needs this setting but the PIC select is used in the FPGA to gate the clock and data line. This was done to save pins

void set_spi_control_1 struct axis_pci_device_entry device,
unsigned char  options
[inline, static]
 

Writes optional SPI settings (bitorder divisor clock phase etc) to control register.

Parameters:
device - hardware master structure
options - Settings for this SPI channel
Returns:
NONE

Writes optional SPI settings (bitorder divisor clock phase etc) to control register

void set_spi_control_2 struct axis_pci_device_entry device  )  [inline, static]
 

writes SPI control register 2

Parameters:
device - hardware master structure
Returns:
NONE

The SPI control register handles error behaviour. I'm not sure if an SPI master should ever receive an over run error. Things must have gone badly wrong for this to occur. We clear the error just in case. This write only register overlays the SPI status register

Here is the call graph for this function:

int wait_for_spi_free struct spi_op op  )  [static]
 

moves spi operation on to queue for SPI hardware

Parameters:
op - spi operation awaiting processing
Returns:
NONE

While driver supports multiple SPI channels there is physically only one set of SPI hardware. Function implements queuing to prevent SPI concurrent operations from failing.


Variable Documentation

struct file_operations spi_file_operations
 

Initial value:

{
    read:            axis_spi_read,           
    write:           axis_spi_write,          
    ioctl:           axis_spi_ioctl,          
    open:            axis_spi_open,            
    release:         axis_spi_release,          
}


Generated on Fri Jan 28 12:37:28 2005 for Axis Kernel Driver by doxygen 1.3.6