blob: 6ae66e8ba744d857d5e52ce052d89d940d27d1b4 [file] [log] [blame]
Gary Jennejohn7968bb52007-01-24 12:16:56 +01001/*
2 This file defines the interface to the lpc22xx SPI module.
3 Copyright (C) 2006 Embedded Artists AB (www.embeddedartists.com)
4
5 This file may be included in software not adhering to the GPL.
6
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.
11
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.
16
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
20*/
21
22#ifndef SPI_H
23#define SPI_H
24
25#include <config.h>
26#include <common.h>
27#include <asm/errno.h>
28#include <asm/arch/hardware.h>
29
30#define SPIF 0x80
31
32#define spi_lock() disable_interrupts();
33#define spi_unlock() enable_interrupts();
34
35extern unsigned long spi_flags;
36extern unsigned char spi_idle;
37
38int spi_init(void);
39
40static inline unsigned char spi_read(void)
41{
42 unsigned char b;
43
44 PUT8(S0SPDR, spi_idle);
45 while (!(GET8(S0SPSR) & SPIF));
46 b = GET8(S0SPDR);
47
48 return b;
49}
50
51static inline void spi_write(unsigned char b)
52{
53 PUT8(S0SPDR, b);
54 while (!(GET8(S0SPSR) & SPIF));
55 GET8(S0SPDR); /* this will clear the SPIF bit */
56}
57
58static inline void spi_set_clock(unsigned char clk_value)
59{
60 PUT8(S0SPCCR, clk_value);
61}
62
63static inline void spi_set_cfg(unsigned char phase,
64 unsigned char polarity,
65 unsigned char lsbf)
66{
67 unsigned char v = 0x20; /* master bit set */
68
69 if (phase)
70 v |= 0x08; /* set phase bit */
71 if (polarity) {
72 v |= 0x10; /* set polarity bit */
73 spi_idle = 0xFF;
74 } else {
75 spi_idle = 0x00;
76 }
77 if (lsbf)
78 v |= 0x40; /* set lsbf bit */
79
80 PUT8(S0SPCR, v);
81}
Wolfgang Denk62e8a972007-01-30 00:50:40 +010082#endif /* SPI_H */