diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2007-10-01 05:27:43 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2007-10-01 05:27:43 +0000 |
commit | 03f45d3affcee6d8ffb58f1cc6f414284ed418b4 (patch) | |
tree | 99ebe8a4ef8e86de4770ebe83a65a3b6156db82f | |
parent | ea47ee64f02030c64e0472939ea3c588ce7e8dab (diff) | |
download | rockbox-03f45d3affcee6d8ffb58f1cc6f414284ed418b4.tar.gz rockbox-03f45d3affcee6d8ffb58f1cc6f414284ed418b4.zip |
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
-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 | |||
146 | drivers/rtc/rtc_s3c2440.c | 146 | drivers/rtc/rtc_s3c2440.c |
147 | #elif (CONFIG_RTC == RTC_AS3514) | 147 | #elif (CONFIG_RTC == RTC_AS3514) |
148 | drivers/rtc/rtc_as3514.c | 148 | drivers/rtc/rtc_as3514.c |
149 | #elif (CONFIG_RTC == RTC_RX5X348AB) | ||
150 | drivers/rtc/rtc_rx5x348ab.c | ||
149 | #endif /* (CONFIG_RTC == RTC_) */ | 151 | #endif /* (CONFIG_RTC == RTC_) */ |
150 | #endif /* SIMULATOR */ | 152 | #endif /* SIMULATOR */ |
151 | 153 | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: rtc_as3514.c 12131 2007-01-27 20:48:48Z dan_a $ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Jonathan Gordon | ||
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 | #include "config.h" | ||
21 | #include "spi.h" | ||
22 | #include "rtc.h" | ||
23 | #include <stdbool.h> | ||
24 | |||
25 | void rtc_init(void) | ||
26 | { | ||
27 | } | ||
28 | |||
29 | int rtc_read_datetime(unsigned char* buf) | ||
30 | { | ||
31 | char command = 0x04; /* burst read from the start of the time/date reg */ | ||
32 | spi_block_transfer(SPI_target_RX5X348AB, | ||
33 | &command, 1, buf, 7); | ||
34 | return 1; | ||
35 | } \ 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) | |||
30 | unsigned short command = 0x8000|(page << 11)|(address << 5); | 30 | unsigned short command = 0x8000|(page << 11)|(address << 5); |
31 | unsigned char out[] = {command >> 8, command & 0xff}; | 31 | unsigned char out[] = {command >> 8, command & 0xff}; |
32 | unsigned char in[8]; | 32 | unsigned char in[8]; |
33 | spi_block_transfer(out, sizeof(out), in, sizeof(in)); | 33 | spi_block_transfer(SPI_target_TSC2100, |
34 | out, sizeof(out), in, sizeof(in)); | ||
34 | 35 | ||
35 | *x = (in[0]<<8)|in[1]; | 36 | *x = (in[0]<<8)|in[1]; |
36 | *y = (in[2]<<8)|in[3]; | 37 | *y = (in[2]<<8)|in[3]; |
@@ -43,7 +44,8 @@ short tsc2100_readreg(int page, int address) | |||
43 | unsigned short command = 0x8000|(page << 11)|(address << 5); | 44 | unsigned short command = 0x8000|(page << 11)|(address << 5); |
44 | unsigned char out[] = {command >> 8, command & 0xff}; | 45 | unsigned char out[] = {command >> 8, command & 0xff}; |
45 | unsigned char in[2]; | 46 | unsigned char in[2]; |
46 | spi_block_transfer(out, sizeof(out), in, sizeof(in)); | 47 | spi_block_transfer(SPI_target_TSC2100, |
48 | out, sizeof(out), in, sizeof(in)); | ||
47 | return (in[0]<<8)|in[1]; | 49 | return (in[0]<<8)|in[1]; |
48 | } | 50 | } |
49 | 51 | ||
@@ -53,7 +55,8 @@ void tsc2100_writereg(int page, int address, short value) | |||
53 | unsigned short command = 0x8000|(page << 11)|(address << 5); | 55 | unsigned short command = 0x8000|(page << 11)|(address << 5); |
54 | unsigned char out[4] = {command >> 8, command & 0xff, | 56 | unsigned char out[4] = {command >> 8, command & 0xff, |
55 | value >> 8, value & 0xff}; | 57 | value >> 8, value & 0xff}; |
56 | spi_block_transfer(out, sizeof(out), NULL, 0); | 58 | spi_block_transfer(SPI_target_TSC2100, |
59 | out, sizeof(out), NULL, 0); | ||
57 | } | 60 | } |
58 | 61 | ||
59 | void tsc2100_keyclick(void) | 62 | 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 @@ | |||
62 | #define CONFIG_CODEC SWCODEC | 62 | #define CONFIG_CODEC SWCODEC |
63 | 63 | ||
64 | /* define this if you have a real-time clock */ | 64 | /* define this if you have a real-time clock */ |
65 | //#define CONFIG_RTC RTC_S3C2440 | 65 | #define CONFIG_RTC RTC_RX5X348AB |
66 | 66 | ||
67 | /* Define this for LCD backlight available */ | 67 | /* Define this for LCD backlight available */ |
68 | #define HAVE_BACKLIGHT | 68 | #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 @@ | |||
140 | #define RTC_AS3514 6 /* Sandisk Sansa e200 series */ | 140 | #define RTC_AS3514 6 /* Sandisk Sansa e200 series */ |
141 | #define RTC_DS1339_DS3231 7 /* h1x0 RTC mod */ | 141 | #define RTC_DS1339_DS3231 7 /* h1x0 RTC mod */ |
142 | #define RTC_IMX31L 8 | 142 | #define RTC_IMX31L 8 |
143 | #define RTC_RX5X348AB 9 | ||
143 | 144 | ||
144 | /* USB On-the-go */ | 145 | /* USB On-the-go */ |
145 | #define USBOTG_ISP1362 1362 /* iriver H300 */ | 146 | #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 @@ | |||
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | #ifndef __SPI_H__ | 19 | #ifndef __SPI_H__ |
20 | #define __SPI_H__ | 20 | #define __SPI_H__ |
21 | 21 | #include "spi-target.h" | |
22 | int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, | ||
23 | uint8_t *rx_bytes, unsigned int rx_size); | ||
24 | void spi_init(void); | ||
25 | 22 | ||
26 | #endif | 23 | #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 @@ | |||
24 | * with this program; if not, write to the Free Software Foundation, Inc., | 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
25 | * 675 Mass Ave, Cambridge, MA 02139, USA. | 25 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | */ | 26 | */ |
27 | 27 | #include "kernel.h" | |
28 | #include "system.h" | 28 | #include "system.h" |
29 | #include "spi.h" | ||
30 | |||
31 | #define GIO_TS_ENABLE (1<<2) | ||
32 | #define GIO_RTC_ENABLE (1<<12) | ||
33 | |||
34 | struct mutex spi_lock; | ||
29 | 35 | ||
30 | #define GIO_TS_ENABLE (1<<2) | 36 | struct SPI_info { |
31 | #define clr_gio_enable() IO_GIO_BITSET1=GIO_TS_ENABLE | 37 | volatile unsigned short *setreg; |
32 | #define set_gio_enable() IO_GIO_BITCLR1=GIO_TS_ENABLE | 38 | volatile unsigned short *clrreg; |
39 | int bit; | ||
40 | }; | ||
41 | #define reg(a) (PHY_IO_BASE+a) | ||
42 | struct SPI_info spi_targets[] = | ||
43 | { | ||
44 | [SPI_target_TSC2100] = { reg(0x0594), reg(0x058E), GIO_TS_ENABLE }, | ||
45 | [SPI_target_RX5X348AB] = { reg(0x058C), reg(0x0592), GIO_RTC_ENABLE }, | ||
46 | }; | ||
47 | |||
48 | static void spi_disable_all_targets(void) | ||
49 | { | ||
50 | int i; | ||
51 | for(i=0;i<SPI_MAX_TARGETS;i++) | ||
52 | { | ||
53 | *spi_targets[i].clrreg = spi_targets[i].bit; | ||
54 | } | ||
55 | } | ||
33 | 56 | ||
34 | int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, | 57 | int spi_block_transfer(enum SPI_target target, |
58 | const uint8_t *tx_bytes, unsigned int tx_size, | ||
35 | uint8_t *rx_bytes, unsigned int rx_size) | 59 | uint8_t *rx_bytes, unsigned int rx_size) |
36 | { | 60 | { |
61 | spinlock_lock(&spi_lock); | ||
37 | /* Activate the slave select pin */ | 62 | /* Activate the slave select pin */ |
38 | set_gio_enable(); | 63 | *spi_targets[target].setreg = spi_targets[target].bit; |
39 | 64 | ||
40 | while (tx_size--) | 65 | while (tx_size--) |
41 | { | 66 | { |
@@ -58,13 +83,15 @@ int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, | |||
58 | *rx_bytes++ = data & 0xff; | 83 | *rx_bytes++ = data & 0xff; |
59 | } | 84 | } |
60 | 85 | ||
61 | clr_gio_enable(); | 86 | *spi_targets[target].clrreg = spi_targets[target].bit; |
62 | 87 | ||
88 | spinlock_unlock(&spi_lock); | ||
63 | return 0; | 89 | return 0; |
64 | } | 90 | } |
65 | 91 | ||
66 | void spi_init(void) | 92 | void spi_init(void) |
67 | { | 93 | { |
94 | spinlock_init(&spi_lock); | ||
68 | /* Set SCLK idle level = 0 */ | 95 | /* Set SCLK idle level = 0 */ |
69 | IO_SERIAL0_MODE |= (1<<10); | 96 | IO_SERIAL0_MODE |= (1<<10); |
70 | 97 | ||
@@ -72,6 +99,9 @@ void spi_init(void) | |||
72 | IO_SERIAL0_TX_ENABLE = 0x0001; | 99 | IO_SERIAL0_TX_ENABLE = 0x0001; |
73 | 100 | ||
74 | /* Set GIO 18 to output for touch screen slave enable */ | 101 | /* Set GIO 18 to output for touch screen slave enable */ |
75 | IO_GIO_DIR1&=~GIO_TS_ENABLE; | 102 | IO_GIO_DIR1 &= ~GIO_TS_ENABLE; |
76 | clr_gio_enable(); | 103 | /* Set GIO 12 to output for rtc slave enable */ |
104 | IO_GIO_DIR0 &= ~GIO_RTC_ENABLE; | ||
105 | |||
106 | spi_disable_all_targets(); /* make sure only one is ever enabled at a time */ | ||
77 | } | 107 | } |
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 @@ | |||
21 | #define SPI_TARGET_H | 21 | #define SPI_TARGET_H |
22 | 22 | ||
23 | #include <inttypes.h> | 23 | #include <inttypes.h> |
24 | #include <stdbool.h> | ||
25 | |||
26 | enum SPI_target { | ||
27 | SPI_target_TSC2100 = 0, | ||
28 | SPI_target_RX5X348AB, | ||
29 | SPI_MAX_TARGETS, | ||
30 | }; | ||
24 | 31 | ||
25 | void spi_init(void); | 32 | void spi_init(void); |
26 | int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size, | 33 | int spi_block_transfer(enum SPI_target target, |
34 | const uint8_t *tx_bytes, unsigned int tx_size, | ||
27 | uint8_t *rx_bytes, unsigned int rx_size); | 35 | uint8_t *rx_bytes, unsigned int rx_size); |
28 | 36 | ||
29 | #endif | 37 | #endif |