1*77f85581Swdenk /* 2*77f85581Swdenk * (C) Copyright 2001 3*77f85581Swdenk * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. 4*77f85581Swdenk * 5*77f85581Swdenk * See file CREDITS for list of people who contributed to this 6*77f85581Swdenk * project. 7*77f85581Swdenk * 8*77f85581Swdenk * This program is free software; you can redistribute it and/or 9*77f85581Swdenk * modify it under the terms of the GNU General Public License as 10*77f85581Swdenk * published by the Free Software Foundation; either version 2 of 11*77f85581Swdenk * the License, or (at your option) any later version. 12*77f85581Swdenk * 13*77f85581Swdenk * This program is distributed in the hope that it will be useful, 14*77f85581Swdenk * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*77f85581Swdenk * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*77f85581Swdenk * GNU General Public License for more details. 17*77f85581Swdenk * 18*77f85581Swdenk * You should have received a copy of the GNU General Public License 19*77f85581Swdenk * along with this program; if not, write to the Free Software 20*77f85581Swdenk * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*77f85581Swdenk * MA 02111-1307 USA 22*77f85581Swdenk */ 23*77f85581Swdenk 24*77f85581Swdenk #ifndef _SPI_H_ 25*77f85581Swdenk #define _SPI_H_ 26*77f85581Swdenk 27*77f85581Swdenk /* 28*77f85581Swdenk * The function call pointer type used to drive the chip select. 29*77f85581Swdenk */ 30*77f85581Swdenk typedef void (*spi_chipsel_type)(int cs); 31*77f85581Swdenk 32*77f85581Swdenk 33*77f85581Swdenk /*----------------------------------------------------------------------- 34*77f85581Swdenk * Initialization, must be called once on start up. 35*77f85581Swdenk */ 36*77f85581Swdenk void spi_init(void); 37*77f85581Swdenk 38*77f85581Swdenk 39*77f85581Swdenk /*----------------------------------------------------------------------- 40*77f85581Swdenk * SPI transfer 41*77f85581Swdenk * 42*77f85581Swdenk * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks 43*77f85581Swdenk * "bitlen" bits in the SPI MISO port. That's just the way SPI works. 44*77f85581Swdenk * 45*77f85581Swdenk * The source of the outgoing bits is the "dout" parameter and the 46*77f85581Swdenk * destination of the input bits is the "din" parameter. Note that "dout" 47*77f85581Swdenk * and "din" can point to the same memory location, in which case the 48*77f85581Swdenk * input data overwrites the output data (since both are buffered by 49*77f85581Swdenk * temporary variables, this is OK). 50*77f85581Swdenk * 51*77f85581Swdenk * If the chipsel() function is not NULL, it is called with a parameter 52*77f85581Swdenk * of '1' (chip select active) at the start of the transfer and again with 53*77f85581Swdenk * a parameter of '0' at the end of the transfer. 54*77f85581Swdenk * 55*77f85581Swdenk * If the chipsel() function _is_ NULL, it the responsibility of the 56*77f85581Swdenk * caller to make the appropriate chip select active before calling 57*77f85581Swdenk * spi_xfer() and making it inactive after spi_xfer() returns. 58*77f85581Swdenk * 59*77f85581Swdenk * spi_xfer() interface: 60*77f85581Swdenk * chipsel: Routine to call to set/clear the chip select: 61*77f85581Swdenk * if chipsel is NULL, it is not used. 62*77f85581Swdenk * if(cs), make the chip select active (typically '0'). 63*77f85581Swdenk * if(!cs), make the chip select inactive (typically '1'). 64*77f85581Swdenk * dout: Pointer to a string of bits to send out. The bits are 65*77f85581Swdenk * held in a byte array and are sent MSB first. 66*77f85581Swdenk * din: Pointer to a string of bits that will be filled in. 67*77f85581Swdenk * bitlen: How many bits to write and read. 68*77f85581Swdenk * 69*77f85581Swdenk * Returns: 0 on success, not 0 on failure 70*77f85581Swdenk */ 71*77f85581Swdenk int spi_xfer(spi_chipsel_type chipsel, int bitlen, uchar *dout, uchar *din); 72*77f85581Swdenk 73*77f85581Swdenk #endif /* _SPI_H_ */ 74