From 65526aa3995bb7594ac4741eb0cd2f4770224943 Mon Sep 17 00:00:00 2001 From: jdgordon Date: Mon, 1 Oct 2007 05:27:43 +0000 Subject: [PATCH] spi is shared between the rtc and tsc2100 adds the very begining of the rtc driver (only reads the time currently git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14935 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 2 + .../spi-target.h => drivers/rtc/rtc_rx5x348ab.c} | 26 ++++++----- firmware/drivers/tsc2100.c | 9 ++-- firmware/export/config-mrobe500.h | 2 +- firmware/export/config.h | 1 + firmware/export/spi.h | 5 +-- firmware/target/arm/tms320dm320/spi-dm320.c | 50 +++++++++++++++++----- firmware/target/arm/tms320dm320/spi-target.h | 10 ++++- 8 files changed, 76 insertions(+), 29 deletions(-) copy firmware/{target/arm/tms320dm320/spi-target.h => drivers/rtc/rtc_rx5x348ab.c} (65%) diff --git a/firmware/SOURCES b/firmware/SOURCES index c864b08d3..72712b6b6 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/target/arm/tms320dm320/spi-target.h b/firmware/drivers/rtc/rtc_rx5x348ab.c similarity index 65% copy from firmware/target/arm/tms320dm320/spi-target.h copy to firmware/drivers/rtc/rtc_rx5x348ab.c index 866919dc2..3db30d2a3 100644 --- a/firmware/target/arm/tms320dm320/spi-target.h +++ b/firmware/drivers/rtc/rtc_rx5x348ab.c @@ -5,9 +5,9 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id$ + * $Id: rtc_as3514.c 12131 2007-01-27 20:48:48Z dan_a $ * - * Copyright (C) 2007 by Catalin Patulea + * 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. @@ -16,14 +16,20 @@ * KIND, either express or implied. * ****************************************************************************/ - -#ifndef SPI_TARGET_H -#define SPI_TARGET_H -#include +#include "config.h" +#include "spi.h" +#include "rtc.h" +#include -void spi_init(void); -int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, - uint8_t *rx_bytes, unsigned int rx_size); +void rtc_init(void) +{ +} -#endif +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 19da33e37..ccb8c1f26 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 7bb7fc57e..a965881bb 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 9bf589a45..7c55ee88a 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 aafc36785..1de12abef 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 c47ab8f6e..31fe63d9d 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 +#include + +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 -- 2.11.4.GIT