2007-09-21 15:51:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Will Robertson
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-09-21 15:51:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2008-05-16 18:40:28 +00:00
|
|
|
#ifndef SPI_IMX31_H
|
|
|
|
#define SPI_IMX31_H
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2008-04-11 08:51:27 +00:00
|
|
|
#define USE_CSPI1_MODULE (1 << 0)
|
|
|
|
#define USE_CSPI2_MODULE (1 << 1)
|
|
|
|
#define USE_CSPI3_MODULE (1 << 2)
|
|
|
|
|
|
|
|
/* SPI_MODULE_MASK is set in target's config */
|
|
|
|
enum spi_module_number
|
|
|
|
{
|
2008-04-12 05:11:50 +00:00
|
|
|
__CSPI_NUM_START = -1, /* The first will be 0 */
|
2008-04-11 08:51:27 +00:00
|
|
|
#if (SPI_MODULE_MASK & USE_CSPI1_MODULE)
|
2008-04-12 05:11:50 +00:00
|
|
|
CSPI1_NUM,
|
2008-04-11 08:51:27 +00:00
|
|
|
#endif
|
|
|
|
#if (SPI_MODULE_MASK & USE_CSPI2_MODULE)
|
|
|
|
CSPI2_NUM,
|
|
|
|
#endif
|
|
|
|
#if (SPI_MODULE_MASK & USE_CSPI3_MODULE)
|
|
|
|
CSPI3_NUM,
|
|
|
|
#endif
|
|
|
|
SPI_NUM_CSPI,
|
|
|
|
};
|
|
|
|
|
2008-04-27 21:32:10 +00:00
|
|
|
struct cspi_map
|
|
|
|
{
|
|
|
|
volatile uint32_t rxdata; /* 00h */
|
|
|
|
volatile uint32_t txdata; /* 04h */
|
|
|
|
volatile uint32_t conreg; /* 08h */
|
|
|
|
volatile uint32_t intreg; /* 0Ch */
|
|
|
|
volatile uint32_t dmareg; /* 10h */
|
|
|
|
volatile uint32_t statreg; /* 14h */
|
|
|
|
volatile uint32_t periodreg; /* 18h */
|
|
|
|
volatile uint32_t skip1[0x69]; /* 1Ch */
|
|
|
|
volatile uint32_t testreg; /* 1C0h */
|
|
|
|
};
|
|
|
|
|
2008-04-11 08:51:27 +00:00
|
|
|
struct spi_node
|
|
|
|
{
|
|
|
|
enum spi_module_number num; /* Module number (CSPIx_NUM) */
|
|
|
|
unsigned long conreg; /* CSPI conreg setup */
|
|
|
|
unsigned long periodreg; /* CSPI periodreg setup */
|
|
|
|
};
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
struct spi_transfer_desc;
|
|
|
|
|
|
|
|
typedef void (*spi_transfer_cb_fn_type)(struct spi_transfer_desc *);
|
|
|
|
|
|
|
|
struct spi_transfer_desc
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
2010-05-04 10:07:53 +00:00
|
|
|
const struct spi_node *node; /* node for this transfer */
|
|
|
|
const void *txbuf; /* buffer to transmit */
|
|
|
|
void *rxbuf; /* buffer to receive */
|
|
|
|
int count; /* number of elements */
|
|
|
|
spi_transfer_cb_fn_type callback; /* function to call when done */
|
|
|
|
struct spi_transfer_desc *next; /* next transfer queued,
|
|
|
|
spi layer sets this */
|
2008-04-11 08:51:27 +00:00
|
|
|
};
|
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
/* NOTE: SPI updates the descrptor during the operation. Do not write
|
|
|
|
* to it until completion notification is received. If no callback is
|
|
|
|
* specified, the caller must find a way to ensure integrity.
|
|
|
|
*
|
|
|
|
* -1 will be written to 'count' if an error occurs, otherwise it will
|
|
|
|
* be zero when completed.
|
|
|
|
*/
|
|
|
|
|
2008-04-11 08:51:27 +00:00
|
|
|
/* One-time init of SPI driver */
|
2007-09-21 15:51:53 +00:00
|
|
|
void spi_init(void);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
|
|
|
/* Enable the specified module for the node */
|
2010-05-04 10:07:53 +00:00
|
|
|
void spi_enable_module(const struct spi_node *node);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
|
|
|
/* Disabled the specified module for the node */
|
2010-05-04 10:07:53 +00:00
|
|
|
void spi_disable_module(const struct spi_node *node);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-05-04 10:07:53 +00:00
|
|
|
/* Send and/or receive data on the specified node (asychronous) */
|
|
|
|
bool spi_transfer(struct spi_transfer_desc *xfer);
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2008-05-16 18:40:28 +00:00
|
|
|
#endif /* SPI_IMX31_H */
|