summaryrefslogtreecommitdiff
path: root/firmware/target/arm/olympus/mrobe-500
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/olympus/mrobe-500')
-rw-r--r--firmware/target/arm/olympus/mrobe-500/spi-mr500.c77
-rw-r--r--firmware/target/arm/olympus/mrobe-500/spi-target.h29
2 files changed, 106 insertions, 0 deletions
diff --git a/firmware/target/arm/olympus/mrobe-500/spi-mr500.c b/firmware/target/arm/olympus/mrobe-500/spi-mr500.c
new file mode 100644
index 0000000000..6c0d4b5990
--- /dev/null
+++ b/firmware/target/arm/olympus/mrobe-500/spi-mr500.c
@@ -0,0 +1,77 @@
1/*
2 * SPI interface driver for the DM320 SoC
3 *
4 * Copyright (C) 2007 shirour <mrobefan@gmail.com>
5 * Copyright (C) 2007 Catalin Patulea <cat@vv.carleton.ca>
6 *
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.
11 *
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.
22 *
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.
26 */
27
28#include "system.h"
29
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)
33
34int dm320_spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size,
35 uint8_t *rx_bytes, unsigned int rx_size)
36{
37 /* Activate the slave select pin */
38 set_gio_enable();
39
40 while (tx_size--)
41 {
42 /* Send one byte */
43 IO_SERIAL0_TX_DATA = *tx_bytes++;
44
45 /* Wait until transfer finished */
46 while (IO_SERIAL0_RX_DATA & 0x100);
47 }
48
49 while (rx_size--)
50 {
51 /* Make the clock tick */
52 IO_SERIAL0_TX_DATA = 0;
53
54 /* Wait until transfer finished */
55 unsigned short data;
56 while ((data = IO_SERIAL0_RX_DATA) & 0x100);
57
58 *rx_bytes++ = data & 0xff;
59 }
60
61 clr_gio_enable();
62
63 return 0;
64}
65
66void dm320_spi_init(void)
67{
68 /* Set SCLK idle level = 0 */
69 IO_SERIAL0_MODE |= (1<<10);
70
71 /* Enable TX */
72 IO_SERIAL0_TX_ENABLE = 0x0001;
73
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();
77}
diff --git a/firmware/target/arm/olympus/mrobe-500/spi-target.h b/firmware/target/arm/olympus/mrobe-500/spi-target.h
new file mode 100644
index 0000000000..ebaacb45a0
--- /dev/null
+++ b/firmware/target/arm/olympus/mrobe-500/spi-target.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
9 *
10 * Copyright (C) 2007 by Catalin Patulea
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef SPI_TARGET_H
21#define SPI_TARGET_H
22
23#include <inttypes.h>
24
25void dm320_spi_init(void);
26int dm320_spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size,
27 uint8_t *rx_bytes, unsigned int rx_size);
28
29#endif