start of the tsc2100 driver.
[Rockbox.git] / firmware / target / arm / olympus / mrobe-500 / spi-mr500.c
blob8aeecd97f2319eb88a602cdb347efd3542b5681c
1 /*
2 * SPI interface driver for the DM320 SoC
4 * Copyright (C) 2007 shirour <mrobefan@gmail.com>
5 * Copyright (C) 2007 Catalin Patulea <cat@vv.carleton.ca>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "system.h"
30 #define GIO_TS_ENABLE (1<<2)
31 #define clr_gio_enable() outw(GIO_TS_ENABLE, IO_GIO_BITSET1)
32 #define set_gio_enable() outw(GIO_TS_ENABLE, IO_GIO_BITCLR1)
34 int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size,
35 uint8_t *rx_bytes, unsigned int rx_size)
37 /* Activate the slave select pin */
38 set_gio_enable();
40 while (tx_size--)
42 /* Send one byte */
43 IO_SERIAL0_TX_DATA = *tx_bytes++;
45 /* Wait until transfer finished */
46 while (IO_SERIAL0_RX_DATA & 0x100);
49 while (rx_size--)
51 /* Make the clock tick */
52 IO_SERIAL0_TX_DATA = 0;
54 /* Wait until transfer finished */
55 unsigned short data;
56 while ((data = IO_SERIAL0_RX_DATA) & 0x100);
58 *rx_bytes++ = data & 0xff;
61 clr_gio_enable();
63 return 0;
66 void spi_init(void)
68 /* Set SCLK idle level = 0 */
69 IO_SERIAL0_MODE |= (1<<10);
71 /* Enable TX */
72 IO_SERIAL0_TX_ENABLE = 0x0001;
74 /* Set GIO 18 to output for touch screen slave enable */
75 outw(inw(IO_GIO_DIR1)&~GIO_TS_ENABLE, IO_GIO_DIR1);
76 clr_gio_enable();