1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (c) 2007 Will Robertson
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 #define USE_CSPI1_MODULE (1 << 0)
25 #define USE_CSPI2_MODULE (1 << 1)
26 #define USE_CSPI3_MODULE (1 << 2)
28 /* SPI_MODULE_MASK is set in target's config */
29 enum spi_module_number
31 __CSPI_NUM_START
= -1, /* The first will be 0 */
32 #if (SPI_MODULE_MASK & USE_CSPI1_MODULE)
35 #if (SPI_MODULE_MASK & USE_CSPI2_MODULE)
38 #if (SPI_MODULE_MASK & USE_CSPI3_MODULE)
46 enum spi_module_number num
; /* Module number (CSPIx_NUM) */
47 unsigned long conreg
; /* CSPI conreg setup */
48 unsigned long periodreg
; /* CSPI periodreg setup */
51 struct spi_transfer_desc
;
53 typedef void (*spi_transfer_cb_fn_type
)(struct spi_transfer_desc
*);
55 struct spi_transfer_desc
57 const struct spi_node
*node
; /* node for this transfer */
58 const void *txbuf
; /* buffer to transmit */
59 void *rxbuf
; /* buffer to receive */
60 int count
; /* number of elements */
61 spi_transfer_cb_fn_type callback
; /* function to call when done */
62 struct spi_transfer_desc
*next
; /* next transfer queued,
63 spi layer sets this */
66 /* NOTE: SPI updates the descrptor during the operation. Do not write
67 * to it until completion notification is received. If no callback is
68 * specified, the caller must find a way to ensure integrity.
70 * -1 will be written to 'count' if an error occurs, otherwise it will
71 * be zero when completed.
74 /* One-time init of SPI driver */
77 /* Enable the specified module for the node */
78 void spi_enable_module(const struct spi_node
*node
);
80 /* Disabled the specified module for the node */
81 void spi_disable_module(const struct spi_node
*node
);
83 /* Send and/or receive data on the specified node (asychronous) */
84 bool spi_transfer(struct spi_transfer_desc
*xfer
);
86 /* Returns 'true' if the descriptor is not busy */
87 bool spi_transfer_complete(const struct spi_transfer_desc
*xfer
);
89 #endif /* SPI_IMX31_H */