diff options
-rw-r--r-- | firmware/SOURCES | 2 | ||||
-rw-r--r-- | firmware/drivers/rtc/rtc_rx5x348ab.c | 35 | ||||
-rw-r--r-- | firmware/drivers/tsc2100.c | 9 | ||||
-rw-r--r-- | firmware/export/config-mrobe500.h | 2 | ||||
-rw-r--r-- | firmware/export/config.h | 1 | ||||
-rw-r--r-- | firmware/export/spi.h | 5 | ||||
-rw-r--r-- | firmware/target/arm/tms320dm320/spi-dm320.c | 50 | ||||
-rw-r--r-- | firmware/target/arm/tms320dm320/spi-target.h | 10 |
8 files changed, 95 insertions, 19 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index c864b08d34..72712b6b6c 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -146,6 +146,8 @@ drivers/rtc/rtc_ds1339_ds3231.c drivers/rtc/rtc_s3c2440.c #elif (CONFIG_RTC == RTC_AS3514) drivers/rtc/rtc_as3514.c +#elif (CONFIG_RTC == RTC_RX5X348AB) +drivers/rtc/rtc_rx5x348ab.c #endif /* (CONFIG_RTC == RTC_) */ #endif /* SIMULATOR */ diff --git a/firmware/drivers/rtc/rtc_rx5x348ab.c b/firmware/drivers/rtc/rtc_rx5x348ab.c new file mode 100644 index 0000000000..3db30d2a38 --- /dev/null +++ b/firmware/drivers/rtc/rtc_rx5x348ab.c @@ -0,0 +1,35 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: rtc_as3514.c 12131 2007-01-27 20:48:48Z dan_a $ + * + * Copyright (C) 2007 by Jonathan Gordon + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "spi.h" +#include "rtc.h" +#include <stdbool.h> + +void rtc_init(void) +{ +} + +int rtc_read_datetime(unsigned char* buf) +{ + char command = 0x04; /* burst read from the start of the time/date reg */ + spi_block_transfer(SPI_target_RX5X348AB, + &command, 1, buf, 7); + return 1; +}
\ No newline at end of file diff --git a/firmware/drivers/tsc2100.c b/firmware/drivers/tsc2100.c index 19da33e377..ccb8c1f26b 100644 --- a/firmware/drivers/tsc2100.c +++ b/firmware/drivers/tsc2100.c @@ -30,7 +30,8 @@ void tsc2100_read_values(short *x, short* y, short *z1, short *z2) unsigned short command = 0x8000|(page << 11)|(address << 5); unsigned char out[] = {command >> 8, command & 0xff}; unsigned char in[8]; - spi_block_transfer(out, sizeof(out), in, sizeof(in)); + spi_block_transfer(SPI_target_TSC2100, + out, sizeof(out), in, sizeof(in)); *x = (in[0]<<8)|in[1]; *y = (in[2]<<8)|in[3]; @@ -43,7 +44,8 @@ short tsc2100_readreg(int page, int address) unsigned short command = 0x8000|(page << 11)|(address << 5); unsigned char out[] = {command >> 8, command & 0xff}; unsigned char in[2]; - spi_block_transfer(out, sizeof(out), in, sizeof(in)); + spi_block_transfer(SPI_target_TSC2100, + out, sizeof(out), in, sizeof(in)); return (in[0]<<8)|in[1]; } @@ -53,7 +55,8 @@ void tsc2100_writereg(int page, int address, short value) unsigned short command = 0x8000|(page << 11)|(address << 5); unsigned char out[4] = {command >> 8, command & 0xff, value >> 8, value & 0xff}; - spi_block_transfer(out, sizeof(out), NULL, 0); + spi_block_transfer(SPI_target_TSC2100, + out, sizeof(out), NULL, 0); } void tsc2100_keyclick(void) diff --git a/firmware/export/config-mrobe500.h b/firmware/export/config-mrobe500.h index 7bb7fc57ef..a965881bbd 100644 --- a/firmware/export/config-mrobe500.h +++ b/firmware/export/config-mrobe500.h @@ -62,7 +62,7 @@ #define CONFIG_CODEC SWCODEC /* define this if you have a real-time clock */ -//#define CONFIG_RTC RTC_S3C2440 +#define CONFIG_RTC RTC_RX5X348AB /* Define this for LCD backlight available */ #define HAVE_BACKLIGHT diff --git a/firmware/export/config.h b/firmware/export/config.h index 9bf589a459..7c55ee88a3 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -140,6 +140,7 @@ #define RTC_AS3514 6 /* Sandisk Sansa e200 series */ #define RTC_DS1339_DS3231 7 /* h1x0 RTC mod */ #define RTC_IMX31L 8 +#define RTC_RX5X348AB 9 /* USB On-the-go */ #define USBOTG_ISP1362 1362 /* iriver H300 */ diff --git a/firmware/export/spi.h b/firmware/export/spi.h index aafc367855..1de12abefb 100644 --- a/firmware/export/spi.h +++ b/firmware/export/spi.h @@ -18,9 +18,6 @@ ****************************************************************************/ #ifndef __SPI_H__ #define __SPI_H__ - -int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, - uint8_t *rx_bytes, unsigned int rx_size); -void spi_init(void); +#include "spi-target.h" #endif diff --git a/firmware/target/arm/tms320dm320/spi-dm320.c b/firmware/target/arm/tms320dm320/spi-dm320.c index c47ab8f6ed..31fe63d9dd 100644 --- a/firmware/target/arm/tms320dm320/spi-dm320.c +++ b/firmware/target/arm/tms320dm320/spi-dm320.c @@ -24,18 +24,43 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 675 Mass Ave, Cambridge, MA 02139, USA. */ - +#include "kernel.h" #include "system.h" +#include "spi.h" + +#define GIO_TS_ENABLE (1<<2) +#define GIO_RTC_ENABLE (1<<12) + +struct mutex spi_lock; -#define GIO_TS_ENABLE (1<<2) -#define clr_gio_enable() IO_GIO_BITSET1=GIO_TS_ENABLE -#define set_gio_enable() IO_GIO_BITCLR1=GIO_TS_ENABLE +struct SPI_info { + volatile unsigned short *setreg; + volatile unsigned short *clrreg; + int bit; +}; +#define reg(a) (PHY_IO_BASE+a) +struct SPI_info spi_targets[] = +{ + [SPI_target_TSC2100] = { reg(0x0594), reg(0x058E), GIO_TS_ENABLE }, + [SPI_target_RX5X348AB] = { reg(0x058C), reg(0x0592), GIO_RTC_ENABLE }, +}; + +static void spi_disable_all_targets(void) +{ + int i; + for(i=0;i<SPI_MAX_TARGETS;i++) + { + *spi_targets[i].clrreg = spi_targets[i].bit; + } +} -int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, +int spi_block_transfer(enum SPI_target target, + const uint8_t *tx_bytes, unsigned int tx_size, uint8_t *rx_bytes, unsigned int rx_size) { + spinlock_lock(&spi_lock); /* Activate the slave select pin */ - set_gio_enable(); + *spi_targets[target].setreg = spi_targets[target].bit; while (tx_size--) { @@ -58,13 +83,15 @@ int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, *rx_bytes++ = data & 0xff; } - clr_gio_enable(); - + *spi_targets[target].clrreg = spi_targets[target].bit; + + spinlock_unlock(&spi_lock); return 0; } void spi_init(void) { + spinlock_init(&spi_lock); /* Set SCLK idle level = 0 */ IO_SERIAL0_MODE |= (1<<10); @@ -72,6 +99,9 @@ void spi_init(void) IO_SERIAL0_TX_ENABLE = 0x0001; /* Set GIO 18 to output for touch screen slave enable */ - IO_GIO_DIR1&=~GIO_TS_ENABLE; - clr_gio_enable(); + IO_GIO_DIR1 &= ~GIO_TS_ENABLE; + /* Set GIO 12 to output for rtc slave enable */ + IO_GIO_DIR0 &= ~GIO_RTC_ENABLE; + + spi_disable_all_targets(); /* make sure only one is ever enabled at a time */ } diff --git a/firmware/target/arm/tms320dm320/spi-target.h b/firmware/target/arm/tms320dm320/spi-target.h index 866919dc27..7123fc1c05 100644 --- a/firmware/target/arm/tms320dm320/spi-target.h +++ b/firmware/target/arm/tms320dm320/spi-target.h @@ -21,9 +21,17 @@ #define SPI_TARGET_H #include <inttypes.h> +#include <stdbool.h> + +enum SPI_target { + SPI_target_TSC2100 = 0, + SPI_target_RX5X348AB, + SPI_MAX_TARGETS, +}; void spi_init(void); -int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, +int spi_block_transfer(enum SPI_target target, + const uint8_t *tx_bytes, unsigned int tx_size, uint8_t *rx_bytes, unsigned int rx_size); #endif |