2 This file defines the interface to the lpc22xx SPI module.
3 Copyright (C) 2006 Embedded Artists AB (www.embeddedartists.com)
5 This file may be included in software not adhering to the GPL.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <asm/errno.h>
28 #include <asm/arch/hardware.h>
32 #define spi_lock() disable_interrupts();
33 #define spi_unlock() enable_interrupts();
35 extern unsigned long spi_flags;
36 extern unsigned char spi_idle;
40 static inline unsigned char spi_read(void)
44 PUT8(S0SPDR, spi_idle);
45 while (!(GET8(S0SPSR) & SPIF));
51 static inline void spi_write(unsigned char b)
54 while (!(GET8(S0SPSR) & SPIF));
55 GET8(S0SPDR); /* this will clear the SPIF bit */
58 static inline void spi_set_clock(unsigned char clk_value)
60 PUT8(S0SPCCR, clk_value);
63 static inline void spi_set_cfg(unsigned char phase,
64 unsigned char polarity,
67 unsigned char v = 0x20; /* master bit set */
70 v |= 0x08; /* set phase bit */
72 v |= 0x10; /* set polarity bit */
78 v |= 0x40; /* set lsbf bit */